Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* shows the current session user * shows the handler nodes connected with
- Loading branch information
Michael Beer
committed
Aug 9, 2017
1 parent
6a6070a
commit 881dbaf
Showing
2 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from prompt_toolkit.filters import IsDone, HasFocus, RendererHeightIsKnown, to_cli_filter, Condition | ||
from prompt_toolkit.enums import DEFAULT_BUFFER | ||
from prompt_toolkit.token import Token | ||
from prompt_toolkit.layout import Window, HSplit, VSplit, Float | ||
from prompt_toolkit.layout.containers import ConditionalContainer, FloatContainer | ||
from prompt_toolkit.layout.dimension import LayoutDimension | ||
from prompt_toolkit.layout.controls import TokenListControl, BufferControl, FillControl | ||
from prompt_toolkit.layout.lexers import PygmentsLexer | ||
from prompt_toolkit.layout.screen import Char | ||
from prompt_toolkit.layout.menus import CompletionsMenu | ||
from prompt_toolkit.layout.toolbars import TokenListToolbar | ||
from prompt_toolkit.layout.margins import PromptMargin, ConditionalMargin | ||
from prompt_toolkit.layout.utils import token_list_width | ||
|
||
__all__ = ( | ||
'create_layout', | ||
) | ||
|
||
def create_layout(message='', lexer=None, | ||
reserve_space_for_menu=8, | ||
get_prompt_tokens=None, | ||
get_bottom_toolbar_tokens=None, | ||
input_processors=None, multiline=False, | ||
wrap_lines=True): | ||
|
||
sidebar_token = [ | ||
(Token.Toolbar.Status.Key, "[ctrl+d]"), | ||
(Token.Toolbar.Status, " Exit") | ||
] | ||
sidebar_width = token_list_width(sidebar_token) | ||
|
||
multiline = to_cli_filter(multiline) | ||
get_prompt_tokens = lambda _: [(Token.Prompt, message)] | ||
get_sidebar_tokens = lambda _: sidebar_token | ||
lexer = PygmentsLexer(lexer, sync_from_start=True) | ||
|
||
def get_height(cli): | ||
# If there is an autocompletion menu to be shown, make sure that our | ||
# layout has at least a minimal height in order to display it. | ||
if reserve_space_for_menu and not cli.is_done: | ||
buff = cli.current_buffer | ||
|
||
# Reserve the space, either when there are completions, or when | ||
# `complete_while_typing` is true and we expect completions very | ||
# soon. | ||
if buff.complete_while_typing() or buff.complete_state is not None: | ||
return LayoutDimension(min=reserve_space_for_menu) | ||
|
||
return LayoutDimension() | ||
|
||
# Create and return Container instance. | ||
return HSplit([ | ||
VSplit([ | ||
HSplit([ | ||
# The main input, with completion menus floating on top of it. | ||
FloatContainer( | ||
HSplit([ | ||
Window( | ||
BufferControl( | ||
input_processors=input_processors, | ||
lexer=lexer), | ||
get_height=get_height, | ||
wrap_lines=wrap_lines, | ||
left_margins=[ | ||
# In multiline mode, use the window margin to display | ||
# the prompt and continuation tokens. | ||
ConditionalMargin( | ||
PromptMargin(get_prompt_tokens), | ||
filter=multiline | ||
) | ||
], | ||
), | ||
]), | ||
[ | ||
# Completion menu | ||
Float(xcursor=True, | ||
ycursor=True, | ||
content=CompletionsMenu( | ||
max_height=16, | ||
scroll_offset=1, | ||
extra_filter=HasFocus(DEFAULT_BUFFER))), | ||
] | ||
) | ||
]) | ||
]), | ||
] + [ | ||
VSplit([ | ||
ConditionalContainer( | ||
Window( | ||
TokenListControl(get_bottom_toolbar_tokens), | ||
height=LayoutDimension.exact(1) | ||
), | ||
filter=~IsDone() & RendererHeightIsKnown()), | ||
ConditionalContainer( | ||
Window( | ||
TokenListControl(get_sidebar_tokens), | ||
height=LayoutDimension.exact(1), | ||
width=LayoutDimension.exact(sidebar_width) | ||
), | ||
filter=~IsDone() & RendererHeightIsKnown()) | ||
]) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters