rustyline
rustyline copied to clipboard
Highlighter Example
After a few hours of reading the documentation and looking around online I was unable to understand how to implement a highlighter with rustyline can you give me a minimal example?
Is there an update on this?
There is a basic example here to highlight matching brackets. You can also search all dependent crates for more advanced examples: https://github.com/search?q=language%3Arust+rustyline+impl+Highlighter+syntax&type=Code Like https://github.com/nushell/nushell/blob/f8be1becf28e29b728bd7cf481d3c717b0831751/src/shell/helper.rs#L67
And you should be aware that, currently, highlighting is not always reevaluated each time you press a key at the end of line.
Furthermore, we would like to introduce a Tokenizer
to avoid reparsing whole input each time we do completion / highlighting / hinting / validation. So the API may change...
I was thinking more of an example of how to make your own like if I want to make it so that the exit is yellow or something like that. Instead of just showing the built-in ones
See https://github.com/JesterOrNot/rustsh
What's wrong with: https://github.com/nushell/nushell/blob/f8be1becf28e29b728bd7cf481d3c717b0831751/src/shell/helper.rs#L67 ?
Nothing, from time to time I help with nushell, I think it's awesome, but it's hard to replicate they use external libraries for parsing, etc I am proposing that you show a minimal example of how to create your own syntax highlighter with rustyline for people to build off of.
See https://github.com/nushell/nushell/tree/master/crates/nu-parser
I would prefer to add such minimal example when we have a Tokenizer
.
Can I contribute to the Tokenizer
I really like this library
Sure ! There is no draft but only comments here:
- https://github.com/kkawakam/rustyline/issues/207#issuecomment-585351357
- https://github.com/kkawakam/rustyline/issues/197#issuecomment-458282974
What still needs to be done? Can we create a draft PR?
A draft PR would be perfect.
Is there a branch where it is being worked on?
Nope.
So what is the idea behind the Tokenizer so that I can get started
Provide a TokenTree / Document instead of a simple String for the Completer / Highlighter / Hinter / Validator.
So basically a lexer?
An API compatible with an incremental lexer / parser.
We should pass the whole line
in case the lexer / parser is not incremental and a change
.
We should then have access to an AST / Document which can be used by Completer
/ Highlighter
/ Hinter
/ Validator
.