Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/sql: history-search result is messed up by line navigation #21826

Closed
andreimatei opened this issue Jan 26, 2018 · 11 comments · Fixed by #86457
Closed

cli/sql: history-search result is messed up by line navigation #21826

andreimatei opened this issue Jan 26, 2018 · 11 comments · Fixed by #86457
Assignees
Labels
A-cli-client CLI commands that pertain to using SQL features C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@andreimatei
Copy link
Contributor

andreimatei commented Jan 26, 2018

At the prompt, press Ctrl+R to get the history search, then type something to get a result:

root@:26257/t> alter table s add constraint b_unique unique (b);                                                                                                                   bck:alte

Now, I like my result but I want to edit it, so I press right arrow. At this point, the result is messed up because the characters [C show up at the beginning of the line. Escape sequence gone wrong?
This is with iterm2.

After pressing the right arrow, the line looks like this:

root@:26257/t> [Calter table s add constraint b_unique unique (b);

If you poke into the history code to fix this and you also do #21825 for me, you get my peer ack :P

Jira issue: CRDB-5873

Epic CRDB-22182

@andreimatei andreimatei added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jan 26, 2018
@andreimatei andreimatei added this to the 2.0 milestone Jan 26, 2018
@knz
Copy link
Contributor

knz commented Jan 26, 2018

I'll blame the terminal. This never happens to me. Have you tried with apple's regular terminal?

Also there's no special code in the current implementation to do this. The escape sequences to clear the line, move the cursor home, redraw the prompt, are all sent without any complication from the terminfo/termcap spec to the terminal. I'm wary to 1) spend hours to figure how your terminal diverges from expectations 2) bake a custom fix into some arbitrary fork of libedit (presumably we need to find the copy they use for osx, who knows what other osx-specific code there's in there) 3) vendor that 4) deal with the fallout when our vendored version becomes out of sync with whatever fixes needed upstream when folk upgrade their osx release.

So yeah, no. I'll leave the issue open until this can be further qualified, but I will certainly not work on it myself.

@knz knz modified the milestones: 2.0, Later Jan 26, 2018
@knz knz removed their assignment Jan 26, 2018
@andreimatei
Copy link
Contributor Author

Happens to me with OSX's Terminal app too. It doesn't happen on a Linux term?

Just in case this is news and rings a bell, [C is some sort of escape code for the right arrow.

Can I get another another person to confirm that this happens on iTerm2 and it's not just me - maybe I have a weird key binding in some config somewhere. @tschottdorf would you mind?

@tbg
Copy link
Member

tbg commented Feb 1, 2018

Happens to me too, in both.

@knz knz changed the title cli: history-search result is messed up by line navigation cli/sql: history-search result is messed up by line navigation Apr 11, 2018
@rmloveland
Copy link
Collaborator

@andreimatei I found a workaround for Terminal.app

  1. Open Preferences
  2. Go to Keyboard tab
  3. Click + to add a new keycode
  4. For Cursor Right key with no modifier, choose to Send Text. In the text area, I hit Ctrl-f (forward char in Emacs binding) to enter that code (you may want something else, this worked for me)
  5. Now when I find a result and press the right arrow, the cursor moves forward a char but does not insert the escape sequence and I can continue editing normally

@knz
Copy link
Contributor

knz commented Jul 20, 2018

we'll look into it during cli bug fixit day

@andreimatei
Copy link
Contributor Author

andreimatei commented Jul 20, 2018 via email

@knz
Copy link
Contributor

knz commented Aug 3, 2018

ok I found the bug, it's in upstream. While the history search mode is activated, the thing only recognizes regular key presses. an escape sequence like an arrow key is handled as an ESC key followed by [, A. The initial ESC character is interpreted as a request to abandon history search, and then the two characters [ A are handled as regular key precesses.

@knz
Copy link
Contributor

knz commented Aug 3, 2018

The proper behavior can be obtained like this:

  • press ^R to start searching
  • find the entry you want in the search
  • press enter to activate the selection
  • then, start to navigate to edit the entry

@knz
Copy link
Contributor

knz commented Aug 3, 2018

oh wow no "enter" actually also runs the command. now I understand why this won't do

@knz
Copy link
Contributor

knz commented Aug 3, 2018

Found a workaround: after finding your history entry press Ctrl+A or Ctrl+E or simply Ctrl+L.

@github-actions
Copy link

github-actions bot commented Jun 8, 2021

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
5 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@knz knz added A-cli-client CLI commands that pertain to using SQL features and removed no-issue-activity labels Jun 8, 2021
@knz knz removed this from the Later milestone Jun 8, 2021
craig bot pushed a commit that referenced this issue Dec 1, 2022
86457: cli: replace libedit with bubbline r=ZhouXing19 a=knz

First commit from #88574.
Benefits from (but is not dependent on) #87606 server-side.

Fixes #21826
Fixes #71207
Fixes #71209
Fixes #57885

NB: this will benefit from upstream library releases based off the still-unmerged PRs listed in knz/bubbline#2.

Release justification: n/a will not merge before stability ends

Release note (cli change): The engine used as line editor in the
interactive shell (`cockroach sql`, `demo`) has been updated. It
includes numerous bug fixes and new features.
The previous engine can still be accessed via the env
var COCKROACH_SQL_FORCE_LIBEDIT. This support will be removed
in a later version.

92335: kvserver,logstore: introduce log StateLoader r=tbg a=pavelkalinnikov

Previously the `StateLoader` accessed both log and state machine state. This commit moves most of the log-specific accesstors to the `logstore` package.

Part of #91979
Release note: None

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
Co-authored-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
@craig craig bot closed this as completed in #86457 Dec 1, 2022
@exalate-issue-sync exalate-issue-sync bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli-client CLI commands that pertain to using SQL features C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants