rustyline icon indicating copy to clipboard operation
rustyline copied to clipboard

Highlighter Example

Open JesterOrNot opened this issue 5 years ago • 18 comments

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?

JesterOrNot avatar Jan 26 '20 21:01 JesterOrNot

Is there an update on this?

JesterOrNot avatar Mar 01 '20 22:03 JesterOrNot

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...

gwenn avatar Mar 02 '20 18:03 gwenn

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

JesterOrNot avatar Mar 02 '20 18:03 JesterOrNot

See https://github.com/JesterOrNot/rustsh

JesterOrNot avatar Mar 02 '20 18:03 JesterOrNot

What's wrong with: https://github.com/nushell/nushell/blob/f8be1becf28e29b728bd7cf481d3c717b0831751/src/shell/helper.rs#L67 ?

gwenn avatar Mar 02 '20 18:03 gwenn

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.

JesterOrNot avatar Mar 02 '20 19:03 JesterOrNot

See https://github.com/nushell/nushell/tree/master/crates/nu-parser

JesterOrNot avatar Mar 02 '20 19:03 JesterOrNot

I would prefer to add such minimal example when we have a Tokenizer.

gwenn avatar Mar 02 '20 19:03 gwenn

Can I contribute to the Tokenizer I really like this library

JesterOrNot avatar Mar 02 '20 19:03 JesterOrNot

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

gwenn avatar Mar 02 '20 19:03 gwenn

What still needs to be done? Can we create a draft PR?

JesterOrNot avatar Mar 02 '20 19:03 JesterOrNot

A draft PR would be perfect.

gwenn avatar Mar 02 '20 20:03 gwenn

Is there a branch where it is being worked on?

JesterOrNot avatar Mar 02 '20 20:03 JesterOrNot

Nope.

gwenn avatar Mar 02 '20 20:03 gwenn

So what is the idea behind the Tokenizer so that I can get started

JesterOrNot avatar Mar 02 '20 22:03 JesterOrNot

Provide a TokenTree / Document instead of a simple String for the Completer / Highlighter / Hinter / Validator.

gwenn avatar Mar 03 '20 21:03 gwenn

So basically a lexer?

JesterOrNot avatar Mar 10 '20 20:03 JesterOrNot

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.

gwenn avatar Mar 10 '20 20:03 gwenn