def append_typewriter(self, filename: str = "", text: str = "", code: Code = None) -> "ActionsBuilder": """Adds an :class:`purdy.actions.AppendTypewriter` action :param filename: name of a file to read for :class:`purdy.content.Code` content. If both this and `text` is given, `filename` is used first :param text: text to read for :class:`purdy.content.Code` content. :param code: a :class:`purdy.content.Code` object containing the source code to insert. If all `code`, `filename` and `text` are given, `code` will be used first. :return: self """ return self._add_action( AppendTypewriter(self.__code_box, self._create_code(filename, text, code)))
from purdy.content import Code from purdy.settings import settings from purdy.ui import SplitScreen settings['movie_mode'] = 500 py_code = Code('../display_code/code.py') con_code = Code('../display_code/simple.repl') screen = SplitScreen(settings, top_starting_line_number=-1, top_auto_scroll=False) py_box = screen.top con_box = screen.bottom actions = [ Append(py_box, py_code), Wait(), AppendTypewriter(con_box, con_code), Wait(), StopMovie(), Wait(), Highlight(py_box, 4, True), Wait(), Highlight(con_box, 3, True), Wait(), Highlight(py_box, 4, False), ] if __name__ == '__main__': screen.run(actions)
#!/usr/bin/env python ### Example purdy library code # # Demonstrates the Shell action that runs a subprocess and returns the result from purdy.actions import Shell, AppendTypewriter from purdy.content import Code from purdy.ui import SimpleScreen screen = SimpleScreen() code_box = screen.code_box cmd1 = 'echo "hello there"' cmd2 = 'echo "it is a nice day today"' blob = Code(text=f'$ {cmd1}') blob2 = Code(text=f'$ {cmd2}') actions = [ AppendTypewriter(code_box, blob), Shell(code_box, cmd1), AppendTypewriter(code_box, blob2), Shell(code_box, cmd2), ] if __name__ == '__main__': screen.run(actions)
undefined > a 3 > let b = '4' undefined > b '4' > b == a false > b === a false > if(a) { ... console.log(a) ... } 3 undefined > c Uncaught ReferenceError: c is not defined """ node = Code(text=text, lexer_name='node') actions = [ Append(code_box, js), Wait(), AppendTypewriter(code_box, node), ] if __name__ == '__main__': screen.run(actions)
#!/usr/bin/env python ### Example purdy library code # # Shows a split screen session with two code boxes on top and a third below. from purdy.actions import Append, AppendTypewriter from purdy.content import Code from purdy.ui import Screen, CodeBox, TwinCodeBox py_code = Code(filename='../display_code/decorator.repl') con_code = Code(filename='../display_code/console.repl') screen = Screen(rows=[ TwinCodeBox(left_starting_line_number=1, right_weight=2, height=14), CodeBox(auto_scroll=False) ]) actions = [ AppendTypewriter(screen.code_boxes[0], py_code), Append(screen.code_boxes[1], con_code), Append(screen.code_boxes[2], con_code), ] if __name__ == '__main__': screen.run(actions)