Commits

Mike Bayer committed 946c377

more formatting

Comments (0)

Files changed (2)

sliderepl/core.py

 else:
     clearcmd = "clear"
 
-class SysOutStack(object):
-    def __init__(self):
-        self.stack = [sys.stdout]
-
-    def write(self, data):
-        self.stack[-1].write(data)
-
-    def flush(self, *args):
-        self.stack[-1].flush()
-
-    class _PushCtx(object):
-        def __init__(self, parent):
-            self.parent = parent
-        def __enter__(self):
-            pass
-        def __exit__(self, *args):
-            self.parent.pop()
-
-    def push(self, buf):
-        self.stack.append(buf)
-        sys.stdout = self.stack[-1]
-        return SysOutStack._PushCtx(self)
-
-    def pop(self):
-        assert len(self.stack) > 1
-        val = self.stack.pop()
-        sys.stdout = self.stack[-1]
-        return val
-
-sysout = SysOutStack()
 
 class Deck(object):
     expose = ('next', 'goto', 'show', 'info', 'prev',
                         else:
                             to_show = l
 
-                        to_show = to_show.rstrip()
+                        to_show = to_show #.rstrip()
 
                         if not run and \
-                            last_block and \
-                            j == len(display) - 1:
+                                last_block and \
+                                j == len(display) - 1:
                             self.deck._exec_on_return = True
                         shown.append(to_show)
 
                     Deck._add_history(''.join(display).rstrip())
-                    shown = "\n" + '\n'.join(shown).rstrip()
+                    shown = ''.join(shown)   #+ "\n" #.rstrip() + "\n"
 
-                    sysout.write(shown)
+                    if last_block:
+                        shown = shown.rstrip() + "\n"
+                    sys.stdout.write(self.deck._highlight_text(shown))
 
-                    if len(display) > 1:
-                        if not re.match(r'#[\s\n]', display[0]) or \
-                            (i + 1 < len(self.codeblocks) and
-                                not re.match(r'#[\s\n]',
-                                        self.codeblocks[i + 1][0][0])):
-                            print("")
+                    #if len(display) > 1:
+                    #    if not re.match(r'#[\s\n]', display[0]) or \
+                    #       (i + 1 < len(self.codeblocks) and
+                    #            not re.match(r'#[\s\n]',
+                    #                            self.codeblocks[i + 1][0][0])):
+                    #        print("")
 
                 if run:
                     try:
                     except:
                         traceback.print_exc()
             if run:
-                print ("\n")
+                print ("")
 
         def __str__(self):
             return ''.join(self.lines)

sliderepl/hairy.py

     def _highlight_text(self, text):
         bg = self.color == 'dark' and 'dark' or 'light'
         if self.color in ('auto', 'light', 'dark'):
-            whitespace = re.match(r'(.*)(\s+)$', text, re.S)
+            whitespace = re.match(r'(.*?)(\s+)$', text, re.S)
             if whitespace:
-                content = whitespace.group(1)
+                text = whitespace.group(1)
                 whitespace = whitespace.group(2)
             content = highlight(
                 text, _pycon_lexer,
                     TerminalFormatter(bg=bg, colorscheme=scheme))
             if whitespace:
-                content += whitespace
+                content = content.rstrip() + whitespace
         else:
             content = text
         return content
 
-    class Slide(core.Deck.Slide):
-        def run(self, *args, **kwargs):
-            if not self.deck._highlight:
-                core.Deck.Slide.run(self, *args, **kwargs)
-                return
-
-            io = StringIO()
-            with core.sysout.push(io):
-                core.Deck.Slide.run(self, *args, **kwargs)
-                content = self.deck._highlight_text(io.getvalue())
-            core.sysout.write(content)
-
-