| 47 | |
| 48 | |
| 49 | class MyCli(AppStateMixin, OutputMixin, ClientCommandsMixin, ClientConnectionMixin, ClientQueryMixin): |
| 50 | default_prompt = DEFAULT_PROMPT |
| 51 | default_prompt_splitln = "\\u@\\h\\n(\\t):\\d>" |
| 52 | max_len_prompt = 45 |
| 53 | prompt_lines: int |
| 54 | sqlexecute: SQLExecute | None |
| 55 | numeric_alignment: str |
| 56 | |
| 57 | # check XDG_CONFIG_HOME exists and not an empty string |
| 58 | xdg_config_home = os.environ.get("XDG_CONFIG_HOME", "~/.config") |
| 59 | system_config_files: list[str | IO[str]] = [ |
| 60 | "/etc/myclirc", |
| 61 | os.path.join(os.path.expanduser(xdg_config_home), "mycli", "myclirc"), |
| 62 | ] |
| 63 | |
| 64 | def __init__( |
| 65 | self, |
| 66 | sqlexecute: SQLExecute | None = None, |
| 67 | prompt: str | None = None, |
| 68 | toolbar_format: str | None = None, |
| 69 | logfile: TextIOWrapper | Literal[False] | None = None, |
| 70 | login_path: str | None = None, |
| 71 | auto_vertical_output: bool = False, |
| 72 | warn: bool | None = None, |
| 73 | myclirc: str = "~/.myclirc", |
| 74 | show_warnings: bool | None = None, |
| 75 | cli_verbosity: int = 0, |
| 76 | ) -> None: |
| 77 | self.sqlexecute = sqlexecute |
| 78 | self.logfile = logfile |
| 79 | self.login_path = login_path |
| 80 | self.toolbar_error_message: str | None = None |
| 81 | self.prompt_session: PromptSession | None = None |
| 82 | self._keepalive_counter = 0 |
| 83 | self.keepalive_ticks: int | None = 0 |
| 84 | self.sandbox_mode: bool = False |
| 85 | self.checkpoint: IO | None = None |
| 86 | |
| 87 | # Load config. |
| 88 | config_files: list[str | IO[str]] = self.system_config_files + [myclirc] |
| 89 | |
| 90 | c = self.config = read_config_files(config_files) |
| 91 | # only needed in --checkup mode. todo: only load when needed |
| 92 | self.config_without_package_defaults = read_config_files(config_files, ignore_package_defaults=True) |
| 93 | # only needed in --checkup mode. todo: only load when needed |
| 94 | self.config_without_user_options = read_config_files(config_files, ignore_user_options=True) |
| 95 | self.multi_line = c["main"].as_bool("multi_line") |
| 96 | self.key_bindings = c["main"]["key_bindings"] |
| 97 | self.emacs_ttimeoutlen = c['keys'].as_float('emacs_ttimeoutlen') |
| 98 | self.vi_ttimeoutlen = c['keys'].as_float('vi_ttimeoutlen') |
| 99 | special.set_timing_enabled(c["main"].as_bool("timing")) |
| 100 | special.set_show_favorite_query(c["main"].as_bool("show_favorite_query")) |
| 101 | if show_warnings is not None: |
| 102 | special.set_show_warnings_enabled(show_warnings) |
| 103 | else: |
| 104 | special.set_show_warnings_enabled(c['main'].as_bool('show_warnings')) |
| 105 | self.beep_after_seconds = float(c["main"]["beep_after_seconds"] or 0) |
| 106 | self.default_keepalive_ticks = c['connection'].as_int('default_keepalive_ticks') |