[GH-ISSUE #249] Font modifier cell options (bold, italic, underline) #137

Closed
opened 2026-03-03 16:22:43 +03:00 by kerem · 14 comments
Owner

Originally created by @dyc3 on GitHub (Nov 7, 2020).
Original GitHub issue: https://github.com/mum4k/termdash/issues/249

Originally assigned to: @dyc3 on GitHub.

It's currently not possible to set text as bold, italic, underline, or strikethrough.

Modifier ANSI
Bold \e[1m
Italics \e[3m
Underline \e[4m
Strikethrough \e[9m
Originally created by @dyc3 on GitHub (Nov 7, 2020). Original GitHub issue: https://github.com/mum4k/termdash/issues/249 Originally assigned to: @dyc3 on GitHub. It's currently not possible to set text as bold, italic, underline, or strikethrough. | Modifier | ANSI | |-|-| | Bold | `\e[1m` | | Italics | `\e[3m` | | Underline | `\e[4m` | | Strikethrough | `\e[9m` |
kerem 2026-03-03 16:22:43 +03:00
Author
Owner

@mum4k commented on GitHub (Nov 10, 2020):

This is a good point. Looks like we are in luck and both of our terminal layer libraries support at least some of these attributes (details below). Looks like tcell supports more of them than termbox-go, so this may be a point where we start breaking away from termbox.

termbox-go: github.com/nsf/termbox-go@9b52a5faed/api_common.go (L155-L159)
tcell: github.com/gdamore/tcell@7d87d8188c/style.go (L87-L127)

@dyc3 please let me know if you are interested in implementing this feature in termdash. If you are, I can provide some pointers. Alternatively I could work on this in the near future.

<!-- gh-comment-id:724461709 --> @mum4k commented on GitHub (Nov 10, 2020): This is a good point. Looks like we are in luck and both of our terminal layer libraries support at least some of these attributes (details below). Looks like tcell supports more of them than termbox-go, so this may be a point where we start breaking away from termbox. termbox-go: https://github.com/nsf/termbox-go/blob/9b52a5faed9e2c795f64459fd13cd179c2b0ab2f/api_common.go#L155-L159 tcell: https://github.com/gdamore/tcell/blob/7d87d8188c8d3a236c778107d4925a9b2465a5f6/style.go#L87-L127 @dyc3 please let me know if you are interested in implementing this feature in termdash. If you are, I can provide some pointers. Alternatively I could work on this in the near future.
Author
Owner

@dyc3 commented on GitHub (Nov 10, 2020):

I could give it a shot. If you could point me in the right direction that would help a lot.

<!-- gh-comment-id:724490074 --> @dyc3 commented on GitHub (Nov 10, 2020): I could give it a shot. If you could point me in the right direction that would help a lot.
Author
Owner

@mum4k commented on GitHub (Nov 11, 2020):

Thank you @dyc3 for the offer of help. I will compile some instructions and pointers and respond here once done.

<!-- gh-comment-id:725192681 --> @mum4k commented on GitHub (Nov 11, 2020): Thank you @dyc3 for the offer of help. I will compile some instructions and pointers and respond here once done.
Author
Owner

@mum4k commented on GitHub (Nov 11, 2020):

Termdash has a core concept - a terminal is essentially a cell buffer, i.e. a 2D matrix of cells. Each cell is represented as the Cell object:

github.com/mum4k/termdash@2a7dafa3a8/private/canvas/buffer/buffer.go (L36-L43)

Notice the cell.Options object which stores options for each cell instance:

github.com/mum4k/termdash@2a7dafa3a8/cell/cell.go (L25-L28)

When Termdash draws the cell buffer onto a terminal, it accesses the terminal true this API:

github.com/mum4k/termdash@2a7dafa3a8/terminal/terminalapi/terminalapi.go (L25-L27)

Which currently has two implementations, one for termbox-go and one for tcell. Notice that the SetCell method directly takes a list of cell options that it applies using methods specific to the implementation:

github.com/mum4k/termdash@2a7dafa3a8/terminal/terminalapi/terminalapi.go (L46)

Hopefully this introduction helps, what we need to do is:

  1. define new (additional) cell options to represent font properties we want to implement (bold, underline, etc.).
  2. update termbox-go and tcell terminalapi implementations to correctly translate these new cell options into calls required to make them work. I have included links to options supported by termbox-go and tcell above in the discussion on this issue.

Note that termbox-go supports a smaller set of options, but we can still implement all of them in termdash. The SetCell method on the terminalapi interface returns an error, so we can simply return an error if say termdash was started with termbox-go and an unsupported option was requested.

Please feel free to let me know if I can provide more details and thanks again for your help.

<!-- gh-comment-id:725196217 --> @mum4k commented on GitHub (Nov 11, 2020): Termdash has a core concept - a terminal is essentially a cell buffer, i.e. a 2D matrix of cells. Each cell is represented as the Cell object: https://github.com/mum4k/termdash/blob/2a7dafa3a835dbe45d9a6eaa2f22e184666c8065/private/canvas/buffer/buffer.go#L36-L43 Notice the cell.Options object which stores options for each cell instance: https://github.com/mum4k/termdash/blob/2a7dafa3a835dbe45d9a6eaa2f22e184666c8065/cell/cell.go#L25-L28 When Termdash draws the cell buffer onto a terminal, it accesses the terminal true this API: https://github.com/mum4k/termdash/blob/2a7dafa3a835dbe45d9a6eaa2f22e184666c8065/terminal/terminalapi/terminalapi.go#L25-L27 Which currently has two implementations, one for termbox-go and one for tcell. Notice that the `SetCell` method directly takes a list of cell options that it applies using methods specific to the implementation: https://github.com/mum4k/termdash/blob/2a7dafa3a835dbe45d9a6eaa2f22e184666c8065/terminal/terminalapi/terminalapi.go#L46 Hopefully this introduction helps, what we need to do is: 1. define new (additional) cell options to represent font properties we want to implement (bold, underline, etc.). 1. update termbox-go and tcell terminalapi implementations to correctly translate these new cell options into calls required to make them work. I have included links to options supported by termbox-go and tcell above in the discussion on this issue. Note that termbox-go supports a smaller set of options, but we can still implement all of them in termdash. The `SetCell` method on the terminalapi interface returns an error, so we can simply return an error if say termdash was started with termbox-go and an unsupported option was requested. Please feel free to let me know if I can provide more details and thanks again for your help.
Author
Owner

@dyc3 commented on GitHub (Nov 11, 2020):

I've found that both termbox and tcell don't support italics or strikethrough. I'm guessing that it's because it's not supported by a decent number of terminal emulators, but most of the popular ones seem to support it. Should I just implement this for bold and underline for now until one of the backends supports it?

<!-- gh-comment-id:725268687 --> @dyc3 commented on GitHub (Nov 11, 2020): I've found that both termbox and tcell don't support italics or strikethrough. I'm guessing that it's because it's not supported by a decent number of terminal emulators, but most of the popular ones seem to support it. Should I just implement this for bold and underline for now until one of the backends supports it?
Author
Owner

@mum4k commented on GitHub (Nov 11, 2020):

If having bold and underline helps you in the meantime, we can start with those. Note that it is also a possibility for us to contribute new functionality to tcell. I would expect the author to accept new options assuming they work in the popular terminals.

<!-- gh-comment-id:725451550 --> @mum4k commented on GitHub (Nov 11, 2020): If having bold and underline helps you in the meantime, we can start with those. Note that it is also a possibility for us to contribute new functionality to `tcell`. I would expect the author to accept new options assuming they work in the popular terminals.
Author
Owner

@dyc3 commented on GitHub (Nov 12, 2020):

It turns out tcell already supports italics and strikethrough. We just need to update tcell's version. Will send a PR shortly.

<!-- gh-comment-id:726318150 --> @dyc3 commented on GitHub (Nov 12, 2020): It turns out tcell already supports italics and strikethrough. We just need to update tcell's version. Will send a PR shortly.
Author
Owner

@mum4k commented on GitHub (Nov 13, 2020):

Thank you for pointing out that tcell upgraded to 2.x. I have filed #254 to follow up. Reading their changelog - there are a few breaking changes that we will need to accomodate.

<!-- gh-comment-id:726866894 --> @mum4k commented on GitHub (Nov 13, 2020): Thank you for pointing out that `tcell` upgraded to 2.x. I have filed #254 to follow up. Reading their changelog - there are a few breaking changes that we will need to accomodate.
Author
Owner

@mum4k commented on GitHub (Nov 14, 2020):

What we are aiming for now is to perform the tcell upgrade and add the italics and strikethrough functionality before we push the next release.

However feel free to let me know if you would prefer if we release in the current state to make the changes you contributed available at master.

<!-- gh-comment-id:727162256 --> @mum4k commented on GitHub (Nov 14, 2020): What we are aiming for now is to perform the `tcell` upgrade and add the italics and strikethrough functionality before we push the next release. However feel free to let me know if you would prefer if we release in the current state to make the changes you contributed available at master.
Author
Owner

@mum4k commented on GitHub (Nov 16, 2020):

@dyc3 with tcell upgraded, do you have the time to send a PR adding support for the remaining font attributes?

<!-- gh-comment-id:727723502 --> @mum4k commented on GitHub (Nov 16, 2020): @dyc3 with `tcell` upgraded, do you have the time to send a PR adding support for the remaining font attributes?
Author
Owner

@dyc3 commented on GitHub (Nov 16, 2020):

Yup! Will do

<!-- gh-comment-id:727737295 --> @dyc3 commented on GitHub (Nov 16, 2020): Yup! Will do
Author
Owner

@mum4k commented on GitHub (Nov 16, 2020):

Great, thank you.

<!-- gh-comment-id:727737474 --> @mum4k commented on GitHub (Nov 16, 2020): Great, thank you.
Author
Owner

@mum4k commented on GitHub (Nov 17, 2020):

Thank you for your help on this feature and with upgrading tcell @dyc3. I will push a new release to master shortly.

<!-- gh-comment-id:729164309 --> @mum4k commented on GitHub (Nov 17, 2020): Thank you for your help on this feature and with upgrading `tcell` @dyc3. I will push a new release to master shortly.
Author
Owner

@mum4k commented on GitHub (Nov 18, 2020):

Resolved by #266

<!-- gh-comment-id:729400082 --> @mum4k commented on GitHub (Nov 18, 2020): Resolved by #266
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/termdash#137
No description provided.