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

fix(line): render Line::styled correctly inside a paragraph #930

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

m4rch3n1ng
Copy link
Contributor

rendering a Paragraph with a Line::styled ignores the style, but using styled spans with a Line::default().spans(vec![Span::styled]) works just fine.

the issue seems to be, that the paragraph tries to render the styled_graphemes of the Spans instead of the Line directly

repro of the problem
fn ui(frame: &mut Frame) {
	let l1 = Line::styled("should be bold", Style::default().bold());
	let l2 = Line::styled("should be colorful", Style::default().cyan());
	let l3 = Line::styled("should be dim", Style::default().dim());

	let lp = Line::default();

	let s1 = vec![Span::styled("but it works with spans", Style::default().cyan())];
	let ls = Line::default().spans(s1);

	let block = Block::default()
		.borders(Borders::ALL)
		.padding(Padding::new(4, 4, 2, 2));
	let paragraph = Paragraph::new(vec![l1, l2, l3, lp, ls]).block(block);

	frame.render_widget(paragraph, frame.size());
}

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c3fb258) 92.0% compared to head (f35e86f) 92.0%.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #930   +/-   ##
=====================================
  Coverage   92.0%   92.0%           
=====================================
  Files         61      61           
  Lines      15521   15551   +30     
=====================================
+ Hits       14286   14316   +30     
  Misses      1235    1235           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kdheepak
Copy link
Collaborator

kdheepak commented Feb 6, 2024

Thanks for making a PR! Can you add a test to make sure this fixes it?

@m4rch3n1ng
Copy link
Contributor Author

done, idk what's going on with codecov though

@orhun orhun changed the title fix: Line::styled not being rendered correctly inside a paragraph fix(line): render Line::styled correctly inside a paragraph Feb 6, 2024
Copy link
Member

@joshka joshka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at some point we'll change this to style the entire line and not just the area covered by the spans, but this is fine as a bug fix.

@joshka joshka merged commit 0dcdbea into ratatui-org:main Feb 6, 2024
38 checks passed
@m4rch3n1ng m4rch3n1ng deleted the line_styled branch February 6, 2024 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants