MCPcopy
hub / github.com/dbcli/pgcli / _build_cli

Method _build_cli

pgcli/main.py:1039–1105  ·  view source on GitHub ↗
(self, history)

Source from the content-addressed store, hash-verified

1037 self.query_history.append(query)
1038
1039 def _build_cli(self, history):
1040 key_bindings = pgcli_bindings(self)
1041
1042 def get_message():
1043 if self.dsn_alias and self.prompt_dsn_format is not None:
1044 prompt_format = self.prompt_dsn_format
1045 else:
1046 prompt_format = self.prompt_format
1047
1048 prompt = self.get_prompt(prompt_format)
1049
1050 if prompt_format == self.default_prompt and len(prompt) > self.max_len_prompt:
1051 prompt = self.get_prompt("\\d> ")
1052
1053 prompt = prompt.replace("\\x1b", "\x1b")
1054 return ANSI(prompt)
1055
1056 def get_continuation(width, line_number, is_soft_wrap):
1057 continuation = self.multiline_continuation_char * (width - 1) + " "
1058 return [("class:continuation", continuation)]
1059
1060 get_toolbar_tokens = create_toolbar_tokens_func(self)
1061
1062 if self.wider_completion_menu:
1063 complete_style = CompleteStyle.MULTI_COLUMN
1064 else:
1065 complete_style = CompleteStyle.COLUMN
1066
1067 with self._completer_lock:
1068 prompt_app = PromptSession(
1069 lexer=PygmentsLexer(PostgresLexer),
1070 reserve_space_for_menu=self.min_num_menu_lines,
1071 message=get_message,
1072 prompt_continuation=get_continuation,
1073 bottom_toolbar=get_toolbar_tokens if self.show_bottom_toolbar else None,
1074 complete_style=complete_style,
1075 input_processors=[
1076 # Highlight matching brackets while editing.
1077 ConditionalProcessor(
1078 processor=HighlightMatchingBracketProcessor(chars="[](){}"),
1079 filter=HasFocus(DEFAULT_BUFFER) & ~IsDone(),
1080 ),
1081 # Render \t as 4 spaces instead of "^I"
1082 TabsProcessor(char1=" ", char2=" "),
1083 ],
1084 auto_suggest=AutoSuggestFromHistory() if self.auto_suggest else None,
1085 tempfile_suffix=".sql",
1086 # N.b. pgcli's multi-line mode controls submit-on-Enter (which
1087 # overrides the default behaviour of prompt_toolkit) and is
1088 # distinct from prompt_toolkit's multiline mode here, which
1089 # controls layout/display of the prompt/buffer
1090 multiline=True,
1091 history=history,
1092 completer=ThreadedCompleter(DynamicCompleter(lambda: self.completer)),
1093 complete_while_typing=True,
1094 style=style_factory(self.syntax_style, self.cli_style),
1095 include_default_pygments_style=False,
1096 key_bindings=key_bindings,

Callers 1

run_cliMethod · 0.95

Calls 3

pgcli_bindingsFunction · 0.85
style_factoryFunction · 0.85

Tested by

no test coverage detected