-
Notifications
You must be signed in to change notification settings - Fork 245
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
Expand tabs => configurable number of spaces to fix #150 #423
Expand tabs => configurable number of spaces to fix #150 #423
Conversation
Thinking about this some more, you replaced tabs at the line level, but most of the formatters can't actually emit tabs. Probably only from literals, message and prefix? So it might pay off to be precise about that. |
Yes, I agree. The code changes I am working on now will only replace inside those elements. Just wanted to check if you think it is acceptable complexity to also store away the original message & prefix and re-expand them when tab width changes? |
How about we only do that if message/prefix/template actually contained any tabs? |
So like this?
|
Something like that, yes. I'll need to see it in context. |
I've been working on this but it is turning out to be pretty ugly code. Trying to keep track of what strings are already expanded vs. not and then re-expanding everything when you change the tab size is unwieldly. To simplify things, what if I just added some mutually exclusive feature flags called "expand_tabs_four_spaces" and "expand_tabs_eight_spaces"? Realistically, I can't imagine why someone would change the size of a tab at runtime anyway. And if someone wants to do it, they can submit the PR :). |
I wonder if we can query the terminal for its tab size? https://unix.stackexchange.com/questions/46368/set-tab-width-in-gui-terminal |
I looked into that but I don't think there's any way to query it unless you actually print a tab and measure the difference in cursor position (e.g. https://unix.stackexchange.com/a/389266). Plus, who knows how Windows / macOS work. |
Maybe open an issue against console? This seems like the kind of thing that it could provide. |
OK, will do. |
On further thought, I don't think that console are any better positioned to fix this than we are, so I'm going to push on and attempt to make a fix. |
It makes more sense here anyway, plus it gets rid of the mem::swap stuff
f3b64b7
to
4e10054
Compare
OK, here's my latest attempt at fixing #150. Still need to write tests for it. |
bbcf003
to
eecba71
Compare
Sorry, it's been a very busy week, but this is definitely still on my list. |
@@ -232,7 +238,7 @@ impl ProgressStyle { | |||
} => { | |||
buf.clear(); | |||
if let Some(formatter) = self.format_map.get(key.as_str()) { | |||
buf.push_str(&formatter(state)); | |||
buf.push_str(&formatter(state).replace('\t', &" ".repeat(self.tab_width))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #420 this is changed to pass in a Formatter
directly. How do we change tab expansion in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll have to modify this line to apply the tab expansion on buf
before handing over to the formatter: https://github.com/console-rs/indicatif/pull/420/files#diff-5452dc5fb15e73154c0ecc33e87a14379a97f817fe0cdb0fb9d17df712feb8fbR243
eecba71
to
4760f8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with the remaining comments addressed. This has turned out quite nice!
4760f8b
to
b4fa333
Compare
OK, just going to wait for the tests to complete then I'll merge :) |
No description provided.