ratatui-org / ratatui

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

Inconsistent behavior between `Line::from` and `Line::raw` #1111

Closed kdheepak closed 2 weeks ago

kdheepak commented 1 month ago

Description

Line::from doesn't split the spans on new lines:

let line = Line::from("hello world\ngoodbye world");
dbg!(line.spans.len()) // 1

let line = Line::raw("hello world\ngoodbye world");
dbg!(line.spans.len()) // 2
EdJoPaTo commented 1 month ago

The idea of line is to have no new lines. So… not sure which is the more correct behaviour?

kdheepak commented 1 month ago

I would expect this to be correct behaviour:

let line = Line::raw("hello world\ngoodbye world");
dbg!(line.spans.len()) // 2

precisely because of the reason you've stated: Line shouldn't have newlines.

joshka commented 1 month ago

Two spans makes it possible to use &strs, one span would mean that an owned string would have to be constructed from the two lines. I think we currently just filter out the newlines when displaying the spans, so the behavior probably just works alright as-is, but going to two makes sense.