def run(): if not sys.stdin.isatty(): pager = Pager.from_pipe() pager.run() else: parser = argparse.ArgumentParser(description='Browse through a text file.') parser.add_argument('filename', metavar='filename', nargs='+', help='The file to be displayed.') parser.add_argument('--vi', help='Prefer Vi key bindings.', action='store_true') parser.add_argument('--emacs', help='Prefer Emacs key bindings.', action='store_true') args = parser.parse_args() # Determine input mode. vi_mode = 'vi' in os.environ.get('EDITOR', '').lower() if args.vi: vi_mode = True if args.emacs: vi_mode = False pager = Pager(vi_mode=vi_mode) # Open files. for filename in args.filename: # When a filename is given, take a lexer from that filename. lexer = PygmentsLexer.from_filename(filename, sync_from_start=False) pager.add_source(FileSource(filename, lexer=lexer)) # Run UI. pager.run()
def print_table(items, columns: List[Column], *, show_header: bool, pager: bool): gen = output_gen(items, columns, show_header, stretch_last_column=pager) if pager and sys.stdout.isatty(): p = Pager() p.add_source(GeneratorSource(line + [('', '\n')] for line in gen)) p.run() else: while True: print_styled(*next(gen))
def run(): if not PTK3: if is_windows(): from prompt_toolkit.eventloop.win32 import Win32EventLoop loop = Win32EventLoop() else: from prompt_toolkit.eventloop.posix import PosixEventLoop from prompt_toolkit.eventloop.select import SelectSelector loop = PosixEventLoop(selector=SelectSelector) set_event_loop(loop) if not sys.stdin.isatty(): pager = Pager.from_pipe() pager.run() else: parser = argparse.ArgumentParser( description='Browse through a text file.') parser.add_argument('filename', metavar='filename', nargs='+', help='The file to be displayed.') parser.add_argument('--vi', help='Prefer Vi key bindings.', action='store_true') parser.add_argument('--emacs', help='Prefer Emacs key bindings.', action='store_true') args = parser.parse_args() # Determine input mode. vi_mode = 'vi' in os.environ.get('EDITOR', '').lower() if args.vi: vi_mode = True if args.emacs: vi_mode = False pager = Pager(vi_mode=vi_mode) # Open files. for filename in args.filename: # When a filename is given, take a lexer from that filename. lexer = PygmentsLexer.from_filename(filename, sync_from_start=False) pager.add_source(FileSource(filename, lexer=lexer)) # Run UI. pager.run()
def __grades(self): p = Pager() assign = ["--------Grade Distribution--------\n"] try: for item in self.collector.get_grades(): assign.append(item) if "Grade Points" in item: assign.append("\n-------------------") p.add_source(GeneratorSource(send_assignments(assign))) p.run() except EOFError: print("Something Went wrong...") return
def __all_due(self): assign = ["--------All Due--------\n"] p = Pager() try: for item in self.collector.print_assignments(cmd='all'): assign.append(item) if "What is Due:" in item: assign.append("\n-------------------") p.add_source(GeneratorSource(send_assignments(assign))) p.run() except EOFError: print("Something went wrong...") return
def __due_tomorrow(self): assign = ["--------Due Tomorrow--------\n"] p = Pager() try: for item in self.collector.print_assignments(cmd='tomorrow'): assign.append(item) if "What is Due:" in item: assign.append("\n-------------------") p.add_source(GeneratorSource(send_assignments(assign))) p.run() except TypeError: # This means nothing due tomorrow, returns None which can't be iterated return except EOFError: print("Something Went wrong...") return
def run(): if not sys.stdin.isatty(): pager = Pager.from_pipe() pager.run() else: parser = argparse.ArgumentParser( description="Browse through a text file.") parser.add_argument("filename", metavar="filename", nargs="+", help="The file to be displayed.") parser.add_argument("--vi", help="Prefer Vi key bindings.", action="store_true") parser.add_argument("--emacs", help="Prefer Emacs key bindings.", action="store_true") args = parser.parse_args() # Determine input mode. vi_mode = "vi" in os.environ.get("EDITOR", "").lower() if args.vi: vi_mode = True if args.emacs: vi_mode = False pager = Pager(vi_mode=vi_mode) # Open files. for filename in args.filename: # When a filename is given, take a lexer from that filename. lexer = PygmentsLexer.from_filename(filename, sync_from_start=False) pager.add_source(FileSource(filename, lexer=lexer)) # Run UI. pager.run()
def print_table(items, columns: List[Column], colours=None, *, show_header: bool, pager: bool): gen = output_gen(items, columns, colours, show_header, stretch_last_column=pager) if pager: p = Pager() p.add_source(GeneratorSource(line + [('', '\n')] for line in gen)) p.run() else: while True: print_formatted_text(next(gen))
def run(): if is_windows(): from prompt_toolkit.eventloop.win32 import Win32EventLoop loop = Win32EventLoop() else: from prompt_toolkit.eventloop.posix import PosixEventLoop from prompt_toolkit.eventloop.select import SelectSelector loop = PosixEventLoop(selector=SelectSelector) set_event_loop(loop) if not sys.stdin.isatty(): pager = Pager.from_pipe() pager.run() else: parser = argparse.ArgumentParser(description='Browse through a text file.') parser.add_argument('filename', metavar='filename', nargs='+', help='The file to be displayed.') parser.add_argument('--vi', help='Prefer Vi key bindings.', action='store_true') parser.add_argument('--emacs', help='Prefer Emacs key bindings.', action='store_true') args = parser.parse_args() # Determine input mode. vi_mode = 'vi' in os.environ.get('EDITOR', '').lower() if args.vi: vi_mode = True if args.emacs: vi_mode = False pager = Pager(vi_mode=vi_mode) # Open files. for filename in args.filename: # When a filename is given, take a lexer from that filename. lexer = PygmentsLexer.from_filename(filename, sync_from_start=False) pager.add_source(FileSource(filename, lexer=lexer)) # Run UI. pager.run()
#!/usr/bin/env python from __future__ import unicode_literals from pypager.pager import Pager from pypager.source import GeneratorSource def generate_a_lot_of_content(): counter = 0 while True: yield [("", "line: %i\n" % counter)] counter += 1 if __name__ == "__main__": p = Pager() p.add_source(GeneratorSource(generate_a_lot_of_content())) p.run()
#!/usr/bin/env python from __future__ import unicode_literals from pypager.source import GeneratorSource from pypager.pager import Pager def generate_a_lot_of_content(): counter = 0 while True: yield [('', 'line: %i\n' % counter)] counter += 1 if __name__ == '__main__': p = Pager() p.add_source(GeneratorSource(generate_a_lot_of_content())) p.run()
from pypager.source import GeneratorSource from pypager.pager import Pager from prompt_toolkit.token import ZeroWidthEscape import io def generate_a_lot_of_content(): """ This is a function that generates content on the fly. It's called when the pager needs to display more content. """ # counter = 0 # while counter < 10: # yield [(counter, 'line: %i\n' % counter)] # counter += 1 output = io.StringIO(newline="\n") output.write("Primeira Linha") output.write("Segunda Linha") return output if __name__ == '__main__': source = GeneratorSource(generate_a_lot_of_content()) p = Pager(source) p.run()