-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configurable REPL settings in bohort
[test-312-latest] [pypi]
- Loading branch information
cipres
committed
Apr 19, 2024
1 parent
abea4b9
commit 374cea4
Showing
6 changed files
with
140 additions
and
49 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
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
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 |
---|---|---|
@@ -1,34 +1,48 @@ | ||
from ptpython.prompt_style import PromptStyle | ||
from ptpython.layout import CompletionVisualisation | ||
from prompt_toolkit.formatted_text import HTML | ||
from prompt_toolkit import print_formatted_text, HTML | ||
from omegaconf import DictConfig | ||
|
||
|
||
def configure(repl): | ||
def configure(config: DictConfig, repl) -> None: | ||
class CustomPrompt(PromptStyle): | ||
def in_prompt(self): | ||
return HTML("<ansigreen>bohort [%s]</ansigreen>: ") % ( | ||
repl.current_statement_index | ||
) | ||
return HTML("<{ipcolor}>bohort [{idx}]</{ipcolor}>: ".format( | ||
ipcolor=config.repl.input_prompt_color, | ||
idx=repl.current_statement_index | ||
)) | ||
|
||
def in2_prompt(self, width): | ||
return "...: ".rjust(width) | ||
|
||
def out_prompt(self): | ||
return HTML("<ansicyan>Result[%s]</ansicyan>: ") % ( | ||
repl.current_statement_index | ||
) | ||
return HTML("<{opcolor}>Result[{idx}]</{opcolor}>: ".format( | ||
opcolor=config.repl.output_prompt_color, | ||
idx=repl.current_statement_index | ||
)) | ||
|
||
repl.all_prompt_styles["custom"] = CustomPrompt() | ||
repl.cursor_shape_config = "Blink block" | ||
repl.cursor_shape_config = config.repl.cursor_shape | ||
repl.insert_blank_line_after_output = True | ||
repl.use_code_colorscheme('native') | ||
repl.prompt_style = "custom" | ||
repl.show_signature = True | ||
repl.enable_history_search = True | ||
repl.enable_auto_suggest = True | ||
repl.show_signature = config.repl.show_signature | ||
repl.enable_history_search = config.repl.enable_history_search | ||
repl.enable_auto_suggest = config.repl.enable_auto_suggest | ||
repl.title = 'bohort' | ||
repl.confirm_exit = False | ||
repl.confirm_exit = config.repl.confirm_exit | ||
repl.vi_keep_last_used_mode = True | ||
repl.completion_visualisation = CompletionVisualisation.POP_UP | ||
repl.completion_menu_scroll_offset = 0 | ||
repl.complete_while_typing = False | ||
repl.complete_while_typing = config.repl.complete_while_typing | ||
repl.enable_input_validation = True | ||
|
||
cvisual = config.repl.get('completion_visualisation') | ||
|
||
if cvisual in ['TOOLBAR', 'POP_UP', 'MULTI_COLUMN']: | ||
repl.completion_visualisation = getattr(CompletionVisualisation, | ||
cvisual) | ||
|
||
repl.use_code_colorscheme(config.repl.color_scheme) | ||
|
||
|
||
def pf_text(text: str, color: str = 'ansiyellow') -> None: | ||
print_formatted_text(HTML(f'<{color}>{text}</{color}>')) |
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,14 @@ | ||
nodes: {} | ||
rpc_methods: {} | ||
|
||
repl: | ||
cursor_shape: 'Blink block' | ||
input_prompt_color: 'ansigreen' | ||
output_prompt_color: 'ansiyellow' | ||
completion_visualisation: POP_UP | ||
color_scheme: default | ||
show_signature: true | ||
enable_history_search: true | ||
enable_auto_suggest: true | ||
complete_while_typing: false | ||
confirm_exit: false |
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
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