def get_style(): ctx = context.get() if ctx.app.layout.current_buffer is buffer: cls = style.TEXTBOX_FOCUSED else: cls = style.TEXTBOX return f"class:{cls}"
def main(path, command, process_and_exit, horizontal, manual, focus): if len(path) > 1: raise click.ClickException("Only one path argument is supported") if process_and_exit and manual: raise click.ClickException("--manual with --process-and-exit makes no sense") ctx = context.get() path = path[0] if path else None if path or not sys.stdin.isatty(): if path: with open(path) as f: text = f.read() else: text = sys.stdin.read() sys.stdin.close() sys.stdin = open(2) ctx.input_buffer.text = text ctx.live = not manual ctx.box_veritcal_orientation = not horizontal ctx.cmd_buffer.text = command if process_and_exit: ctx.non_interactive = True process_one() else: ctx.app = create_app(focus) with patch_stdout(): ctx.app.run() if ctx.print_output_on_exit or ctx.non_interactive: print(ctx.output_buffer.text)
def __init__(self): self.ctx = context.get() self.process_ctx = context.get_process() self.ctx.process_fn = self.process_key self.lexer_threshold = 10000 self.input_lexer = ToggledLexer(inputs.registry, take_last=False) self.output_lexer = ToggledLexer(outputs.registry, take_last=True)
def copy_output_to_clipboard(_): ctx = context.get() ctx.app.clipboard.set_text(ctx.output_buffer.text) ctx.copied_to_clipboard = True def off(): ctx.copied_to_clipboard = False ctx.app.loop.call_later(0.1, off)
def run1(_): ctx = context.get() ctx.process_fn("run")
def toggle_live(_): ctx = context.get() ctx.live = not ctx.live
def toggle_help(_): ctx = context.get() ctx.display_help = not ctx.display_help
def exit_and_print_output(_): ctx = context.get() ctx.print_output_on_exit = True ctx.app.exit()
def change_boxes_orientation(_): ctx = context.get() ctx.box_veritcal_orientation = not ctx.box_veritcal_orientation