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

Paragraph wrapped in a block can not be styled as expected #990

Closed
PierreQuebriac opened this issue Mar 20, 2024 · 2 comments · Fixed by #992
Closed

Paragraph wrapped in a block can not be styled as expected #990

PierreQuebriac opened this issue Mar 20, 2024 · 2 comments · Fixed by #992
Labels
bug Something isn't working

Comments

@PierreQuebriac
Copy link

PierreQuebriac commented Mar 20, 2024

Description

I was following the tutorial on the JSON editor: https://ratatui.rs/tutorials/json-editor/ and noticed a dissimilarity of result after compilation on the title step.

The tutorial offer to write this:

    let title_block = Block::default()
        .borders(Borders::ALL)
        .style(Style::default());

    let title = Paragraph::new(Text::styled(
        "Create New Json",
        Style::default().fg(Color::Green),
    ))
    .block(title_block);

    f.render_widget(title, chunks[0]);

And I was expecting to get a box with white borders surrounding a green text saying "Create new JSON" and after compilation I got a box with white borders and a white text.

To Reproduce

The easiest way to reproduce was to download the raratui website app here and run cargo run

Expected behavior

I was expected that a code like this

let title = Paragraph::new(Text::styled(
        "Create New Json",
        Style::default().fg(Color::Green),
    ))
    .block(
        Block::default()
            .borders(Borders::ALL)
            .style(Style::default()),
    );

would provide a white border box with a green text inside.

Screenshots

issue_screenshot

Environment

  • OS: Linux
  • Terminal Emulator: xterm
  • Font: Monospace
  • Crate version: 0.26.1
  • Backend: crossterm

Additional context

I noticed that in version 0.25.0 this bug does not happen

Thanks for helping me !

@PierreQuebriac PierreQuebriac added the bug Something isn't working label Mar 20, 2024
@orhun
Copy link
Sponsor Member

orhun commented Mar 20, 2024

Changing Text to Line fixes this:

diff --git a/code/ratatui-json-editor-app/src/ui.rs b/code/ratatui-json-editor-app/src/ui.rs
index edccbaa..8b47d4d 100644
--- a/code/ratatui-json-editor-app/src/ui.rs
+++ b/code/ratatui-json-editor-app/src/ui.rs
@@ -29,7 +29,7 @@ pub fn ui(f: &mut Frame, app: &App) {
         .borders(Borders::ALL)
         .style(Style::default());
 
-    let title = Paragraph::new(Text::styled(
+    let title = Paragraph::new(Line::styled(
         "Create New Json",
         Style::default().fg(Color::Green),
     ))

But yeah, I'd also expect Text::styled to apply the style as well. Not sure what's going on there.

@PierreQuebriac
Copy link
Author

It works ! Thank you for your help !

joshka added a commit that referenced this issue Mar 21, 2024
Paragraph was ignoring the new style field on Text added in 0.26.0

Fixes: #990
joshka added a commit that referenced this issue Mar 22, 2024
Paragraph was ignoring the new `Text::style` field added in 0.26.0

Fixes: #990
joshka added a commit to nowNick/ratatui that referenced this issue May 24, 2024
…#992)

Paragraph was ignoring the new `Text::style` field added in 0.26.0

Fixes: ratatui-org#990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants