History search regressions in v2
See original GitHub issueDescription
I use pgcli
in vi and multi-line mode. It seems that history search with an empty query buffer has regressed in v2, possibly due to the prompt_toolkit
upgrade.
In v1.11.0 if I use history search with ctrl-r, having previously executed multi-line queries, I am shown the full query that matches the pattern. If I press ctrl-r again, I’m shown the full next query that matches. If I press ctrl-c the buffer is set to the first matching query.
In v2.1.0 after pressing ctrl-r and typing a pattern, I only see the line that matches the search pattern, which means it’s difficult to identify the correct query from my history. If I press ctrl-r again, the prompt is broken and just shows the pattern, but no matches (pressing ctrl-r again appears to do nothing in this state). If I exit the broken prompt with ctrl-c I’m shown a stacktrace, which I can exit with Enter - then the buffer is set to the first matching query.
Desired behaviour
Ideally, the history search would behave the same whether or not anything has been typed in the buffer, and regardless of the number of times ctrl-r is pressed, namely:
- Show the full matched query, not just the matching line
- Ctrl-c should return the buffer to the state before ctrl-r was pressed the first time
The first is a regression, but I suppose the latter is a feature request.
Reproduction
With ~/.config/pgcli/history
containing:
# 2019-04-06 00:00:00.000000
+SELECT a
+FROM (VALUES (1, 1), (1, 2)) v(a, b)
+ORDER BY a
# 2019-04-06 00:00:01.000000
+SELECT 1
# 2019-04-06 00:00:02.000000
+SELECT a
+FROM (VALUES (1, 1), (1, 2)) v(a, b)
+ORDER BY a DESC
# 2019-04-06 00:00:03.000000
+SELECT 2
# 2019-04-06 00:00:04.000000
+SELECT b
+FROM (VALUES (1, 1), (1, 2)) v(a, b)
+ORDER BY b
# 2019-04-06 00:00:05.000000
+SELECT 3
# 2019-04-06 00:00:06.000000
+SELECT b
+FROM (VALUES (1, 1), (1, 2)) v(a, b)
+ORDER BY b DESC
and an empty query buffer (so no partial query typed):
1.11.0
:
After pressing ctrl-r and typing ORDER
I see:
postgres@localhost:postgres> SELECT b
FROM (VALUES (1, 1), (1, 2)) v(a, b)
ORDER BY b DESC
I-search backward: ORDER
pressing ctrl-r again, I see:
postgres@localhost:postgres> SELECT b
FROM (VALUES (1, 1), (1, 2)) v(a, b)
ORDER BY b
I-search backward: ORDER
If I press ctrl-c I see:
postgres@localhost:postgres> SELECT b
FROM (VALUES (1, 1), (1, 2)) v(a, b)
ORDER BY b DESC
2.1.0
:
After pressing ctrl-r and typing ORDER
I see:
(reverse-i-search)`ORDER': ORDER BY b DESC
pressing ctrl-r again, I see:
ORDER
If I press ctrl-c I see:
Unhandled exception in event loop:
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/eventloop/posix.py", line 154, in _run_task
t()
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/eventloop/context.py", line 115, in new_func
return func(*a, **kw)
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 562, in read_from_input
self.key_processor.process_keys()
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/key_binding/key_processor.py", line 273, in process_keys
self._process_coroutine.send(key_press)
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/key_binding/key_processor.py", line 180, in _process
self._call_handler(matches[-1], key_sequence=buffer[:])
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/key_binding/key_processor.py", line 323, in _call_handler
handler.call(event)
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 78, in call
return self.handler(event)
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/search.py", line 28, in abort_search
search.stop_search()
File "/Users/owenstephens/.local/share/virtualenvs/pgcli_2.1.0-g_DKg-2C/lib/python2.7/site-packages/prompt_toolkit/search.py", line 128, in stop_search
del layout.search_links[search_buffer_control]
Exception <SearchBufferControl buffer=<Buffer(name=u'SEARCH_BUFFER', text=u'ORDER') at 4404687696> at 4404560272>
Press ENTER to continue...
If I press enter, I see:
postgres@localhost:postgres> SELECT b
FROM (VALUES (1, 1), (1, 2)) v(a, b)
ORDER BY b DESC
With a non-empty query buffer
If the query buffer is not empty at the point of pressing ctrl-r for the first time, the behaviour is the same in 1.11.0 and 2.1.0:
- If I ctrl-c after typing a pattern, my buffer is reset to its state prior to pressing ctrl-r,
- If I ctrl-c after typing a pattern and pressing ctrl-r again, the buffer is reset to the first matching query
Your environment
- Please provide your OS and version information. MacOS 10.13.6
- Please provide your CLI version. 1.11.0 and 2.1.0
- What is the output of
pip freeze
command.
1.11.0
:
backports.csv==1.0.7
cli-helpers==1.2.0
Click==7.0
configobj==5.0.6
humanize==0.5.1
pgcli==1.11.0
pgspecial==1.11.5
prompt-toolkit==1.0.15
psycopg2==2.7.7
Pygments==2.3.1
setproctitle==1.1.10
six==1.12.0
sqlparse==0.2.4
tabulate==0.8.3
terminaltables==3.1.0
wcwidth==0.1.7
2.1.0
:
backports.csv==1.0.7
cli-helpers==1.2.0
Click==7.0
configobj==5.0.6
humanize==0.5.1
pgcli==2.1.0
pgspecial==1.11.5
prompt-toolkit==2.0.9
psycopg2==2.7.7
Pygments==2.3.1
setproctitle==1.1.10
six==1.12.0
sqlparse==0.2.4
tabulate==0.8.3
terminaltables==3.1.0
wcwidth==0.1.7
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top GitHub Comments
That’s one well written bug report. Thank you!
It looks this way. @jonathanslenders, would you be able to help?