question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

selection mode highlighting is very confusing in my terminal

See original GitHub issue

This is with gnome-terminal on Linux, using ipython.

Suppose I have this text:

here is the mark: _ more text

I place my cursor on top of the underscore, and hit control-space, and then move my cursor around to perform various experiments:

What I see after moving my cursor to the left a bit (using [x] to indicate that x is displayed in reverse-font):

here is the mark[:][ ][_] more text

What this means: the text k: _ is selected, and will be cut if I hit control-W. Notice that k is not highlighted.

What I see immediately after hitting control-space, before moving the cursor anywhere:

here is the mark: _ more text

i.e., the cursor has disappeared, and nothing is highlighted. What this means: the text _ is selected, and will be cut if I hit control-W. (NB that in addition to being visually confusing, this is subtly incompatible with what emacs does, cf. #323 – for emacs, immediately after hitting control-space, the mark and point are both immediately to the left of the character that’s under the cursor, and so hitting control-W cuts the empty string.)

What I see after moving the cursor one space in either direction:

here is the mark: [_] more text

What this means: either the text _ (space and the following underscore) or the text _ (underscore and the following space) is selected and will be cut if hit control-W. These cases are visually indistinguishable.

What I see after placing the cursor top of the t at the end of the line:

here is the mark: [_][ ][m][o][r][e][ ][t][e][x]t

What I see after moving the cursor one more space to the right, so that it’s actually at the end of the line:

here is the mark: [_][ ][m][o][r][e][ ][t][e][x][t][ ]

i.e. moving the cursor one space to the right apparently causes two extra highlighted spaces to appear. AFAICT these two cases are identical in terms of what’s selected: in both cases, hitting control-W will cut the text _ more text (which is not what’s visually selected in either case!)

I think maybe there are two underlying bugs here:

  • prompt-toolkit should follow emacs and interpreter the mark and point as being placed at the space in between characters, to the left of where the cursor is when control-Space is pressed (for mark) and where the cursor is currently (for point)
  • prompt-toolkit’s attempt to highlight the selected region by reversing the text colors collides with gnome-terminal’s using this same approach to show the cursor. It would be better if prompt toolkit used some more distinctive mechanism for showing the highlight, like perhaps the light grey background that it uses for completion drop-downs.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jonathanslenderscommented, May 14, 2018

This fix has been merged: https://github.com/jonathanslenders/python-prompt-toolkit/pull/619 I think it should be fine now. Please let me know if I miss something. It doesn’t do the whole kill-ring thing yet, but that’s a different issue.

1reaction
asmeurercommented, May 10, 2018

Since this is somewhat of a backwards incompatible change, should this be considered for 2.0?

Read more comments on GitHub >

github_iconTop Results From Across the Web

bash - Why can't I highlight text in a linux terminal emulator ...
The problem isn't show some highlighted text but how to let know the X window application (the terminal emulator) that text been selected,...
Read more >
Pasted text in the terminal is always highlighted and selected
This confusing behavior is not present in Ubuntu 20.04. - In Ubuntu 20.04, when text is pasted into Gnome Terminal, the text is...
Read more >
How to fix terminal emacs selection highlighting - Stack Overflow
Ideally I want reverse video for selection so that it is reliably high-contrast, rather than looking for some color to use as the...
Read more >
Syntax highlighting in the terminal - Unix Stack Exchange
If you use Emacs as your editor of choice, you will get the same highlighting in the editor as you get when viewing...
Read more >
Pasted text in Gnome Terminal in 21.04 is always highlighted
If you try to select the highlighted text by clicking and dragging the mouse pointer, the text color actually inverts, and the text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found