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

Line highlighting does not begin until backspace is pressed #768

Open
zesterer opened this issue Mar 12, 2024 · 4 comments
Open

Line highlighting does not begin until backspace is pressed #768

zesterer opened this issue Mar 12, 2024 · 4 comments

Comments

@zesterer
Copy link

I'm implementing some simple syntax highlighting based on example.rs. Syntax highlighting only seems to occur once backspace is pressed, and not after each keystroke (i.e: the input line appears unhighlighted until I press backspace at the end of the line, triggering a highlight).

At first I thought this was an issue in my own code, but I confirmed this to not be the case by placing if line.len() > 0 { panic!(); } within the body of my Highlighter::highlight function (the > 0 check is just to prevent a panic happening once at startup). As suspected, rustyline allows me to input whatever characters I want, only panicking if backspace is pressed.

@zesterer
Copy link
Author

zesterer commented Mar 12, 2024

Actually, my mistake: it seems that the default implementation of the highlight_char method returns false in all cases, so I needed to override this. I do think this is unexpected behaviour though: if not overriding it leads to incorrect behaviour, it should either (a) have a default implementation that does produce correct behaviour (return true) or (b) not have a default implementation.

I'll keep the issue open since this still seems like an unexpected default behaviour.

@gwenn
Copy link
Collaborator

gwenn commented Mar 12, 2024

As explain in highlight_char, rustyline must refresh the whole buffer at each key stroke if set to true.
You can can try to input a very large multiline input buffer and do some random change or just move the cursor.
I expect you to see some slowness...

@zesterer
Copy link
Author

zesterer commented Mar 31, 2024

I definitely understand that argument, but that only demonstrates that providing a default implementation of those methods is problematic: it took me quite a while to figure out that there was a method I was, in fact, supposed to override in order to produce the correct behaviour.

@gwenn
Copy link
Collaborator

gwenn commented Apr 1, 2024

I hope that one day rustyline will have the logic to redraw only the dirty cells / lines like textmode and change the default behaviour of highlight_char.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants