Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Italic Borders? #1129

Closed
Jaxx497 opened this issue May 23, 2024 · 3 comments · May be fixed by #1190
Closed

Italic Borders? #1129

Jaxx497 opened this issue May 23, 2024 · 3 comments · May be fixed by #1190
Assignees
Labels
Status: In Progress Someone is actively working on this Status: Pending Waiting on clarification / more information from submitter Type: Documentation Improvements or additions to documentation

Comments

@Jaxx497
Copy link

Jaxx497 commented May 23, 2024

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

  • OS: Windows 11
  • Terminal Emulator: Windows Terminal
  • Font: Tested on multiple fonts including Lucida Console, SauceCodePro Nerd Font, NSimSun...
  • Crate version: 0.26.3
  • Backend: Crossterm

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),
    )
@Jaxx497 Jaxx497 added the Type: Bug Something isn't working label May 23, 2024
@joshka
Copy link
Member

joshka commented May 23, 2024

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

  • style applies to the entire block
  • border_style only overrides the things the style defines
  • title_style overrides any border_style
  • the italic modifier is defined in the style
  • the italic modifier is not overridden by a border style modifier that removes the italic

To fix:

.border_style(Style::new().red().on_black().not_italic())

@joshka joshka added Type: Bug Type: Documentation Improvements or additions to documentation and removed Type: Bugz labels Jun 19, 2024
joshka added a commit that referenced this issue Jun 19, 2024
@joshka
Copy link
Member

joshka commented Jun 19, 2024

@Jaxx497 Would you mind taking a quick look at #1190 and see if that helps clarify your questions here, and perhaps suggest some better wording if it doesn't?

@joshka joshka added Status: Pending Waiting on clarification / more information from submitter Status: In Progress Someone is actively working on this and removed Type: Bug Something isn't working labels Jun 19, 2024
@joshka joshka self-assigned this Jun 19, 2024
joshka added a commit that referenced this issue Jun 19, 2024
@Jaxx497
Copy link
Author

Jaxx497 commented Jun 19, 2024

@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

@Jaxx497 Jaxx497 closed this as completed Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress Someone is actively working on this Status: Pending Waiting on clarification / more information from submitter Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants