Commits

Mike Bayer committed 58ea27e

more formatting

  • Participants
  • Parent commits b13ae48

Comments (0)

Files changed (2)

File sliderepl/core.py

             timer = ""
         if echo:
             if self._presentation:
-                if not getattr(slide, 'no_clear', False):
+                if not slide.no_clear:
                     os.system(clearcmd)
                     print(slide._banner(timer))
                 else:
                     print("")
+                    print(slide._banner(timer, True))
             else:
                 print(slide._banner(timer))
 
     class Slide(object):
         no_clear = False
         no_exec = False
+        no_echo = False
         init = False
         title = None
 
             sys.stdout = old_stdout
             print("%% executed initial setup slide.")
 
-        def _banner(self, timer):
+        def _banner(self, timer, half=True):
+            # not doing the full banners for now
+
             banner = ""
 
             box_size = 63
 
-            header = "%s / %d" % (self.file, self.index)
-            if timer:
-                header += " / " + timer
+            if not half:
+                header = "%s / %d" % (self.file, self.index)
+                if timer:
+                    header += " / " + timer
 
-            if header:
-                box_size = max(box_size, len(header))
+                if header:
+                    box_size = max(box_size, len(header))
+            else:
+                if not self.title and not self.intro:
+                    return ""
 
             title = None
 
                             "| %s%s|" % (l, (" " * (box_size - len(l) - 2)))
                             for l in self.intro) + "\n"
 
-            banner += "|%s%s |\n" % (" " * (box_size - len(header) - 2), header)
+            if not half:
+                banner += "|%s%s |\n" % (" " * (box_size - len(header) - 2), header)
 
             banner += "+%s+\n" % ("-" * (box_size - 1))
 
             for i, (display, co) in enumerate(self.codeblocks):
                 last_block = i == len(self.codeblocks) - 1
 
-                no_echo = getattr(self, 'no_echo', False)
+                no_echo = self.no_echo
                 if echo and not no_echo:
                     shown = []
 
                         shown.append(to_show)
 
                     Deck._add_history(''.join(display).rstrip())
-                    shown = '\n'.join(shown).rstrip()
+                    shown = "\n" + '\n'.join(shown).rstrip()
 
-                    print(shown)
+                    sys.stdout.write(shown)
 
                     if len(display) > 1:
                         if not re.match(r'#[\s\n]', display[0]) or \
                         exec_(co, environ)
                     except:
                         traceback.print_exc()
+            if run:
+                print ("\n")
 
         def __str__(self):
             return ''.join(self.lines)
                 assert co
                 self.codeblocks.append((self._pop(), co))
 
+            if self.intro:
+                while not self.intro[-1].strip():
+                    self.intro.pop(-1)
+
         def _compile(self):
             style = getattr(self, 'no_return', False) and 'exec' or 'single'
             try:
         t_re = re.compile(r'### +title::(.+)$')
         t_re_2 = re.compile(r'^#####* (.+) #####*$')
 
-        c_re = re.compile(r'#($| .*$)')
+        c_re = re.compile(r'#(?: (.*))?$')
 
         slide = None
-        has_body = False
         with open(path) as fh:
             lines = list(fh)
         while lines:
                     slide.lines = []
                 continue
 
-            if slide and not has_body:
+            if slide:
                 m = c_re.match(line)
                 if m:
-                    slide.intro.append(m.group(1).strip())
+                    if m.group(1):
+                        slide.intro.append(m.group(1).rstrip())
+                    else:
+                        slide.intro.append("")
                     continue
                 elif not line.isspace():
-                    has_body = True
                     slide.lines = []
                 elif slide.intro:
                     slide.intro.append("")
                         slide.no_clear = True
                     elif opt == 's':
                         slide.init = True
-            has_body = slide.no_clear
 
     def show_banner(self):
         print(self.banner)

File sliderepl/hairy.py

 from . import core
 
 import sys
-
+import re
 from pygments import highlight
 from pygments.formatters import TerminalFormatter
 from pygments.lexers import get_lexer_by_name
     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)
+            if whitespace:
+                content = whitespace.group(1)
+                whitespace = whitespace.group(2)
             content = highlight(
                 text, _pycon_lexer,
                     TerminalFormatter(bg=bg, colorscheme=scheme))
+            if whitespace:
+                content += whitespace
         else:
             content = text
         return content