-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add string/binary type color to ByteStream
#12897
Conversation
squashed commits: ---- Be more strict about stream type, and always require it ---- make type non-Option, because None doesn't look very clear ---- also clean up tee a bunch ---- Add helpers for mapping between ByteStream and ListStream ---- do some cleanup and rethink how to map PipelineData into ByteStream ---- make describe output for byte streams mirror that of list streams ---- Temporary fix: print binary streams by collecting them through pretty_hex() first ---- fix `describe -n` on byte streams to not drain ---- streaming pretty hex output for binary streams ---- Don't pipe byte streams through `table` when passing to external commands ---- remove extraneous write ---- Replace the `VecDeque` with a `Cursor<Vec<u8>>` Since the vec is always empty when generating anyway, there's no need for a `VecDeque`. That would be better if we wanted to write stuff while there is still data. The `Cursor<Vec<u8>>` is less complex in implementation and should be a bit faster ---- preserve stream for `into binary`, `into string` ---- make sure `PipelineData::map` respects byte stream type ---- Make the Values iterator buffering more sensible Will return whatever buffers it gets, tries to assemble correct UTF-8 for strings. No line-based buffering here, use `lines` for that if you need it ---- fix `lines`, and change `Lines` to return strings without line ending ---- fix something broken by the merge ---- don't need to take line endings off in Lines because ByteLines already does it fixup 1
test str join
fix `join`: iter should not have been strict fixup 2 test bytes collect
Thanks @devyn, it looks good for the most part. Looks like there's some merge/rebase artifacts, sorry for all the force pushes lol. |
Does this not work just because all the commands haven't been ported yet? ❯ open README.md | into binary | first 100
Error: nu::shell::only_supports_this_input_type
× Input type not supported.
╭─[entry #2:1:1]
1 │ open README.md | into binary | first 100
· ──┬─ ──┬──
· │ ╰── only list, binary or range input data is supported
· ╰── input type: byte stream
╰──── |
Co-authored-by: Ian Manske <ian.manske@pm.me>
No worries Ian. @fdncred - since a ByteStream should behave the same way, I think I should fix that here. I don't want to cause anything to break in this PR, it should really just make things stream but otherwise work the same way they did before |
Co-authored-by: Ian Manske <ian.manske@pm.me>
Co-authored-by: Ian Manske <ian.manske@pm.me>
Co-authored-by: Ian Manske <ian.manske@pm.me>
sounds good to me. I just use first, last, skip, take quite a bit with binaries and into binary so I'd hope it would keep working. |
so I got Anyway it should all be consistent now |
@IanManske you mentioned |
I'm not sure either lol, I must have read the code wrong. Anyways, the tee looks much nicer now, thanks! |
Description
This PR allows byte streams to optionally be colored as being specifically binary or string data, which guarantees that they'll be converted to
Binary
orString
appropriately oninto_value()
, making them compatible withType
guarantees. This makes them significantly more broadly usable for command input and output.There is still an
Unknown
type for byte streams coming from external commands, which uses the same behavior as we previously did where it's a string if it's UTF-8.A small number of commands were updated to take advantage of this, just to prove the point. I will be adding more after this merges.
User-Facing Changes
describe
:string (stream)
,binary (stream)
into binary
into string
bytes collect
str join
first
(binary)last
(binary)take
(binary)skip
(binary)Tests + Formatting
I've added some tests to cover it at a basic level, and it doesn't break anything existing, but I do think more would be nice. Some of those will come when I modify more commands to stream.
After Submitting
There are a few things I'm not quite satisfied with:
Child
andFile
, but I don't know if this is quite right, and maybe we should bring back the old flag fortrim_end_newline
print --raw
, so that we can put binary data on stdout explicitly if we want to. This PR doesn't change how external commands work though - they still dump straight to stdout.Otherwise, here's the normal checklist:
type
field)