Conversation
src/lib.rs
Outdated
| /// It also supports terminal colors, but this is currently private. | ||
| /// | ||
| /// [`Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html | ||
| pub struct Formatter { |
There was a problem hiding this comment.
I think I'll move this into a new fmt module, since when we do make colouring public there will probably be some more types to go along with it.
If you just create your closure as part of the .format call then you won't need to name the Formatter type directly.
src/lib.rs
Outdated
| // The format is guaranteed to be `Some` by this point | ||
| let mut formatter = tl_buf.as_mut().unwrap(); | ||
|
|
||
| let _ = (self.format)(&mut formatter, record) |
There was a problem hiding this comment.
I think this should clarify its error conditions a bit better:
- We only print the record to the terminal if the record is successfully formatted (which it pretty much always should)
- We always clear the buffer even if the record wasn't printed. Seems like it might not be ideal, but I'm not really sure what would cause a print to fail.
I think it needs a little more thought and should be refactored to clarify the intent a bit better.
src/lib.rs
Outdated
| fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
| self.buf.set_color(&self.spec)?; | ||
| let write = self.buf.write(buf); | ||
| self.buf.reset()?; |
There was a problem hiding this comment.
Not returning the bytes written if the terminal fails to reset seems like a bad thing to do. Maybe.
|
Ok I'm happy. Docs can be dealt with down the track. @BurntSushi if you've got a few minutes sometime I'd be grateful if you could give this a quick scan and let me know if anything looks totally insane :) |
|
@KodrAus LGTM! Nice work. :-) |
> [!NOTE] > Mend has cancelled [the proposed renaming](https://redirect.github.com/renovatebot/renovate/discussions/37842) of the Renovate GitHub app being renamed to `mend[bot]`. > > This notice will be removed on 2025-10-07. <hr> This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [actions/setup-python](https://redirect.github.com/actions/setup-python) | action | major | `v5` -> `v6` | --- ### Release Notes <details> <summary>actions/setup-python (actions/setup-python)</summary> ### [`v6`](https://redirect.github.com/actions/setup-python/compare/v5...v6) [Compare Source](https://redirect.github.com/actions/setup-python/compare/v5...v6) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 5am on the first day of the month" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/epage/_rust). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzEuOSIsInVwZGF0ZWRJblZlciI6IjQxLjEzMS45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Closes #31 and #2 by using
termcolorto do the hard work.Colours
The default format now includes some colours:
The colour API is still private because I'm not sure how we want to expose it.
Buffering
This API goes back to buffering log records before printing them to the terminal, but we use a single buffer per thread rather than allocating for each log. I did some benchmarking and performance looks good overall.