Replies: 7 comments 3 replies
-
Hi @truchi, thanks for the question, it's a great one. Sorry for the slow reply, I wish I had more time for open source work :-) With the changes I made for the 0.13 release, you should be able to wrap things that don't have a So in short, if you can give
Yeah, I think I know what you mean :-) I guess you want to turn on bold/cursive/... on a per-character basis? For textwrap to work, you would only need to group your #[derive(Debug)]
struct Word {
cells: Vec<Cell>,
whitespace: usize,
}
impl Fragment for Word {
fn width(&self) -> usize {
self.cells.len()
}
fn whitespace_width(&self) -> usize {
self.whitespace
}
fn penalty_width(&self) -> usize {
0
}
} I wrote a full example here which shows how these words can be wrapped into one or more lines, depending on the line width: playground. Please let me know if this helps, I would love to include an example with exactly this kind of functionality in the |
Beta Was this translation helpful? Give feedback.
-
Hello, thanks for the reply!
Yep it changed a lot since my previous issue, kudos!
Yes, in individual layers. When printing the flattened canvas to the terminal we can simplify because we are (supposedly) the single owner of I have to play with the Fragment trait to get a grasp of it. The "house building" example is still confusing to me since I didn't run it... I suggest including the output in the docs. Looking at your playground. I'm working on a different part of the project right now, I will be back at that sooner or later! |
Beta Was this translation helpful? Give feedback.
-
Yeah, I agree that it's a rather abstract example! :-) I wanted to show that you could use the wrapping algorithm for something way outside the realm of text — if you really really want to. Notice that you see the "output" indirectly via the It is honestly not so interesting to use
You would be responsible for determining the width of each cell — use The |
Beta Was this translation helpful? Give feedback.
-
Hey @truchi, I hope the above helped you a bit, otherwise please let me know. GitHub recently released a "discussion" feature and I'll try and convert this issue into the very first discussion in this repo 🎉 |
Beta Was this translation helpful? Give feedback.
-
Hello again! Yes you help me a lot, thank you for your time! I created a toy repo to play with theses ideas. I am assuming:
I did the very basics in that first try. The idea is somewhat different from what we talked about earlier. Have a look at So now I wonder how to use Besides that I wonder how to treat indentation and newlines in the input. (Bonus point for bug at width 20: the exlam is on a newline...) |
Beta Was this translation helpful? Give feedback.
-
Hey @truchi! Wow, looks cool what you've put together. Adding a
The first fn width(&self) -> usize {
// Lets say we live in a perfect world for now
self.string.chars().count()
} So this means that the space is double-counted. I've opened truchi/styledtextwrap#1 to fix this in our repository 😄 |
Beta Was this translation helpful? Give feedback.
-
See also #312 where I made a little demo of how one can wrap text for display on a HTML canvas — using a custom |
Beta Was this translation helpful? Give feedback.
-
Hello Sir,
I would like to talk about a use case I am thinking up. This is not really a feature request (as I understand it might be a huge patch), but an open question about building upon
textwrap
.Reading the docs and a few bits of the sources I found out that it may not possible to work with abstractions of text.
Let's say I am writing a terminal rendering pipeline in a layer superimposing fashion (i.e. a simple DOM for terminal). I want my users to be able to wrap text inside their "div"s, but also to style text inline, HTML-style:
I might then work with text with something like this:
As you can see, I cannot get an
&str
from that kind ofText
type. Yet I really need this styling meta with eachchar
to do some sort of painter algorithm, due to how terminal CSI work (they're global, I guess you know what I mean).What pieces from
core
would I be able to reuse, and to what extent, to build awrap
working with myCell
s?Thank you for your answer !
Beta Was this translation helpful? Give feedback.
All reactions