Python prompt_toolkit.application.get_app() Examples
The following are 16
code examples of prompt_toolkit.application.get_app().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prompt_toolkit.application
, or try the search function
.
Example #1
Source File: python_input.py From ptpython with BSD 3-Clause "New" or "Revised" License | 6 votes |
def enter_history(self) -> None: """ Display the history. """ app = get_app() app.vi_state.input_mode = InputMode.NAVIGATION history = PythonHistory(self, self.default_buffer.document) from prompt_toolkit.application import in_terminal import asyncio async def do_in_terminal() -> None: async with in_terminal(): result = await history.app.run_async() if result is not None: self.default_buffer.text = result app.vi_state.input_mode = InputMode.INSERT asyncio.ensure_future(do_in_terminal())
Example #2
Source File: pgbuffer.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def buffer_should_be_handled(pgcli): @Condition def cond(): if not pgcli.multi_line: _logger.debug("Not in multi-line mode. Handle the buffer.") return True if pgcli.multiline_mode == "safe": _logger.debug("Multi-line mode is set to 'safe'. Do NOT handle the buffer.") return False doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document text = doc.text.strip() return ( text.startswith("\\") # Special Command or text.endswith(r"\e") # Special Command or text.endswith(r"\G") # Ended with \e which should launch the editor or _is_complete(text) # A complete SQL command or (text == "exit") # Exit doesn't need semi-colon or (text == "quit") # Quit doesn't need semi-colon or (text == ":q") # To all the vim fans out there or (text == "") # Just a plain enter without any text ) return cond
Example #3
Source File: pgtoolbar.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_vi_mode(): return { InputMode.INSERT: "I", InputMode.NAVIGATION: "N", InputMode.REPLACE: "R", InputMode.INSERT_MULTIPLE: "M", }[get_app().vi_state.input_mode]
Example #4
Source File: __init__.py From edgedb with Apache License 2.0 | 5 votes |
def is_multiline() -> bool: doc = pt_app.get_app().layout.get_buffer_by_name( pt_enums.DEFAULT_BUFFER).document if (doc.cursor_position and doc.text[doc.cursor_position:].strip()): return True return is_multiline_text(doc.text)
Example #5
Source File: key_bindings.py From ptpython with BSD 3-Clause "New" or "Revised" License | 5 votes |
def tab_should_insert_whitespace(): """ When the 'tab' key is pressed with only whitespace character before the cursor, do autocompletion. Otherwise, insert indentation. Except for the first character at the first line. Then always do a completion. It doesn't make sense to start the first line with indentation. """ b = get_app().current_buffer before_cursor = b.document.current_line_before_cursor return bool(b.text and (not before_cursor or before_cursor.isspace()))
Example #6
Source File: python_input.py From ptpython with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _accept_handler(self, buff: Buffer) -> bool: app = get_app() app.exit(result=buff.text) app.pre_run_callables.append(buff.reset) return True # Keep text, we call 'reset' later on.
Example #7
Source File: clitoolbar.py From litecli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_vi_mode(): """Get the current vi mode for display.""" return { InputMode.INSERT: "I", InputMode.NAVIGATION: "N", InputMode.REPLACE: "R", InputMode.INSERT_MULTIPLE: "M", }[get_app().vi_state.input_mode]
Example #8
Source File: clibuffer.py From litecli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def cli_is_multiline(cli): @Condition def cond(): doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document if not cli.multi_line: return False else: return not _multiline_exception(doc.text) return cond
Example #9
Source File: clitoolbar.py From athenacli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_vi_mode(): """Get the current vi mode for display.""" return { InputMode.INSERT: 'I', InputMode.NAVIGATION: 'N', InputMode.REPLACE: 'R', InputMode.INSERT_MULTIPLE: 'M', }[get_app().vi_state.input_mode]
Example #10
Source File: clibuffer.py From athenacli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def cli_is_multiline(cli): @Condition def cond(): doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document if not cli.multi_line: return False else: return not _multiline_exception(doc.text) return cond
Example #11
Source File: fancy-zsh-prompt.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_prompt() -> HTML: """ Build the prompt dynamically every time its rendered. """ left_part = HTML( "<left-part>" " <username>root</username> " " abc " "<path>~/.oh-my-zsh/themes</path>" "</left-part>" ) right_part = HTML( "<right-part> " "<branch> master<exclamation-mark>!</exclamation-mark> </branch> " " <env> py36 </env> " " <time>%s</time> " "</right-part>" ) % (datetime.datetime.now().isoformat(),) used_width = sum( [ fragment_list_width(to_formatted_text(left_part)), fragment_list_width(to_formatted_text(right_part)), ] ) total_width = get_app().output.get_size().columns padding_size = total_width - used_width padding = HTML("<padding>%s</padding>") % (" " * padding_size,) return merge_formatted_text([left_part, padding, right_part, "\n", "# "])
Example #12
Source File: filters.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def has_selected_completion(): """Enable when the current buffer has a selected completion.""" complete_state = get_app().current_buffer.complete_state return (complete_state is not None and complete_state.current_completion is not None)
Example #13
Source File: mssqlbuffer.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def mssql_is_multiline(mssql_cli): @Condition def cond(): doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document if not mssql_cli.multiline: return False if mssql_cli.multiline_mode == 'safe': return True return not _multiline_exception(doc.text) return cond
Example #14
Source File: mssqltoolbar.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_vi_mode(): return { InputMode.INSERT: 'I', InputMode.NAVIGATION: 'N', InputMode.REPLACE: 'R', InputMode.INSERT_MULTIPLE: 'M', }[get_app().vi_state.input_mode]
Example #15
Source File: key_bindings.py From pyvim with BSD 3-Clause "New" or "Revised" License | 5 votes |
def whitespace_before_cursor_on_line(): """ Filter which evaluates to True when the characters before the cursor are whitespace, or we are at the start of te line. """ b = get_app().current_buffer before_cursor = b.document.current_line_before_cursor return bool(not before_cursor or before_cursor[-1].isspace())
Example #16
Source File: layout.py From ptpython with BSD 3-Clause "New" or "Revised" License | 4 votes |
def get_inputmode_fragments(python_input: "PythonInput") -> StyleAndTextTuples: """ Return current input mode as a list of (token, text) tuples for use in a toolbar. """ app = get_app() @if_mousedown def toggle_vi_mode(mouse_event: MouseEvent) -> None: python_input.vi_mode = not python_input.vi_mode token = "class:status-toolbar" input_mode_t = "class:status-toolbar.input-mode" mode = app.vi_state.input_mode result: StyleAndTextTuples = [] append = result.append if python_input.title: result.extend(to_formatted_text(python_input.title)) append((input_mode_t, "[F4] ", toggle_vi_mode)) # InputMode if python_input.vi_mode: recording_register = app.vi_state.recording_register if recording_register: append((token, " ")) append((token + " class:record", "RECORD({})".format(recording_register))) append((token, " - ")) if app.current_buffer.selection_state is not None: if app.current_buffer.selection_state.type == SelectionType.LINES: append((input_mode_t, "Vi (VISUAL LINE)", toggle_vi_mode)) elif app.current_buffer.selection_state.type == SelectionType.CHARACTERS: append((input_mode_t, "Vi (VISUAL)", toggle_vi_mode)) append((token, " ")) elif app.current_buffer.selection_state.type == SelectionType.BLOCK: append((input_mode_t, "Vi (VISUAL BLOCK)", toggle_vi_mode)) append((token, " ")) elif mode in (InputMode.INSERT, "vi-insert-multiple"): append((input_mode_t, "Vi (INSERT)", toggle_vi_mode)) append((token, " ")) elif mode == InputMode.NAVIGATION: append((input_mode_t, "Vi (NAV)", toggle_vi_mode)) append((token, " ")) elif mode == InputMode.REPLACE: append((input_mode_t, "Vi (REPLACE)", toggle_vi_mode)) append((token, " ")) else: if app.emacs_state.is_recording: append((token, " ")) append((token + " class:record", "RECORD")) append((token, " - ")) append((input_mode_t, "Emacs", toggle_vi_mode)) append((token, " ")) return result