-
Notifications
You must be signed in to change notification settings - Fork 60
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
Newline '\n' in rendered strings not enough for working in terminal 'raw mode' #79
Comments
Hey thanks for logging the issue. Yeah we should fix that. Adding carriage returns wold probably be good. Thought maybe we add it as an option to not break the output right now? |
Hey! I would be glad to send a PR, will try to get around to it probably sometime in the next week or two. Is there a specific workflow you prefer I follow in regards to submitting a PR? |
People are using the output and making changes to the strings. Let's not make any changes to the output. So to ship this we need:
Then we can push out a new minor release. |
Pr open and ready for review: #80. Some other small things I encountered while working on this feature, that I thought I should raise and perhaps could be addressed in the future:
I could address those issues myself sometime, if you would be interested. |
Glad you added your observations here. Meant to ask.
Talk to me more about this.
Yeah that option has been a pain in the butt for a while. It's a negative flag to enable and I couldn't find another way to express it back then and now we have this API that is not worth break for this little thing. What would you suggest? Just name it the same internally? I don't really write node anymore these days so lost a bit of interest but force myself to keep both code bases in sync for compat reasons. |
In the rust implementation, the render function adds new lines by pushing String::New() onto the vector, creating a new string that holds the char \n. Later on, when the function checks alignment and modifies the string vector, it manually adds a number of \n chars to an existing string in the vector (and specifically in the rust implementation, the Top alignment works differently by pushing a new string into the vector, which consists of multiple \n chars). I'm pretty sure this is similar in the node implementation. Why is this undesired? Well, there are 2 reasons that come to mind for now:
I hope this makes my thoughts clear. If not, I'll gladly try to explain again. |
I think just changing the inner implementation to refer to space as spaceless, and to check for false instead of true, should do the trick. That would mean there would be no need to change the API. |
Ok got you. I agree with you on point one: we should make the implementation of adding new lines consistent for all alignment methods. I haven't looked at this for a while.
fn main() {
let mut foo = String::new();
println!("{:?}", foo.contains("\n"));
foo += "\n";
println!("{:?}", foo.contains("\n"));
}
// will print:
// false
// true I think you meant this differently. Lines 182 to 190 in 1a807b0
So here we check if thee is vertical space to be added. That seems consistent to me? So overall I agree with your point I just don't know in detail what you're proposing :) |
You're right, my bad. I got confused. String::new() just adds an empty string. I just realized, the add_line() function is meant to add another (empty) string to the vector, and the newlines get introduced later when you join() them to create the combined string. So currently, this is what happens:
I've given it some thought, and I'm not sure these things should be changed just yet. They should happen at some point, but I feel like they are potentially breaking changes, since they are modifying the structure of the text vector. Most users are probably just using the full string, so they wouldn't be affected, but anyone who is processing the text vector would find a different looking vector if we made these changes. I propose the following:
I know this isn't the cleanest, but it has the major benefit of not changing anything about the current implementation and potentially breaking stuff. Let me know your thoughts. |
Sorry for the laps of time ... Who knew time just progresses while you're busy with other things. |
Hey, no worries. Different time zones and personal priorities are going to create asynchronous collaboration. That's just how it is. |
Looks great. Thank you for that work. |
Ok everything is ready and #80 is merged |
FYI the tests broke because prettier failed the files because of the mix between |
Thanks for that. I would love to hear a bit more what you did to fix it, if you feel like explaining.
Thank you so much for letting me contribute! I'm very excited and happy to be a part of your project, and I enjoyed the discussions and collaboration. |
I had to configure git to not convert line endings on windows: cfonts/.github/workflows/testing.yml Lines 162 to 165 in ec003b1
For that to work I had to remove the working dir config: cfonts/.github/workflows/testing.yml Lines 160 to 162 in e00f0fa
And add it to each command manually: cfonts/.github/workflows/testing.yml Lines 195 to 205 in ec003b1
I also had to remove node 12 and 14 from the tests as Github actions has moved to ARM machines which don't support the old node versions anymore: cfonts/.github/workflows/testing.yml Lines 131 to 136 in ec003b1
|
Thanks for the explanation! Who knew newlines could be such a pain in the behind? 😆 By the way, I just noticed I didn't update any of the readme files 🤦♂️ You want me to submit some quick edits? |
No stress. I got the readme already updated but haven't pushed it yet. Thanks though. |
Ok v1.2.0rust and v3.2.0nodejs has been pushed out. It takes some time to hydrate to all channels (brew, macports etc) but it's out there now :) |
Hey! First of all, I wanted to say thanks for the awesome library! I was about to start planning how I implement something similar myself, so I'm really glad I stumbled upon your code :)
On to my use case:
I'm building a TUI application (using Termion as a backend), and I wanted to add some nice looking text blocks to make different game state screens as well as graphical transitions. I tried rendering a string and printing it, but the lines that make up the rendered string were not aligned, cutting up my text blocks length-wise. Anyways, after some time debugging, I found out the reason: when using the 'raw mode' provided by the backend, one of the differences from normal mode is that '\n' only moves the terminal cursor one line down, instead of doing a full line break and setting the cursor to the beginning of the line.
Currently, I can work around that pretty easily by just replacing '\n' with'\r\n' using the replace() method. However, I thought to raise the issue here, and see if you'd be interested in adding support for 'raw mode' strings. I would be happy to take a crack at it too, if you're interested and willing to accept contributions to the code.
What are your thoughts?
The text was updated successfully, but these errors were encountered: