marcusolsson / tui-go

A UI library for terminal applications.
MIT License
2.1k stars 124 forks source link

Proposal: text entry highlight/select functionality #98

Open IngCr3at1on opened 6 years ago

IngCr3at1on commented 6 years ago

Basically I'd like to be able to highlight text in an entry without modifying it.

One use for this (my use) is a MUD client where you want to highlight the input text (automatically) to be able to erase it all with a single backspace (as an alternative to automatically clearing the text for the player).

marcusolsson commented 6 years ago

Hm, the first thing that comes to my mind is that Entry.Draw would have to somehow intelligently assign style names to part of the text. Not sure how you would specify the text to be highlighted, maybe something like entry.SetStyleNameRange("misspelled", 5, 3), where 5 is the offset from where the highlight should start and 3 is how many characters should be highlighted.

IngCr3at1on commented 6 years ago

@marcusolsson that could work however my title for this issue is a bit of a misnomer as what we're talking about is less about highlighting and more about selecting the text; so that it can all be erased with a single backspace instead of having to backspace through the complete text.

In that sense it's more than just a style issue...

marcusolsson commented 6 years ago

Selection is definitely on the roadmap. Both using mouse and programmatically, to define ranges. I don't have any specific solution in mind but here are some thoughts:

Basic functionality would include:

IngCr3at1on commented 6 years ago

@marcusolsson aye makes sense except I still think selection and highlighting go hand-in-hand so "content-space" wouldn't really work entirely; after-all you want to be able to tell that you selected text (by highlighting it in some way) that's going to effects view space.