diff options
-rw-r--r-- | presentty/ansiparser.py | 47 | ||||
-rw-r--r-- | presentty/rst.py | 2 |
2 files changed, 37 insertions, 12 deletions
diff --git a/presentty/ansiparser.py b/presentty/ansiparser.py index a780b42..4750b9e 100644 --- a/presentty/ansiparser.py +++ b/presentty/ansiparser.py | |||
@@ -57,6 +57,8 @@ class ANSIParser(object): | |||
57 | self.blink = False | 57 | self.blink = False |
58 | self.fg = 7 | 58 | self.fg = 7 |
59 | self.bg = 0 | 59 | self.bg = 0 |
60 | self.bg256 = None | ||
61 | self.fg256 = None | ||
60 | 62 | ||
61 | def moveTo(self, x, y): | 63 | def moveTo(self, x, y): |
62 | while x>80: | 64 | while x>80: |
@@ -85,9 +87,8 @@ class ANSIParser(object): | |||
85 | if c == 'm': | 87 | if c == 'm': |
86 | if not values: | 88 | if not values: |
87 | values = [0] | 89 | values = [0] |
88 | fg256 = None | ||
89 | for v in values: | 90 | for v in values: |
90 | if fg256 is True: | 91 | if self.fg256 is True: |
91 | if v <= 0x08: | 92 | if v <= 0x08: |
92 | self.fg = v | 93 | self.fg = v |
93 | elif v <= 0x0f: | 94 | elif v <= 0x0f: |
@@ -97,12 +98,28 @@ class ANSIParser(object): | |||
97 | r, x = divmod(v-16, 36) | 98 | r, x = divmod(v-16, 36) |
98 | g, x = divmod(x, 6) | 99 | g, x = divmod(x, 6) |
99 | b = x % 6 | 100 | b = x % 6 |
100 | fg256 = ('#' + | 101 | self.fg256 = ('#' + |
101 | self.colors256[r] + | 102 | self.colors256[r] + |
102 | self.colors256[g] + | 103 | self.colors256[g] + |
103 | self.colors256[b]) | 104 | self.colors256[b]) |
104 | else: | 105 | else: |
105 | fg256 = 'g' + str(self.colorsgray[v-232]) | 106 | self.fg256 = 'g' + str(self.colorsgray[v-232]) |
107 | elif self.bg256 is True: | ||
108 | if v <= 0x08: | ||
109 | self.bg = v | ||
110 | #elif v <= 0x0f: | ||
111 | # self.bg = v - 0x08 | ||
112 | # self.bold = True | ||
113 | elif v <= 0xe7: | ||
114 | r, x = divmod(v-16, 36) | ||
115 | g, x = divmod(x, 6) | ||
116 | b = x % 6 | ||
117 | self.bg256 = ('#' + | ||
118 | self.colors256[r] + | ||
119 | self.colors256[g] + | ||
120 | self.colors256[b]) | ||
121 | else: | ||
122 | self.bg256 = 'g' + str(self.colorsgray[v-232]) | ||
106 | elif v == 0: | 123 | elif v == 0: |
107 | self.resetColor() | 124 | self.resetColor() |
108 | elif v == 1: | 125 | elif v == 1: |
@@ -111,21 +128,29 @@ class ANSIParser(object): | |||
111 | self.blink = True | 128 | self.blink = True |
112 | elif v>29 and v<38: | 129 | elif v>29 and v<38: |
113 | self.fg = v-30 | 130 | self.fg = v-30 |
131 | self.fg256 = None | ||
114 | elif v>39 and v<48: | 132 | elif v>39 and v<48: |
115 | self.bg = v-40 | 133 | self.bg = v-40 |
134 | self.bg256 = None | ||
116 | elif v==38: | 135 | elif v==38: |
117 | fg256=True | 136 | self.fg256=True |
137 | elif v==48: | ||
138 | self.bg256=True | ||
118 | fg = self.fg | 139 | fg = self.fg |
119 | if self.bold: | 140 | if self.bold: |
120 | fg += 8 | 141 | fg += 8 |
121 | fgattrs = [] | 142 | fgattrs = [] |
122 | if self.blink: | 143 | if self.blink: |
123 | fgattrs.append('blink') | 144 | fgattrs.append('blink') |
124 | if fg256: | 145 | if self.fg256: |
125 | fgattrs.append(fg256) | 146 | fgattrs.append(self.fg256) |
126 | else: | 147 | else: |
127 | fgattrs.append(self.colors[fg]) | 148 | fgattrs.append(self.colors[fg]) |
128 | self.attr = urwid.AttrSpec(', '.join(fgattrs), self.colors[self.bg]) | 149 | if self.bg256: |
150 | bg = self.bg256 | ||
151 | else: | ||
152 | bg = self.colors[self.bg] | ||
153 | self.attr = urwid.AttrSpec(', '.join(fgattrs), bg) | ||
129 | if c == 'A': | 154 | if c == 'A': |
130 | if not values: | 155 | if not values: |
131 | values = [1] | 156 | values = [1] |
diff --git a/presentty/rst.py b/presentty/rst.py index 41b3f97..e96ff21 100644 --- a/presentty/rst.py +++ b/presentty/rst.py | |||
@@ -460,7 +460,7 @@ def main(): | |||
460 | 460 | ||
461 | argp = argparse.ArgumentParser(description='Test RST parser') | 461 | argp = argparse.ArgumentParser(description='Test RST parser') |
462 | argp.add_argument('file', help='presentation file (RST)') | 462 | argp.add_argument('file', help='presentation file (RST)') |
463 | argp.add_argument('slides', nargs='?', default=[], | 463 | argp.add_argument('slides', nargs='*', default=[], |
464 | help='slides to render') | 464 | help='slides to render') |
465 | argp.add_argument('--render', action='store_true', | 465 | argp.add_argument('--render', action='store_true', |
466 | help='Fully render a slide') | 466 | help='Fully render a slide') |