rhysd / tui-textarea

Simple yet powerful multi-line text editor widget for ratatui and tui-rs
https://crates.io/crates/tui-textarea
MIT License
265 stars 54 forks source link

Feature Request: syntax highlighting #63

Open juarezr opened 4 months ago

juarezr commented 4 months ago

Hi,

Do you have any plans for supporting syntax highlighting in the widget?

There are some crates that could help, but I don't know if there is interest in having syntax highlighting as a feature.

Julien-cpsn commented 4 months ago

YES PLEASE

Or at least it would be great to have the possibility to use TextArea with ratatui's Line, since we can color the Spans inside ourselves

KiraCoding commented 3 months ago

I think this would be awesome to have, I'm writing a code editor right now and well syntax highlighting is a key feature of every code editor. I hope someone works on this.

Julien-cpsn commented 3 months ago

I think this would be awesome to have, I'm writing a code editor right now and well syntax highlighting is a key feature of every code editor. I hope someone works on this.

I am doing kind of the same thing and I succeed to apply Syntax highlighting on a Vec of Line into a Paragraph using Syntect. But since the TextArea does not work with a Vec of Line, it's incompatible...

https://github.com/Julien-cpsn/ATAC/blob/main/src%2Futils%2Fsyntax_highlighting.rs#L15

(After digging a little the component, it is rendered by transforming the String to a Vec of Line and putting into a Paragraph. So we might not be that far)

Julien-cpsn commented 2 months ago

Hello guys!

I tried to make a fork and do a quick implementation. Everything works great until you have a tab. The lib creator has put some mechanism to replace \t by some spaces (according to widget tab_len property) only in the text representation. It increments the line length but not the actual text length. I can't get to fix it.... It took me about 5h to do this and I don't to play with it anymore to keep some sanity

Here is the link of my fork: https://github.com/Julien-cpsn/tui-textarea

If you wish to correct this problem, it would be greatly appreciated!!!!

Here are some screenshots:

image image