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
A fill
command to replace str lpad
and str rpad
#7846
Conversation
Maybe this is a good place to address #7757 ? And the hangover from #7752? Since this new command is all about the graphic rendition, I'd say users will expect, e.g Unicode combining character: > let b = $"(char -u 1F468 200D 1F466 200D 1F466)"
> $b
👨👦👦
> $b | fill -a l -c '-' -w 7
👨👦👦- I'd expect that to be ANSI escapes: 〉let a = $"(ansi red)abc(ansi green)def(ansi reset)"
〉$a
abcdef
〉$a | fill -a l -c '-' -w 20
abcdef---
> I'd expect I've been looking for a place to put this capability and could take a crack at working it into your |
@bobhy Feel free to add your changes in this PR if github will allow you to do that. |
@bobhy I was wondering if you were going to add changes to this PR or if you want to land it and tweak after that? |
Sorry, I thought I'd do a warm up exercise first, that has expanded a bit.
Go ahead and merge it. I will come back and update it if my subsequent
brainstorm doesn't pan out.
I'm thinking now that what Nushell *really* needs is formatting directives
on string interpolation rather than a separate command, but haven't even
started that discussion yet.
…On Tue, Jan 31, 2023, 10:27 AM Darren Schroeder ***@***.***> wrote:
@bobhy <https://github.com/bobhy> I was wondering if you were going to
add changes to this PR or if you want to land it and tweak after that?
—
Reply to this email directly, view it on GitHub
<#7846 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPBIZFI7VSYGHDWPORUNBLWVEVPZANCNFSM6AAAAAAUEHS6LU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
storming in with the plans for the bikeshed I am not quite fond off the name (Personally I liked the explicit subcommands over flags with some possible values a bit more but I can see the added power/flexibility of this approach as well) |
Hey @sholderbach. The intent with this command is that:
Having said, all that. I'm up for a rename to I'm also not going to get my feelings hurt if we just close this PR. Just looking to consolidate some things. |
Hi @fdncred, I think there is good value in this approach and have given up on trying to shoehorn formatting directives into string variable interpolation. |
I'm holding my breath while pushing this button. Here goes nothing! |
…I escape codes (#8134) Enhancement of new `fill` command (#7846) to handle content including ANSI escape codes for formatting or multi-code-point Unicode grapheme clusters. In both of these cases, the content is (many) bytes longer than its visible length, and `fill` was counting the extra bytes so not adding enough fill characters. # Description This script: ```rust # the teacher emoji `\u{1F9D1}\u{200D}\u{1F3EB}` is 3 code points, but only 1 print position wide. echo "This output should be 3 print positions wide, with leading and trailing `+`" $"\u{1F9D1}\u{200D}\u{1F3EB}" | fill -c "+" -w 3 -a "c" echo "This output should be 3 print positions wide, with leading and trailing `+`" $"(ansi green)a(ansi reset)" | fill -c "+" -w 3 -a c echo "" ``` Was producing this output: ```rust This output should be 3 print positions wide, with leading and trailing `+` 🧑🏫 This output should be 3 print positions wide, with leading and trailing `+` a ``` After this PR, it produces this output: ```rust This output should be 3 print positions wide, with leading and trailing `+` +🧑🏫+ This output should be 3 print positions wide, with leading and trailing `+` +a+ ``` # User-Facing Changes Users may have to undo fixes they may have introduced to work around the former behavior. I have one such in my prompt string that I can now revert. # Tests + Formatting Don't forget to add tests that cover your changes. -- Done Make sure you've run and fixed any issues with these commands: - [x] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - [x] `cargo test --workspace` to check that all tests pass # After Submitting `fill` command not documented in the book, and it still talks about `str lpad/rpad`. I'll fix. Note added dependency on a new library `print-positions`, which is an iterator that yields a complete print position (cluster + Ansi sequence) per call. Should this be vendored?
Description
The point of this command is to allow you to be able to format ints, floats, filesizes, and strings with an alignment, padding, and a fill character, as strings. It's meant to take the place of
str lpad
andstr rpad
.User-Facing Changes
Deprecated
str lpad
andstr rpad
.Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --check
to check standard code formatting (cargo fmt --all
applies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect
to check that you're using the standard code stylecargo test --workspace
to check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.