async def shell(): global crow input_field = TextArea(height=1, prompt='> ', style='class:input-field', multiline=False, wrap_lines=False) captures = VSplit([capture1, capture2]) container = HSplit([ captures, output_field, Window(height=1, char='/', style='class:line', content=FormattedTextControl(text='druid////'), align=WindowAlign.RIGHT), input_field ]) def cwrite(xs): global crow try: crow.write(xs) except: crowreconnect() def accept(buff): try: myprint('\n> ' + input_field.text + '\n') druidparser(cwrite, input_field.text) except ValueError as err: print(err) get_app().exit() input_field.accept_handler = accept kb = KeyBindings() @kb.add('c-c', eager=True) @kb.add('c-q', eager=True) def _(event): event.app.exit() style = Style([ ('capture-field', '#747369'), ('output-field', '#d3d0c8'), ('input-field', '#f2f0ec'), ('line', '#747369'), ]) application = Application( layout=Layout(container, focused_element=input_field), key_bindings=kb, style=style, mouse_support=True, full_screen=True, ) result = await application.run_async()
def _(event): """ Mark task as complete """ # Only receive input on task view mode if focus_folder or (not focus_folder and not tasks): return global waiting_for_confirmation global prompt_window waiting_for_confirmation = True input_field = TextArea( height=1, prompt="Mark task as complete? <y> to confirm. ", style="class:input-field", multiline=False, wrap_lines=False, ) # Confirmation of commands def confirm(buff): global waiting_for_confirmation global prompt_window user_input = input_field.text if user_input == "y": # Mark task as complete auth.complete_task(folder2id[focus_index_folder], task2id[focus_index_task]) load_tasks() # Return to normal state waiting_for_confirmation = False prompt_window = Window() input_field.accept_handler = confirm prompt_window = input_field event.app.layout.focus(input_field)
def main(): # The layout. search_field = SearchToolbar() # For reverse search. output_field = TextArea(style='class:output-field', text=help_text) input_field = TextArea( height=1, prompt='>>> ', style='class:input-field', multiline=False, wrap_lines=False, search_field=search_field) container = HSplit([ output_field, Window(height=1, char='-', style='class:line'), input_field, search_field, ]) # Attach accept handler to the input field. We do this by assigning the # handler to the `TextArea` that we created earlier. it is also possible to # pass it to the constructor of `TextArea`. # NOTE: It's better to assign an `accept_handler`, rather then adding a # custom ENTER key binding. This will automatically reset the input # field and add the strings to the history. def accept(buff): # Evaluate "calculator" expression. try: output = '\n\nIn: {}\nOut: {}'.format( input_field.text, eval(input_field.text)) # Don't do 'eval' in real code! except BaseException as e: output = '\n\n{}'.format(e) new_text = output_field.text + output # Add text to output buffer. output_field.buffer.document = Document( text=new_text, cursor_position=len(new_text)) input_field.accept_handler = accept # The key bindings. kb = KeyBindings() @kb.add('c-c') @kb.add('c-q') def _(event): " Pressing Ctrl-Q or Ctrl-C will exit the user interface. " event.app.exit() # Style. style = Style([ ('output-field', 'bg:#000044 #ffffff'), ('input-field', 'bg:#000000 #ffffff'), ('line', '#004400'), ]) # Run application. application = Application( layout=Layout(container, focused_element=input_field), key_bindings=kb, style=style, mouse_support=True, full_screen=True) application.run()
def run(): line_cursor_pos = 0 current_line = 0 cursor_lock = Lock() during_accept = False # The layout. output_field = TextArea(style="class:output-field") input_field = TextArea( height=1, prompt=" # ", style="class:input-field", multiline=False, wrap_lines=False, ) roll = ['\\', '-', '/', '|'] current_roll = -1 def get_statusbar_text(): nonlocal during_accept, current_roll if during_accept: if current_roll == 3: current_roll = -1 current_roll = current_roll + 1 return ' {} Searching...'.format(roll[current_roll]) else: return ' = Nice Translator' def get_statusbar_class(): nonlocal during_accept if during_accept: return "class:searching-status" else: return "class:status" container = HSplit([ input_field, Window(height=1, char="-", style="class:line"), output_field, Window(FormattedTextControl(get_statusbar_text), height=1, style=get_statusbar_class), ]) def addline(old, newline): return old + ' {}\n'.format(newline) def accept(buff): with cursor_lock: nonlocal during_accept during_accept = True nonlocal line_cursor_pos nonlocal current_line line_cursor_pos = 0 current_line = 0 new_text = '' if input_field.text.strip() != '': try: translate_result = translate.translate(input_field.text) output = '' for rs in translate_result: output = addline(output, rs) text = output text_lines = text.splitlines(keepends=True) for i, l in enumerate(text_lines): if (l.startswith(' > ')): text_lines[i] = ' ' + text_lines[i][3:] break text = ''.join(text_lines) new_text = ' > ' + text[3:] except Exception as e: new_text = 'Some error occured.\n{}'.format(e) # Add text to output buffer. output_field.buffer.document = Document( text=new_text, cursor_position=line_cursor_pos) during_accept = False def threading_accept(buff): l = [buff] t = Thread(target=accept, args=l) t.start() input_field.accept_handler = threading_accept # The key bindings. kb = KeyBindings() # show where the cursor is # @kb.add("tab") # def _(event): # event.app.layout.focus_next() @kb.add('escape', 'q') def _(event): " Pressing Ctrl-Q or Ctrl-C will exit the user interface. " event.app.exit() # cursor move next line @kb.add('escape', 'n') def _(event): with cursor_lock: nonlocal line_cursor_pos nonlocal current_line new_text = '' lines = output_field.text.splitlines(keepends=True) if len(lines) == 0 or current_line is len(lines) - 1: return for i, l in enumerate(lines): if i == current_line: lines[i] = ' ' + lines[i][3:] lines[i + 1] = ' > ' + lines[i + 1][3:] new_text = new_text + lines[i] line_cursor_pos = line_cursor_pos + len(lines[current_line]) current_line = current_line + 1 output_field.buffer.document = Document( text=new_text, cursor_position=line_cursor_pos) # cursor move previous line @kb.add('escape', 'm') def _(event): with cursor_lock: nonlocal line_cursor_pos nonlocal current_line new_text = '' lines = output_field.text.splitlines(keepends=True) if current_line is 0: return for i, l in enumerate(lines): if i == current_line: lines[i] = ' ' + lines[i][3:] lines[i - 1] = ' > ' + lines[i - 1][3:] break for l in lines: new_text = new_text + l line_cursor_pos = line_cursor_pos - len(lines[current_line - 1]) current_line = current_line - 1 output_field.buffer.document = Document( text=new_text, cursor_position=line_cursor_pos) # Style. style = Style([("output-field", ""), ("input-field", ""), ("line", "#ffffff"), ("status", "bg:grey #fff"), ("searching-status", "bg:purple #fff")]) # Run application. application = Application(layout=Layout(container), key_bindings=kb, style=style, full_screen=True, refresh_interval=0.3) application.run()
def accept(buff): # Evaluate "calculator" expression. try: output = '\n\nIn: {}\nOut: {}'.format( input_field.text, eval(input_field.text)) # Don't do 'eval' in real code! except BaseException as e: output = '\n\n{}'.format(e) new_text = right_buffer.text + output # Add text to output buffer. right_buffer.document = Document(text=new_text, cursor_position=len(new_text)) input_field.accept_handler = accept def application(): root_container = VSplit([ # One window that holds the BufferControl with the default buffer on # the left. input_field, # A vertical line in the middle. We explicitly specify the width, to # make sure that the layout engine will not try to divide the whole # width by three for all these windows. The window will simply fill its # content by repeating this character. Window(width=1, char='|'),
def _(event): """ Create new task/folder """ global waiting_for_confirmation global prompt_window waiting_for_confirmation = True # Check if we are creating new task or folder if focus_folder: # We are creating a new folder input_field = TextArea( height=1, prompt="New folder: ", style="class:input-field", multiline=False, wrap_lines=False, ) # Get new folder name def get_name(buff): global waiting_for_confirmation global prompt_window global left_window user_input = input_field.text if user_input: # Create new folder auth.create_folder(user_input) # Refresh folders load_folders() # Return to normal state waiting_for_confirmation = False prompt_window = Window() else: # We are creating a new task input_field = TextArea( height=1, prompt="New task: ", style="class:input-field", multiline=False, wrap_lines=False, ) # Get new task name def get_name(buff): global waiting_for_confirmation global prompt_window user_input = input_field.text if user_input: # Create new task auth.create_task(user_input, folder2id[focus_index_folder]) # Refresh tasks load_tasks() # Return to normal state waiting_for_confirmation = False prompt_window = Window() input_field.accept_handler = get_name prompt_window = input_field event.app.layout.focus(input_field)
dialog = Dialog(title="Info", body=Label(text="...", dont_extend_height=True), buttons=[ Button(text="OK", handler=button_handler), ]) search_field = SearchToolbar() input_field = TextArea(height=1, prompt='/', style='class:input-field', multiline=False, wrap_lines=False, search_field=search_field) input_field.accept_handler = filterTable table = Window(content=FormattedTextControl( text=getFormattedTable(selected, filteredList), get_cursor_position=GetCursorPosition())) root_container = HSplit([ table, ConditionalContainer(content=input_field, filter=isSearching), ConditionalContainer(content=dialog, filter=showInfo) ]) layout = Layout(container=root_container) def goNextPassword(): nextPassword()
def main(play_with_engine=False): search_field = SearchToolbar() engine = None if play_with_engine: engine = chess.engine.SimpleEngine.popen_uci('/usr/bin/stockfish') board = chess.Board() chess_completer = WordCompleter([str(x) for x in board.legal_moves]) output_field = TextArea(style="class:output-field", text=board.unicode()) input_field = TextArea(height=1, prompt=">>> ", style="class:input-field", multiline=False, wrap_lines=False, search_field=search_field, completer=chess_completer, complete_while_typing=True) container = HSplit([ output_field, Window(height=1, char="-", style="class:line"), input_field, search_field, ]) def accept(buff): new_move = chess.Move.from_uci(input_field.text) board.push(new_move) if engine: result = engine.play(board, chess.engine.Limit(time=0.1)) board.push(result.move) output = board.unicode() output_field.buffer.document = Document(text=output) input_field.completer = WordCompleter( [str(x) for x in board.legal_moves]) input_field.accept_handler = accept kb = KeyBindings() @kb.add("c-c") def app_exit(event): event.app.exit() style = Style([ ("output-field", "bg:#000044 #ffffff"), ("input-field", "bg:#000000 #ffffff"), ("line", "#004400"), ]) application = Application( layout=Layout(container, focused_element=input_field), key_bindings=kb, style=style, mouse_support=True, full_screen=True, ) application.run()
if update_announcements_enabled: update_announcements_enabled= False if update_leaderboard_enabled: update_leaderboard_enabled= False if show_submission_info_enabled: show_submission_info_enabled = False def clear_floats(): root_container.floats.clear() root_container.floats.append(completions_menu) input_field.accept_handler = input_parser host = os.getenv("BL_ROYALE_HOST", "scrimmage.royale.ndacm.org:5000") update_announcements_enabled= False async def update_announcements(): loop = asyncio.get_event_loop() payload = await loop.run_in_executor(None, requests.get, "http://" + host + "/announcements") if not update_announcements_enabled: return output_field.text = "Announcements:\n\n"
def commit_selector(buf): content_field.buffer = str(buffer) get_app().layout.focus(output_field) def get_header(): return 'this is the header text' def get_commit_desc(): return 'this is the commit desc.' commits_field.accept_handler = commit_selector body = HSplit([ Window(FormattedTextControl(get_header)), Window(height=1, char='-', style='class:line'), # Main play area VSplit([ commits_field, Window(width=1, char='|', style='class:line'), content_field ]), Window(height=1, char='-', style='class:line'), Window(FormattedTextControl(get_commit_desc)) ]) application = Application(layout=Layout(body), key_bindings=kb,
else: try: runner.parse_and_run(src, other) # TODO: How do we return stuff? update_status_text() except Exception as e: err_str = traceback.format_exc() new_history += err_str + "\n" # Print text to history buffer history_field.buffer.document = Document( text=new_history, cursor_position=len(new_history) ) input_field.accept_handler = submit_command container = HSplit( [ VSplit( [status_field, Window(width=1, char="|", style="class:line"), history_field] ), Window(height=1, char="-", style="class:line"), input_field, search_field, ] ) # Define application. style = Style(
) buffer = Application.current_buffer chat_handler(buffer, process_response(chat_history, True), general_ch, True) elif input_field.text.strip(): # message utils.send_message(channels_window.current_value, input_field.text) except BaseException as e: output = f"\n\n{e}" new_text = output_field.text + output output_field.document = Document( text=new_text, cursor_position=len(new_text), ) input_field.accept_handler = command_handler spinner.succeed("interface rendered") spinner.start("starting app ...") # Run application. application = Application( layout=Layout(container, focused_element=input_field), key_bindings=bindings, style=style, mouse_support=True, full_screen=True, erase_when_done=True, ) spinner.succeed("all good")
]), floats=[ Float( xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1), ) ], ) def accept(buff): execute_action() input_sc.accept_handler = accept # Key bindings kb = KeyBindings() @kb.add("c-c") def _(event): event.app.exit() ######################################################################################################################## # The SlashNextOTI Console Application ################################################################################# snx_oti_console = Application(layout=Layout(body, focused_element=input_sc),