diff --git a/changelog.rst b/changelog.rst index 6ae26ca5..18640252 100644 --- a/changelog.rst +++ b/changelog.rst @@ -11,6 +11,7 @@ Bug fixes: ---------- * Fix issue where `syntax_style` config value would not have any effect. (#1212) +* Fix crash because of not found `InputMode.REPLACE_SINGLE` with prompt-toolkit < 3.0.6 3.1.0 ===== diff --git a/pgcli/pgtoolbar.py b/pgcli/pgtoolbar.py index f4289a1a..441a733d 100644 --- a/pgcli/pgtoolbar.py +++ b/pgcli/pgtoolbar.py @@ -1,15 +1,20 @@ +from packaging.version import parse as parse_version + +import prompt_toolkit from prompt_toolkit.key_binding.vi_state import InputMode from prompt_toolkit.application import get_app def _get_vi_mode(): - return { + modes = { InputMode.INSERT: "I", InputMode.NAVIGATION: "N", InputMode.REPLACE: "R", - InputMode.REPLACE_SINGLE: "R", InputMode.INSERT_MULTIPLE: "M", - }[get_app().vi_state.input_mode] + } + if parse_version(prompt_toolkit.__version__) >= parse_version("3.0.6"): + modes[InputMode.REPLACE_SINGLE] = "R" + return modes[get_app().vi_state.input_mode] def create_toolbar_tokens_func(pgcli):