ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.78k stars 263 forks source link

Italic Borders? #1129

Closed Jaxx497 closed 1 week ago

Jaxx497 commented 1 month ago

Description

I've found that when displayed in the Windows terminal (via powershell), the borders of a widget will appear italicized.

To Reproduce

This is the relevant code that will reproduce the error (image below):

Block::new()
    .borders(Borders::ALL)
    .border_type(BorderType::Double)
    .border_style(Style::new().red().on_black())
    .title(Title::from(" Now Playing ").alignment(Alignment::Center))
    .style(Style::new().light_red().italic())

Expected behavior

I'd expect the borders to render normally (see code snippet at bottom for work-around)

Screenshots

image

Environment

Additional context

It's possible to workaround this issue with the following code. I didn't look too far into it, but it seems that the initial implementation is applying the italics to the border characters as well as the title characters, whereas the following implementation limits the italics to the title itself, but this feels far less intuitive to write out. It's worth noting that I did not see any problems with this when using Wezterm on Windows or Kitty on Arch Linux.

Block::new()
    .borders(Borders::ALL)
    .border_type(BorderType::Double)
    .border_style(Style::new().red().on_black())
    .title(
        Title::from(Line::from(vec![" Now Playing ".italic()]))
            .alignment(Alignment::Center),
    )
joshka commented 1 month ago

This is the intended behavior.

https://docs.rs/ratatui/latest/ratatui/widgets/block/struct.Block.html#method.border_style

If a Block::style is defined, border_style will be applied on top of it.

https://docs.rs/ratatui/latest/ratatui/widgets/block/struct.Block.html#method.style

This is the most generic Style a block can receive, it will be merged with any other more specific style. Elements can be styled further with Block::title_style and Block::border_style.

https://github.com/ratatui-org/ratatui/blob/main/examples/README.md#block shows examples of various combinations of styling

To fix:

.border_style(Style::new().red().on_black().not_italic())
joshka commented 1 week ago

@Jaxx497 Would you mind taking a quick look at https://github.com/ratatui-org/ratatui/pull/1190 and see if that helps clarify your questions here, and perhaps suggest some better wording if it doesn't?

Jaxx497 commented 1 week ago

@joshka I think this is a great addition to the documentation. The example in particular is thought out and easy to follow. Admittedly, my initial misunderstanding came from not realizing that .style() was overwriting the other styles (which now seems incredibly obvious). Thank you for taking the time to clarify this