* Add streaming support to save for ExternalStream data
Prior to this change, save would collect data from an ExternalStream (data
originating from externals) consuming memory for the full amount of data piped
to it,
This change adds streaming support for ExternalStream allowing saving of
arbitrarily large files and bounding memory usage.
* Remove broken save test
This test passes but not for the right reasons, since this test was
written filename has become a required parameter. The parser outputs
an error but the test still passes as is checking the original un-mutated
file assuming save has re-written the contents.
This change removes the test.
```
running 1 test
=== stderr
Error: nu::parser::missing_positional (https://docs.rs/nu-parser/0.60.0/nu-parser/enum.ParseError.html#variant.MissingPositional)
× Missing required positional argument.
╭─[source:1:1]
1 │ open save_test_1/cargo_sample.toml | save
· ▲
· ╰── missing filename
╰────
help: Usage: save {flags} <filename>
test commands::save::figures_out_intelligently_where_to_write_out_with_metadata ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 515 filtered out; finished in 0.10s
```
* Add test for passing binary data through externals
This change adds an ignored test to confirm that binary data is passed
correctly between externals to be enabled in a later commit along with
the fix.
To assist in platform agnostic testing of binary data a couple of
additional testbins were added to allow testing on `Value::Binary` inside
`ExternalStream`.
* Support binary data to stdin of run-external
Prior to this change, any pipeline producing binary data (not detected
as string) then feed into an external would be ignored due to
run-external only supporting `Value::String` on stdin.
This change adds binary stdin support for externals allowing something
like this for example:
〉^cat /dev/urandom | ^head -c 1MiB | ^pv -b | ignore
1.00MiB
This would previously output `0.00 B [0.00 B/s]` due to the data not
being pushed to stdin at each stage.
Prior to this change, a pipeline of externals would result in high memory
usage if any of the producers in the chain, produced data faster than
the consumers.
For example a pipeline:
> fast-producer | slow-consumer
Would cause a build up of `Value::{String,Binary}`'s in the mpsc channels
between each command as values are added to the channels faster than they
are consumed, eventually OOM'ing depnding on system resources, the volume
of data and speed diff. between fast v's slow.
This change replaces the unbounded channels with bounded channels
to limit the number of values that can build up and providing
back-pressure to limit ram usage.
* Add android as target os for procfs-based ps
* Turn off code for dealing with trash on platforms which are known to not support a standard trash protocol
* Update lib.rs
* Update lib.rs
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
* Fix path when expanding tilde
Expanding tilde with no other relative paths would result in:
`$HOME/` instead of `$HOME`. This occurs when users run `cd` with
no extra arguments. In that case, the user's PWD would include the
trailing separator. This does not happen when explicitly passing
a value, such as `cd ~`, because in that case, the path would be
canonicalized.
This happens because std::path::PathBuf::push always adds a separator,
even if adding an empty path, which is what happens when `cd` is
invoked.
* Add test
* Fix test on Windows
Co-authored-by: Hristo Filaretov <h.filaretov@protonmail.com>
* Fix alias import
Alias importing was registering the alias id as a decl instead of alias.
This caused issues when hiding and then reimporting the alias.
* Clippy format
Co-authored-by: Hristo Filaretov <h.filaretov@protonmail.com>
* added missing metadata for drop and uniq #4763
* added missing metadata for keep #4763
* added missing metadata for append #4763
* added missing metadata for shuffle #4763
* add a display of what the colors look like in `ansi --list`
* change 'color' to 'preview' - add the ability to turn it off via config with use_ansi_coloring
To simplify use of nu-ansi-term in both nushell/nushell and
nushell/reedline remove it from the workspace to have a separate
progression of version numbers.
This allows reedline to use the latest published version and nushells
workspace to use the same most recent version
Changes the `Cargo.toml`s to use reedline from crates.io
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
* Refactor usage of is_perf_true to be a parameter passed around
* Move repl loop and command/script execution to nu_cli
* Move config setup out of nu_cli
* Update config_files.rs
* Update main.rs
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
* Refactor & fix which
Instead of fetching all definitions / aliases, only show the one that is
visible.
* Fix $nu.scope to show only visible definitions
* Add missing tests file; Rename one which test
* Do not pass non-string env vars to externals
Also misc cleanup
* Add note to default config
* Add a test
* Ensure PATH/Path conversion list <-> string
* Update docs for open and decode command, regenerate all docs
* Update open.rs
* Update open.md
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
At the moment `crossterm` apparently has a regression decoding certain important key combinations on Windows.
Thus reedline reverted to the previous version.
Some changes are necessary to remove the need for `crossterm` in the use of `lscolors`.
Introduces two local conversion traits.
Additionally update the `Highlighter` API to support the cursor
position.
This will enable brace/statement match highlighting.
Previously, the parser tried to look up the predecl also in the
permanent state and if a definition with that name already existed, it
would try to update it, which is illegal.
* Handle string->value env conv. with env. var.
Also adds the environment variable for Path/PATH and removes it from
config.
* Simplify getting the string->value conversion
* Refactor env conversion into its own function
* Use env var for to_string conversion; Remove conf
* Fix indentation in default config
This restores a basic version of the `post` command.
Some source types have been omitted from this first take.
I copied from `fetch` and from `post`@0.40.0.
Part of #4356
* Fix failing pipeline()
The `skip(1)` was there likely to remove the welcome message.
* Fix typo
* Fix nu! test macro to enter cwd correctly
Nushell's current working directory is determined primarily by the PWD
environment variable.
* Add `date format --list`, and make format string optional (providing default)
* Make DRY
`into datetime --list` now uses `generate_strfttime_list` from `date format --list`
* refactor strftime to use current datetime
* Fix formatting of specification descriptions
Fixes issues caused when copying directly from docs.rs
* Change default format to rfc2822
Perhaps to make it more DRY, functions from `into datetime` can be used. However, currently `into datetime` is a bit tricky to use as it needs a separate time zone argument.
* Tweak in-shell docs to match modified behavior
* Show %#z format specifier in `into datetime --list` only
* cargo fmt
* Satisfy clippy
* Add different features combinations
* Specify styles manually
* Fix args
* Fix typo
* Let other CI jobs finish if one fails
* Fix unused symbols without plugin feature
* Put "which" tests behind "which" feature
* Add Python virtualenv job
* Oops forgot git command
* Install Nushell in virtualenv tests
* Add names to steps; Test v.env in separate step
* cd into virtualenv
* Do not run on Python 2.7
* Build Nushell after formatting and clippy checks
* Add alias interning
Now, AliasId is used to reference aliases stored in EngineState, similar
to decls, blocks, etc.
* Fix wrong message
* Fix using decl instead of alias
* Extend also alias id visibility
* Merge also aliases from delta
* Add alias hiding code
Does not work yet but passes tests at least.
* Fix wrong alias lookup and visibility appending
* Add hide alias tests
* Fmt & Clippy
* Fix random clippy warnings in "which" command
* Fix "index out of bounds" when input to group-by is empty #4369
* Fix formatting #4369
* Adds test for empty input
Co-authored-by: Ray Henry <ray.henry@thermofisher.com>
Same rationale as in #4378
Also accelerate `grid`
before:
```
Command being timed: "./eager_nu -c for i in 0..100000 { echo whatever } | grid"
User time (seconds): 0.21
System time (seconds): 0.05
Percent of CPU this job got: 36%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.71
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 48112
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 10580
Voluntary context switches: 266
Involuntary context switches: 2595
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
```
after:
```
Command being timed: "./lazy_nu -c for i in 0..100000 { echo whatever } | grid"
User time (seconds): 0.14
System time (seconds): 0.05
Percent of CPU this job got: 33%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.60
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 48272
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 1
Minor (reclaiming a frame) page faults: 10582
Voluntary context switches: 286
Involuntary context switches: 831
Swaps: 0
File system inputs: 56
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
```
For the width calculations for table layout the `strip_ansi` function
has to be called frequently. By checking for the ASCII control chars
(0x00 to 0x1f) except `\n` that are stripped by `strip_ansi_escapes` the number of
necessary allocations can be reduced significantly for the simple case
of text not containing ANSI escapes.
**Benchmark:**
```
nu -c "for i in 0..1000 { ls } | flatten | table"
```
**Allocation reduction**
Running on the nushell repo root as the directory, this change reduces the
allocation volume by approximately 400 MB
(Measured run via KDE heaptrack)
**Speed improvement to output**
Measured via `/usr/bin/time -v`
*before*
```
Command being timed: "./eager_nu -c for i in 0..1000 {ls} | flatten | table"
User time (seconds): 0.87
System time (seconds): 0.14
Percent of CPU this job got: 87%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.16
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 18888
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 4809
Voluntary context switches: 38
Involuntary context switches: 14
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
```
*after*
```
Command being timed: "./lazy_nu -c for i in 0..1000 {ls} | flatten | table"
User time (seconds): 0.63
System time (seconds): 0.14
Percent of CPU this job got: 80%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.97
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 18660
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 5149
Voluntary context switches: 24
Involuntary context switches: 5
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
```
* Allow range in 'drop nth'
* Unit tests for drop nth range
* Add range case to the description
* Fix description 2
* format fixes
* Fix example and some refactoring
* clippy fixes
* fix into filesize tests and filesize
* tweaks
* added span back for like the 10th time
* Update filesize.rs
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>