-
Notifications
You must be signed in to change notification settings - Fork 20
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
nu-ansi-term overhaul #53
Conversation
way we do not call write_fmt unnecesarily, and use write_str/write_all for plain/non-formatting input.
… no longer need to specifically implement From<T> for Content for a wide variety of different T
…osts; however, now we have lifetime errors we must be careful about.
…tances, rather than separating it out into content/oscontrol/styles.
… string literals, as our raw string literals will already have been processed as a string literal by the compiler?
…ut, to arguments discovered in format string literal.
…returns Box<dyn Trait>. Fixed various errors in the quote! part of ansi_generics_macro.
…re wrong, because they were named prefix_with_reset (confusingly) before too
Thanks for the PR. It was good chatting with you on Discord about it. You're right, it's large, probably too large. What I'm trying to wrap my head around is why. What exactly are you trying to fix? Like I said in Discord, we probably won't accept the macros unless there's some great justification, which I'm not seeing yet but maybe it's hidden in all the changes. Also, breaking changes have to be justified. I really appreciate all your effort here but I don't see how we can accept this PR as is. Maybe others on the nushell core-team will jump in and help. |
…lly possible to make the style difference calculations const (using while loops, but for now I have not pursued that
The main thing I was trying to fix was: being able to give
format_args!
directly as objects that can be styled bynu-ansi-term
. The reasoning behind that was to 1) not have to allocateString
s unnecessarily when writing to a buffer, while still being able to format, and 2) to ease creation of ansi-formattable strings.I also discovered that there's a lot of unnecessary usage of
write!
, and in some cases, with unnecessary use offmt::Arguments
(i.e.write!(f, "{}", 39)
): so I removed those too, and simply made calls towrite_str
(here's the difference betweenwrite_str
andwrite!
: https://godbolt.org/z/WsTG345ac). This, surprisingly, required tweaking the way theAnyWrite
trait was set up. (This was a really long/painful bit, even though it is ultimately trivial to write out. I think my conclusion ultimately is that theAnyWrite
trait is a mistake. It is sufficient to have anio::Write
as the primary writer. There is no point in trying to generalize over fmt::Write and io::Write.)There are other performance improvements here too: the current version of nu-ansi-term re-calculates style differences every time a string is written to a writer:
nu-ansi-term/src/display.rs
Line 349 in f1c83ff
On the other hand, I cache the style updates, and only re-calculate them when there is a change/update to the strings/styles.
When trying to pass tests, I found that the
Difference
machinery was particularly difficult to work with (even though it is very simple) because of lots of code duplication:nu-ansi-term/src/difference.rs
Line 47 in f1c83ff
So I then worked to simplify that so that, by breaking it down into re-usable components. I used
bitflags
for this, because that's what I am familiar with.Upon trying to use what I was left with from the above, I realized that I really wished there was a way to nest ANSI strings, with some simple definition of how styles interact (for now, for me, parent styles merged with child styles is sufficient). So there's some functionality that allows one to give a parent style as a context to a child string.
Part of the goal with all of this was to run criterion benchmarks; but I'd run out of energy/motivation to do so, hence introduced the work as is. So, I've spun the work off into another crate, and when I have the energy to do benchmarks, will do those, but for now I need to get working on my actual projects