How do I add colors to my lines? #3391
-
I am making an application that reads in files from a filesystem and displays them (this I have) I am trying to figure out how I can have lines with different colors in the ListView or TextView. I want to be able to do something like this: (yellow) Lorem ipsum dolor (/yellow) The colors here are only meant to signify the color fo the line. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
TreeView has 'ColorGetter' and 'AspectGetter' that could achieve this. If
you set the builder to return empty (i.e. no children) then it will
function like list view.
You can add objects to the tree and decide color using the above delegates.
Alternatively you can look at the syntax highlighting scenario or do
something custom drawing.
But there is no markup and trying to use ansii escapes directly will not go
well. Terminal.Gui has a Driver layer which abstracts away color codes
into Attribute and ColorScheme so any attempt at drawing with codes
directly would mean fighting against the API instead of working with it.
…On Sun, 7 Apr 2024, 21:05 Hippo The Coder, ***@***.***> wrote:
I am making an application that reads in files from a filesystem and
displays them (this I have)
but based on certain rules I wish to highlight each line according the
ruleset.
I am trying to figure out how I can have lines with different colors in
the ListView or TextView.
I have tried various properties wth Terminal.GUI without solving it,
and I have various soltuions using ANSI codes more directly but each time
I just get hte escape codes
printed instead of the color change.
I want to be able to do something like this:
(yellow) Lorem ipsum dolor (/yellow)
(blue) sit amet, consectetur (/blue)
(blue) adipiscing elit, sed do (/blue)
(blue) eiusmod tempor incididunt (/blue)
(green) ut labore et dolore magna (/green)
(blue) Ut enim ad minim ((blue)
(pink) veniam, quis nostrud (/pink)
The colors here are only meant to signify the color fo the line.
I am not looking for markup syntax or anything like that.
—
Reply to this email directly, view it on GitHub
<#3391>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHO3C5F4BPHSNM5APRHN3KTY4GRIHAVCNFSM6AAAAABF3SP6K2VHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGQ3TGOJVGI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
To work with list view custom rendering you would want to
implement IListDataSource and particularly the Render method.
To get started you can copy code from ListWrapper
https://github.com/gui-cs/Terminal.Gui/blob/develop/Terminal.Gui/Views/ListView.cs#L817
…On Sun, 7 Apr 2024, 21:34 Thomas Nind, ***@***.***> wrote:
TreeView has 'ColorGetter' and 'AspectGetter' that could achieve this. If
you set the builder to return empty (i.e. no children) then it will
function like list view.
You can add objects to the tree and decide color using the above delegates.
Alternatively you can look at the syntax highlighting scenario or do
something custom drawing.
But there is no markup and trying to use ansii escapes directly will not
go well. Terminal.Gui has a Driver layer which abstracts away color codes
into Attribute and ColorScheme so any attempt at drawing with codes
directly would mean fighting against the API instead of working with it.
On Sun, 7 Apr 2024, 21:05 Hippo The Coder, ***@***.***>
wrote:
> I am making an application that reads in files from a filesystem and
> displays them (this I have)
> but based on certain rules I wish to highlight each line according the
> ruleset.
>
> I am trying to figure out how I can have lines with different colors in
> the ListView or TextView.
> I have tried various properties wth Terminal.GUI without solving it,
> and I have various soltuions using ANSI codes more directly but each time
> I just get hte escape codes
> printed instead of the color change.
>
> I want to be able to do something like this:
>
> (yellow) Lorem ipsum dolor (/yellow)
> (blue) sit amet, consectetur (/blue)
> (blue) adipiscing elit, sed do (/blue)
> (blue) eiusmod tempor incididunt (/blue)
> (green) ut labore et dolore magna (/green)
> (blue) Ut enim ad minim ((blue)
> (pink) veniam, quis nostrud (/pink)
>
> The colors here are only meant to signify the color fo the line.
> I am not looking for markup syntax or anything like that.
>
> —
> Reply to this email directly, view it on GitHub
> <#3391>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AHO3C5F4BPHSNM5APRHN3KTY4GRIHAVCNFSM6AAAAABF3SP6K2VHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGQ3TGOJVGI>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
-
The UICatalog has the "List View With Selection" scenario which uses different colors for even and odd lines. You can implement your own condition for display the wanted color. Take a look. |
Beta Was this translation helpful? Give feedback.
The UICatalog has the "List View With Selection" scenario which uses different colors for even and odd lines. You can implement your own condition for display the wanted color. Take a look.