prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.18k stars 277 forks source link

Bracket highlighting is counterintuitive #120

Open ned2 opened 8 years ago

ned2 commented 8 years ago

This might be specific to my configuration, but when I have parenthesis highlighting on and move my cursor to a parenthesis, the background colour of the cursor changes from white to dark blue while the matching parenthesis is highlighted a light purple. This is completely counter-intuitive for me as the changed contrast makes it feel like my cursor has jumped to the matching parenthesis. In this image the cursor is actually on the left paren but looks all the world like it's on the right paren.

parens_highlighting

I've had to disable parenthesis highlighting as using it just breaks my brain. I tried to look into where I could go about overriding the colours but did not get very far. Is it possible to customise this behaviour within ~/.ptpython/config.py?

jonathanslenders commented 8 years ago

Hi @ned2,

Thanks for reporting this. What terminal are you using?

@takluyver @Carreau This is probably also True for IPython. I'm going to do some more testing this evening. It should be possible to find a background color that works on all terminals.

Jonathan

ned2 commented 8 years ago

The screenshot was taken in Guake Terminal. I also see the same issue on Gnome Terminal.

On Fri, 27 May 2016 at 16:33 Jonathan Slenders notifications@github.com wrote:

Hi @ned2 https://github.com/ned2,

Thanks for reporting this. What terminal are you using?

@takluyver https://github.com/takluyver @Carreau https://github.com/Carreau This is probably also True for IPython. I'm going to do some more testing this evening. It should be possible to find a background color that works on all terminals.

Jonathan

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jonathanslenders/ptpython/issues/120#issuecomment-222070926, or mute the thread https://github.com/notifications/unsubscribe/ACs1GHQTvE2jvsYqJCcu7tsz_we1sibxks5qFpBAgaJpZM4IoJcS .

ned2 commented 8 years ago

What about just leaving the cursor background color unchanged -- so in my setup where the screenshot was taken, the cursor (which is on the left paren) would be backgrounded white (with the character color inverted)? This makes tracking the cursor simple. It's also how the emacs package smartparens does bracket highlighting. (and of course you'd still see the highlighted color that matches the corresponding paren during the off blinks -- if you have it set to blink)

infmagic2047 commented 8 years ago

Maybe matching brackets should use two different tokens instead of only one (Token.MatchingBracket).

takluyver commented 8 years ago

@jonathanslenders thanks for the heads up. We'll keep an eye on it, and we can always turn the default back off if it looks like it's going to be more trouble than it's worth. I'm enjoying it so far!

ned2 commented 8 years ago

I just cloned the IPython master branch and I'm seeing the same confusing highlighting. Perhaps this is not something that is a problem for everyone or there could be terminal/environments where the colours are not a problem.

For me, it's especially hard to visually process when you have an opening and a closing parenthesis with nothing between. When moving the cursor across the two characters, I consistently think that my cursor is on the other paren that it actually is and start writing text outside of the parentheses.

On Fri, 27 May 2016 at 20:51 Thomas Kluyver notifications@github.com wrote:

@jonathanslenders https://github.com/jonathanslenders thanks for the heads up. We'll keep an eye on it, and we can always turn the default back off if it looks like it's going to be more trouble than it's worth. I'm enjoying it so far!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jonathanslenders/ptpython/issues/120#issuecomment-222117700, or mute the thread https://github.com/notifications/unsubscribe/ACs1GHRsBR_zaLbU_vaC9TRB_Smka7eOks5qFsydgaJpZM4IoJcS .

Carreau commented 8 years ago

I think the confusion is because matching bracket have a bg color.

I would be in favor of changing the default matching bracket style to something without backgroud:

    Token.MatchingBracket:                        '#00bbee bold',

For example seem to work great on light and dark, Bold seem necessary as brackets have often only few pixels, so bold increase the visual contrast at the edge of the vision. Underline can also be effective.

ned2 commented 8 years ago

I agree this is part of the problem, but I think the matching bracket's bg color changing is only a problem in conjunction with the current cursor bg color changing to a dark color -- which makes the matching cursor look like the current cursor. I think it would be sufficient to change the behavior of the current cursor and leave the matching token's bg color the untouched.

On Sun, 29 May 2016 at 03:44 Matthias Bussonnier notifications@github.com wrote:

I think the confusion is because matching bracket have a bg color.

I would be in favor of changing the default matching bracket style to something without backgroud:

Token.MatchingBracket:                        '#00bbee bold',

For example seem to work great on light and dark, Bold seem necessary as brackets have often only few pixels, so bold increase the visual contrast at the edge of the vision. Underline can also be effective.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jonathanslenders/ptpython/issues/120#issuecomment-222320629, or mute the thread https://github.com/notifications/unsubscribe/ACs1GAdpP3xbt95wQ5YV9n_2_O3R_iuUks5qGH72gaJpZM4IoJcS .

jonathanslenders commented 8 years ago

Hi all,

Yesterday, I did some experiments, and the following commit is the best that I could get. (With background color.) It looks good in gnome-terminal dark+light background, Guake, xterm black+white background: https://github.com/jonathanslenders/python-prompt-toolkit/commit/3e17fdf2f2aa3da8778365f3a62b6bcae204c60b

In that commit, I also use a different token for a bracket that is under the cursor position. So, you can style it differently. I think I keep the style from that commit as the default in prompt-toolkit, but anyone should be able to override it. It is impossible to find anything that works everywhere. Even the defaults from Vim that I tried to copy don't work everywhere.

For ptpython: I have a second look later on.

edit: Also, after that commit, if no background or foreground is given for the a brace, it will take the original background from the original token, returned by the lexer.

Jonathan

Carreau commented 8 years ago

I agree this is part of the problem, but I think the matching bracket's bg color changing is only a problem in conjunction with the current cursor bg color changing to a dark color -- which makes the matching cursor look like the current cursor. I think it would be sufficient to change the behavior of the current cursor and leave the matching token's bg color the untouched.

Ah, but that's a missunderstanding, ptk does not change the color of the cursor. In most terminals the color of the cursor is just "inverted" with respect to the rest of the text: smc

If you just remove the background color from the matched bracket,the cursor does not change:

smc2

Agreed we could hack around and have a specific token type if cursor in on the bracket, but that seem overkill.

Note, the cursor being a box is also a choice of the terminal emulator, I can chose it to be underlined, or a vertical bar as well.

ned2 commented 8 years ago

@Carreau ah right, yeah that makes much more sense -- the dark background color was just the inverted color of the matching parenthesis.

In my current Emacs setup, I wind up with behaviour that looks the same as the Smart Cursor Color behaviour from iterm2. Not sure how Emacs achieves this, but seeing as this feels like it just works, it felt like ptpython/prompt_toolkit was doing something extra/weird.

@jonathanslenders ah fantastic, default colors are now much more comprehensible to me. Thanks!

naggie commented 7 years ago

I'd love to be able to disable this.

image

Which one is the cursor?

mixmastamyk commented 4 months ago

What is the color-scheme key to customize this? The default is too bright on a dark background/light text. I had to shut it off. 😞