mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Compare commits
527 Commits
0.94.2
...
back-to-th
Author | SHA1 | Date | |
---|---|---|---|
139342ac4a | |||
63583d6072 | |||
f172e42869 | |||
c3a6aca464 | |||
f5121a5c78 | |||
e7f2aaf721 | |||
36909a2b73 | |||
d941e7324f | |||
8756fedb3b | |||
dba2f6e0f8 | |||
e911ff4d67 | |||
28b6db115a | |||
e735bd475f | |||
299d199150 | |||
5e784d38eb | |||
868029f655 | |||
043d1ed9fb | |||
6230a62e9e | |||
71b49c3374 | |||
2eef42c6b9 | |||
0209992f6c | |||
c9d54f821b | |||
59d6dee3b3 | |||
9d25b2f29a | |||
91ff57faa7 | |||
b99affba4b | |||
639bd4fc2e | |||
a0f38f8845 | |||
a11c9e9d70 | |||
bdbcf82967 | |||
1f47d72e86 | |||
d83781ddec | |||
e32e55938b | |||
de08b68ba8 | |||
0e3a8c552c | |||
389e7d2502 | |||
fce6146576 | |||
02313e6819 | |||
df0a174802 | |||
bcb7ef48b6 | |||
9f714e62cb | |||
a95c2198a6 | |||
2df91e7f92 | |||
44be445b57 | |||
e43632fd95 | |||
69e4abad0f | |||
3bedbd0669 | |||
1d15bbc95b | |||
5002d87af4 | |||
2a3805c164 | |||
52f646d8db | |||
36c1073441 | |||
2979595cc5 | |||
d67120be19 | |||
ad31f1cf26 | |||
99798ace7d | |||
ba4becc61c | |||
397499b106 | |||
55c3fc9141 | |||
2830ec008c | |||
4c8b09eb97 | |||
98e0864be8 | |||
6dc71f5ad0 | |||
d6f4e4c4fe | |||
33ae71f300 | |||
abcca0897e | |||
b1379b2b14 | |||
27ebccce80 | |||
6964968f14 | |||
68377c176d | |||
baadaee016 | |||
199aa2ad3a | |||
29b176b719 | |||
6ce20675eb | |||
1e9967c3bf | |||
e0bc85d0dd | |||
e3fd4d3f81 | |||
00709fc5bd | |||
157494e803 | |||
f03ba6793e | |||
475aa4f1dd | |||
1d6ac16530 | |||
573a7e2c7b | |||
cebbc82322 | |||
cf5b2aeb88 | |||
52eb9c2ef3 | |||
702dcd8581 | |||
9e6ada6411 | |||
a38663ec90 | |||
02804ab537 | |||
b2d0d9cf13 | |||
46589faaca | |||
166d5fa4ff | |||
4bd38847c2 | |||
30a4187be4 | |||
f0c83a4459 | |||
fc61416c79 | |||
8200831b07 | |||
497954d84c | |||
bcaef8959c | |||
5bef81a059 | |||
d68c3ec89a | |||
0c72f881a6 | |||
8195e2d638 | |||
e8c20390e0 | |||
13df0af514 | |||
54e9aa92bc | |||
1afff777a6 | |||
071faae772 | |||
08a241f763 | |||
63f9e273b3 | |||
71d604067a | |||
66d0e18674 | |||
a940a8aa80 | |||
0d30550950 | |||
65bb0ff167 | |||
151767a5e3 | |||
a948ec6c2c | |||
28a7461057 | |||
6f47990a63 | |||
183c2221bb | |||
03ee54a4df | |||
2541a712e4 | |||
ee877607fb | |||
93351b889a | |||
5fa9d76500 | |||
cd0d0364ec | |||
cf5fec63c0 | |||
5c5cf418fb | |||
fb14008f50 | |||
18c8c16c5e | |||
299a218de7 | |||
1a081c09de | |||
6e1e824473 | |||
af77bc60e2 | |||
9ca0fb772d | |||
c535c24d03 | |||
c9cb62067c | |||
ebc7b80c23 | |||
aaaab8e070 | |||
a59477205d | |||
5101b5e306 | |||
fb34a4fc6c | |||
1bcceafd93 | |||
217eb4ed70 | |||
78af66f2ce | |||
f63cecc316 | |||
8d60c0d35d | |||
0c139c7411 | |||
c4bac90b35 | |||
2ab8751ff9 | |||
d192d854d6 | |||
6b5906613c | |||
493850b1bf | |||
6600b3edfb | |||
aff974552a | |||
2afc6a974e | |||
1e64f59220 | |||
3e074bc447 | |||
3d008e2c4e | |||
6c1c7f9509 | |||
f531cc2058 | |||
edd69aa283 | |||
3d20c53904 | |||
2d360fda7f | |||
d0c2adabf7 | |||
870eb2530c | |||
b2cab3274b | |||
92091599ff | |||
4d2d553cca | |||
dc53c20628 | |||
e7c5f83460 | |||
f611196373 | |||
abd230e12e | |||
4792328d0e | |||
63b94dbd28 | |||
eb0de25d19 | |||
ebe42241fe | |||
fa4f9b083e | |||
e7b7c7f39a | |||
6be458c686 | |||
348c59b740 | |||
2c827d2bf4 | |||
61544eecd6 | |||
c150af4279 | |||
39bda8986e | |||
ee997ef3dd | |||
e3f59910b8 | |||
f4940e115f | |||
3f31ca7b8e | |||
0119534f61 | |||
84e1ac27e5 | |||
644bebf4c6 | |||
f58a4b5017 | |||
ae0e13733d | |||
2c379cba71 | |||
7171c9b84a | |||
055d7e27e9 | |||
af76e11dd6 | |||
7dda39a89e | |||
4f822e263f | |||
a39e94de8a | |||
a88f46c6c9 | |||
4ca1f95b6c | |||
71ced35987 | |||
1128df2d29 | |||
da98c23ab3 | |||
e3efc8da9f | |||
3f332bef35 | |||
525eac1afd | |||
7003b007d5 | |||
dfdb2b5d31 | |||
822007dbbb | |||
0560826414 | |||
39b0f3bdda | |||
712fec166d | |||
43dcf19ac3 | |||
ffddee5678 | |||
95b78eee25 | |||
3ab9f0b90a | |||
9261c0c55a | |||
7a888c9e9b | |||
e211b7ba53 | |||
60769ac1ba | |||
34e7bd861c | |||
d667b3c0bc | |||
b63c3514c4 | |||
7e9d32d64e | |||
621fb25670 | |||
a80273bd7b | |||
5473def7ef | |||
04746b8e2d | |||
31b3104af7 | |||
803bc9c63f | |||
e690e7aac0 | |||
e841fce0f9 | |||
d7b0dc1275 | |||
5627c95916 | |||
f122065772 | |||
4732507f46 | |||
5f45f6c223 | |||
a55d172e52 | |||
48e401834d | |||
d5946a9667 | |||
a432bf94ec | |||
0eabbb88dd | |||
80c8edcfb4 | |||
059167ac96 | |||
4e205cd9a7 | |||
18772b73b3 | |||
983014cc40 | |||
4ff33933dd | |||
035308bb1d | |||
e530e7d654 | |||
7d4449f021 | |||
ec3e0e593d | |||
ff09c7964e | |||
ce13ecfd10 | |||
c18e6bfca0 | |||
bc6947cd09 | |||
faaa12838e | |||
edee2a3c15 | |||
2ced9e4d19 | |||
926331dbfb | |||
eca2975b3d | |||
1cd0544a3f | |||
73e8de9753 | |||
4e83ccdf86 | |||
6d36941e55 | |||
2f44801414 | |||
9172b22985 | |||
1c37f4b958 | |||
56ed532038 | |||
b974f8f7e3 | |||
802bfed173 | |||
07e7c8c81f | |||
20b53067cd | |||
f4c0d9d45b | |||
85b06b22d9 | |||
63f00e78d1 | |||
ff1ad77130 | |||
af34d5c062 | |||
ed82f9ee18 | |||
d081e3386f | |||
ca8eb856e8 | |||
168835ecd2 | |||
4157ca711d | |||
d34a24db33 | |||
2c6b1471e1 | |||
ae5fed41ed | |||
ca73d85c09 | |||
f82c43f850 | |||
3dc9691aaa | |||
42531e017c | |||
928c57db41 | |||
d880241102 | |||
813aac89bd | |||
d2bf82d22b | |||
3f12b14053 | |||
8e2917b9ae | |||
3c3ec7891c | |||
6b839c3c32 | |||
ea22c319b6 | |||
7432e67da1 | |||
0576794e74 | |||
12f57dbc62 | |||
fe57c5c22e | |||
18161e5707 | |||
466b3899e0 | |||
7b82c6b482 | |||
e3f78b8793 | |||
c31291753c | |||
f7d6c28a00 | |||
d618fd0527 | |||
d80de68665 | |||
5f7afafe51 | |||
53fbf62493 | |||
e68f744dda | |||
e2d0514bb5 | |||
4a7d4401b8 | |||
6446f26283 | |||
9f90d611e1 | |||
a88c3f48e2 | |||
5c2439abc0 | |||
a80dfe8e80 | |||
6a62ced645 | |||
366e52b76d | |||
6fcd09682c | |||
9ab706db62 | |||
01891d637d | |||
5db57abc7d | |||
dbd60ed4f4 | |||
aa9a42776b | |||
4665323bb4 | |||
e281c03403 | |||
e8764de3c6 | |||
f3843a6176 | |||
c19944f291 | |||
22379c9846 | |||
aa7d7d0cc3 | |||
f976c31887 | |||
ac18e43603 | |||
63cea44130 | |||
5417c89387 | |||
b66671d339 | |||
1981c50c8f | |||
fcb8e36caa | |||
0918050ac8 | |||
3d1145e759 | |||
cf4864a9cd | |||
ae40d56fc5 | |||
c5aa15c7f6 | |||
f5bff8c9c8 | |||
b0bf54614f | |||
a2758e6c40 | |||
d42cf55431 | |||
46b5e510ac | |||
02659b1c8a | |||
8f981c1eb4 | |||
0b8d0bcd7a | |||
ee875bb8a3 | |||
d56457d63e | |||
4bd87d0496 | |||
ccd0160c32 | |||
acd4cb83e8 | |||
a7a5315638 | |||
9fec5883c0 | |||
f65bc97a54 | |||
deaa711ca6 | |||
076a29ae19 | |||
9de7f931c0 | |||
d97512df8e | |||
801cfae279 | |||
f87cf895c2 | |||
ac561b1b0e | |||
1a5bf2447a | |||
d7392f1f3b | |||
ea8c4e3af2 | |||
616e9faaf1 | |||
b68c7cf3fa | |||
0178295363 | |||
ad8054ebed | |||
ff27d6a18e | |||
4cdceca1f7 | |||
1964dacaef | |||
e98b2ceb8c | |||
399a7c8836 | |||
c6b6b1b7a8 | |||
152fb5be39 | |||
83081f9852 | |||
6ce5530fc2 | |||
5af8d62666 | |||
32db5d3aa3 | |||
fa183b6669 | |||
d2a1f96dbd | |||
de2b752771 | |||
948b90299d | |||
34da26d039 | |||
8707d14f95 | |||
1514b9fbef | |||
b27cd70fd1 | |||
afaa019fae | |||
8833d3f89f | |||
d5e00c0d5d | |||
3fae77209a | |||
ca7a2ae1d6 | |||
ba1d900020 | |||
f59dfac130 | |||
9e738193f3 | |||
8316a1597e | |||
0cfd5fbece | |||
9b63e17072 | |||
122ff1f19c | |||
0d060aeae8 | |||
e5cf4863e9 | |||
69e4790b00 | |||
a2873336bb | |||
4fe0f860a8 | |||
33d0537cae | |||
40e629beb1 | |||
1b1928c103 | |||
153b45bc63 | |||
4f8d82bb88 | |||
720b4cbd01 | |||
a71732ba12 | |||
57452337ff | |||
1f1f581357 | |||
0d79b63711 | |||
46ed69ab12 | |||
ee74ec7423 | |||
198aedb6c2 | |||
58e8ea6084 | |||
020f4436d9 | |||
8a7a407627 | |||
b679c2bfa2 | |||
0fd0e36be8 | |||
38ecb6d380 | |||
c5a00ca3f1 | |||
5a486029db | |||
def36865ef | |||
55ee476306 | |||
f241110005 | |||
0dd35cddcd | |||
f93c6680bd | |||
43e349a274 | |||
4509944988 | |||
9b7f899410 | |||
b6bdadbc6f | |||
dcb6ab6370 | |||
db86dd9f26 | |||
10e84038af | |||
91d44f15c1 | |||
dd8f8861ed | |||
9845d13347 | |||
4c82a748c1 | |||
20834c9d47 | |||
7d2d573eb8 | |||
c09a8a5ec9 | |||
bb6cb94e55 | |||
26bdba2068 | |||
bdc32345bd | |||
44aa0a2de4 | |||
12991cd36f | |||
103f59be52 | |||
532c0023c2 | |||
a894e9c246 | |||
c171a2b8b7 | |||
28ed0fe700 | |||
ae6489f04b | |||
97876fb0b4 | |||
b79a2255d2 | |||
3a6d8aac0b | |||
b1cf0e258d | |||
af6e1cb5a6 | |||
323d5457f9 | |||
634361b2d1 | |||
bdbb096526 | |||
63c863c81b | |||
17daf783b2 | |||
1e430d155e | |||
0372e8c53c | |||
b0d1b4b182 | |||
a8376fad40 | |||
c09488f515 | |||
944d941dec | |||
a55a48529d | |||
af22bb8d52 | |||
5b7e8bf1d8 | |||
021b8633cb | |||
650ae537c3 | |||
dc76183cd5 | |||
5ac3ad61c4 | |||
e52d7bc585 | |||
48a34ffe6d | |||
d2121a155e | |||
cfe13397ed | |||
d6a9fb0e40 | |||
a246a19387 | |||
2d0a60ac67 | |||
83cf212e20 | |||
e3a20e90b0 | |||
83628f04ff | |||
460df0e99a | |||
eef4a89ff4 | |||
073d8850e9 | |||
f2f4b83886 | |||
5d163c1bcc | |||
75d5807dcd | |||
f378c72f6f | |||
a6b1d1f6d9 | |||
96493b26d9 | |||
36ad7f15c4 | |||
78fdb2f4d1 | |||
a3bc85bb5f | |||
a9c2349ada | |||
e4104d0792 | |||
b10325dff1 | |||
d4fa014534 | |||
c310175a1e | |||
6b2012bdfa | |||
28e33587d9 | |||
ff5cb6f1ff | |||
65911c125c | |||
3f0db11ae5 | |||
7746e84199 | |||
a84fdb1d37 | |||
ad5a6cdc00 |
16
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
16
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -13,7 +13,7 @@ body:
|
|||||||
id: repro
|
id: repro
|
||||||
attributes:
|
attributes:
|
||||||
label: How to reproduce
|
label: How to reproduce
|
||||||
description: Steps to reproduce the behavior
|
description: Steps to reproduce the behavior (including succinct code examples or screenshots of the observed behavior)
|
||||||
placeholder: |
|
placeholder: |
|
||||||
1.
|
1.
|
||||||
2.
|
2.
|
||||||
@ -28,13 +28,6 @@ body:
|
|||||||
placeholder: I expected nu to...
|
placeholder: I expected nu to...
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
|
||||||
id: screenshots
|
|
||||||
attributes:
|
|
||||||
label: Screenshots
|
|
||||||
description: Please add any relevant screenshots here, if any
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: config
|
id: config
|
||||||
attributes:
|
attributes:
|
||||||
@ -55,10 +48,3 @@ body:
|
|||||||
| installed_plugins | binaryview, chart bar, chart line, fetch, from bson, from sqlite, inc, match, post, ps, query json, s3, selector, start, sys, textview, to bson, to sqlite, tree, xpath |
|
| installed_plugins | binaryview, chart bar, chart line, fetch, from bson, from sqlite, inc, match, post, ps, query json, s3, selector, start, sys, textview, to bson, to sqlite, tree, xpath |
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
|
||||||
id: context
|
|
||||||
attributes:
|
|
||||||
label: Additional context
|
|
||||||
description: Add any other context about the problem here.
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
|
15
.github/dependabot.yml
vendored
15
.github/dependabot.yml
vendored
@ -18,6 +18,21 @@ updates:
|
|||||||
ignore:
|
ignore:
|
||||||
- dependency-name: "*"
|
- dependency-name: "*"
|
||||||
update-types: ["version-update:semver-patch"]
|
update-types: ["version-update:semver-patch"]
|
||||||
|
groups:
|
||||||
|
# Only update polars as a whole as there are many subcrates that need to
|
||||||
|
# be updated at once. We explicitly depend on some of them, so batch their
|
||||||
|
# updates to not take up dependabot PR slots with dysfunctional PRs
|
||||||
|
polars:
|
||||||
|
patterns:
|
||||||
|
- "polars"
|
||||||
|
- "polars-*"
|
||||||
|
# uutils/coreutils also versions all their workspace crates the same at the moment
|
||||||
|
# Most of them have bleeding edge version requirements (some not)
|
||||||
|
# see: https://github.com/uutils/coreutils/blob/main/Cargo.toml
|
||||||
|
uutils:
|
||||||
|
patterns:
|
||||||
|
- "uucore"
|
||||||
|
- "uu_*"
|
||||||
- package-ecosystem: "github-actions"
|
- package-ecosystem: "github-actions"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
|
4
.github/workflows/audit.yml
vendored
4
.github/workflows/audit.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
# Prevent sudden announcement of a new advisory from failing ci:
|
# Prevent sudden announcement of a new advisory from failing ci:
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.7
|
||||||
- uses: rustsec/audit-check@v1.4.1
|
- uses: rustsec/audit-check@v2.0.0
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
@ -33,10 +33,10 @@ jobs:
|
|||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.7
|
||||||
|
|
||||||
- name: Setup Rust toolchain and cache
|
- name: Setup Rust toolchain and cache
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
|
||||||
|
|
||||||
- name: cargo fmt
|
- name: cargo fmt
|
||||||
run: cargo fmt --all -- --check
|
run: cargo fmt --all -- --check
|
||||||
@ -57,22 +57,17 @@ jobs:
|
|||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
platform: [windows-latest, macos-latest, ubuntu-20.04]
|
platform: [windows-latest, macos-latest, ubuntu-20.04]
|
||||||
include:
|
|
||||||
- default-flags: ""
|
|
||||||
# linux CI cannot handle clipboard feature
|
|
||||||
- platform: ubuntu-20.04
|
|
||||||
default-flags: "--no-default-features --features=default-no-clipboard"
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.7
|
||||||
|
|
||||||
- name: Setup Rust toolchain and cache
|
- name: Setup Rust toolchain and cache
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: cargo test --workspace --profile ci --exclude nu_plugin_* ${{ matrix.default-flags }}
|
run: cargo test --workspace --profile ci --exclude nu_plugin_*
|
||||||
- name: Check for clean repo
|
- name: Check for clean repo
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@ -95,10 +90,10 @@ jobs:
|
|||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.7
|
||||||
|
|
||||||
- name: Setup Rust toolchain and cache
|
- name: Setup Rust toolchain and cache
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
|
||||||
|
|
||||||
- name: Install Nushell
|
- name: Install Nushell
|
||||||
run: cargo install --path . --locked --no-default-features
|
run: cargo install --path . --locked --no-default-features
|
||||||
@ -146,10 +141,10 @@ jobs:
|
|||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.7
|
||||||
|
|
||||||
- name: Setup Rust toolchain and cache
|
- name: Setup Rust toolchain and cache
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
|
||||||
|
|
||||||
- name: Clippy
|
- name: Clippy
|
||||||
run: cargo clippy --package nu_plugin_* -- $CLIPPY_OPTIONS
|
run: cargo clippy --package nu_plugin_* -- $CLIPPY_OPTIONS
|
||||||
|
18
.github/workflows/milestone.yml
vendored
Normal file
18
.github/workflows/milestone.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Description:
|
||||||
|
# - Update milestone of a merged PR
|
||||||
|
|
||||||
|
name: Milestone Action
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [closed]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-milestone:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Milestone Update
|
||||||
|
if: ${{github.event.pull_request.merged == true}}
|
||||||
|
steps:
|
||||||
|
- name: Set Milestone
|
||||||
|
uses: hustcer/milestone-action@main
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
41
.github/workflows/nightly-build.yml
vendored
41
.github/workflows/nightly-build.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
|||||||
# if: github.repository == 'nushell/nightly'
|
# if: github.repository == 'nushell/nightly'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4.1.6
|
uses: actions/checkout@v4
|
||||||
if: github.repository == 'nushell/nightly'
|
if: github.repository == 'nushell/nightly'
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
@ -36,10 +36,10 @@ jobs:
|
|||||||
token: ${{ secrets.WORKFLOW_TOKEN }}
|
token: ${{ secrets.WORKFLOW_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Nushell
|
- name: Setup Nushell
|
||||||
uses: hustcer/setup-nu@v3.10
|
uses: hustcer/setup-nu@v3
|
||||||
if: github.repository == 'nushell/nightly'
|
if: github.repository == 'nushell/nightly'
|
||||||
with:
|
with:
|
||||||
version: 0.93.0
|
version: 0.98.0
|
||||||
|
|
||||||
# Synchronize the main branch of nightly repo with the main branch of Nushell official repo
|
# Synchronize the main branch of nightly repo with the main branch of Nushell official repo
|
||||||
- name: Prepare for Nightly Release
|
- name: Prepare for Nightly Release
|
||||||
@ -65,7 +65,7 @@ jobs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
standard:
|
standard:
|
||||||
name: Std
|
name: Nu
|
||||||
needs: prepare
|
needs: prepare
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@ -78,8 +78,11 @@ jobs:
|
|||||||
- x86_64-unknown-linux-gnu
|
- x86_64-unknown-linux-gnu
|
||||||
- x86_64-unknown-linux-musl
|
- x86_64-unknown-linux-musl
|
||||||
- aarch64-unknown-linux-gnu
|
- aarch64-unknown-linux-gnu
|
||||||
|
- aarch64-unknown-linux-musl
|
||||||
- armv7-unknown-linux-gnueabihf
|
- armv7-unknown-linux-gnueabihf
|
||||||
|
- armv7-unknown-linux-musleabihf
|
||||||
- riscv64gc-unknown-linux-gnu
|
- riscv64gc-unknown-linux-gnu
|
||||||
|
- loongarch64-unknown-linux-gnu
|
||||||
extra: ['bin']
|
extra: ['bin']
|
||||||
include:
|
include:
|
||||||
- target: aarch64-apple-darwin
|
- target: aarch64-apple-darwin
|
||||||
@ -99,20 +102,26 @@ jobs:
|
|||||||
extra: msi
|
extra: msi
|
||||||
os: windows-latest
|
os: windows-latest
|
||||||
- target: x86_64-unknown-linux-gnu
|
- target: x86_64-unknown-linux-gnu
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
- target: x86_64-unknown-linux-musl
|
- target: x86_64-unknown-linux-musl
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
- target: aarch64-unknown-linux-gnu
|
- target: aarch64-unknown-linux-gnu
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
|
- target: aarch64-unknown-linux-musl
|
||||||
|
os: ubuntu-22.04
|
||||||
- target: armv7-unknown-linux-gnueabihf
|
- target: armv7-unknown-linux-gnueabihf
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
|
- target: armv7-unknown-linux-musleabihf
|
||||||
|
os: ubuntu-22.04
|
||||||
- target: riscv64gc-unknown-linux-gnu
|
- target: riscv64gc-unknown-linux-gnu
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
|
- target: loongarch64-unknown-linux-gnu
|
||||||
|
os: ubuntu-22.04
|
||||||
|
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
@ -122,15 +131,15 @@ jobs:
|
|||||||
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
|
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
|
||||||
|
|
||||||
- name: Setup Rust toolchain and cache
|
- name: Setup Rust toolchain and cache
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
|
||||||
# WARN: Keep the rustflags to prevent from the winget submission error: `CAQuietExec: Error 0xc0000135`
|
# WARN: Keep the rustflags to prevent from the winget submission error: `CAQuietExec: Error 0xc0000135`
|
||||||
with:
|
with:
|
||||||
rustflags: ''
|
rustflags: ''
|
||||||
|
|
||||||
- name: Setup Nushell
|
- name: Setup Nushell
|
||||||
uses: hustcer/setup-nu@v3.10
|
uses: hustcer/setup-nu@v3
|
||||||
with:
|
with:
|
||||||
version: 0.93.0
|
version: 0.98.0
|
||||||
|
|
||||||
- name: Release Nu Binary
|
- name: Release Nu Binary
|
||||||
id: nu
|
id: nu
|
||||||
@ -161,7 +170,7 @@ jobs:
|
|||||||
# REF: https://github.com/marketplace/actions/gh-release
|
# REF: https://github.com/marketplace/actions/gh-release
|
||||||
# Create a release only in nushell/nightly repo
|
# Create a release only in nushell/nightly repo
|
||||||
- name: Publish Archive
|
- name: Publish Archive
|
||||||
uses: softprops/action-gh-release@v2.0.5
|
uses: softprops/action-gh-release@v2.0.8
|
||||||
if: ${{ startsWith(github.repository, 'nushell/nightly') }}
|
if: ${{ startsWith(github.repository, 'nushell/nightly') }}
|
||||||
with:
|
with:
|
||||||
prerelease: true
|
prerelease: true
|
||||||
@ -181,14 +190,14 @@ jobs:
|
|||||||
- name: Waiting for Release
|
- name: Waiting for Release
|
||||||
run: sleep 1800
|
run: sleep 1800
|
||||||
|
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Setup Nushell
|
- name: Setup Nushell
|
||||||
uses: hustcer/setup-nu@v3.10
|
uses: hustcer/setup-nu@v3
|
||||||
with:
|
with:
|
||||||
version: 0.93.0
|
version: 0.98.0
|
||||||
|
|
||||||
# Keep the last a few releases
|
# Keep the last a few releases
|
||||||
- name: Delete Older Releases
|
- name: Delete Older Releases
|
||||||
|
27
.github/workflows/release-pkg.nu
vendored
27
.github/workflows/release-pkg.nu
vendored
@ -84,6 +84,27 @@ if $os in ['macos-latest'] or $USE_UBUNTU {
|
|||||||
$env.CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER = 'arm-linux-gnueabihf-gcc'
|
$env.CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER = 'arm-linux-gnueabihf-gcc'
|
||||||
cargo-build-nu
|
cargo-build-nu
|
||||||
}
|
}
|
||||||
|
'aarch64-unknown-linux-musl' => {
|
||||||
|
aria2c https://musl.cc/aarch64-linux-musl-cross.tgz
|
||||||
|
tar -xf aarch64-linux-musl-cross.tgz -C $env.HOME
|
||||||
|
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.HOME)/aarch64-linux-musl-cross/bin')
|
||||||
|
$env.CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER = 'aarch64-linux-musl-gcc'
|
||||||
|
cargo-build-nu
|
||||||
|
}
|
||||||
|
'armv7-unknown-linux-musleabihf' => {
|
||||||
|
aria2c https://musl.cc/armv7r-linux-musleabihf-cross.tgz
|
||||||
|
tar -xf armv7r-linux-musleabihf-cross.tgz -C $env.HOME
|
||||||
|
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.HOME)/armv7r-linux-musleabihf-cross/bin')
|
||||||
|
$env.CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER = 'armv7r-linux-musleabihf-gcc'
|
||||||
|
cargo-build-nu
|
||||||
|
}
|
||||||
|
'loongarch64-unknown-linux-gnu' => {
|
||||||
|
aria2c https://github.com/loongson/build-tools/releases/download/2024.08.08/x86_64-cross-tools-loongarch64-binutils_2.43-gcc_14.2.0-glibc_2.40.tar.xz
|
||||||
|
tar xf x86_64-cross-tools-loongarch64-*.tar.xz
|
||||||
|
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.PWD)/cross-tools/bin')
|
||||||
|
$env.CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER = 'loongarch64-unknown-linux-gnu-gcc'
|
||||||
|
cargo-build-nu
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
# musl-tools to fix 'Failed to find tool. Is `musl-gcc` installed?'
|
# musl-tools to fix 'Failed to find tool. Is `musl-gcc` installed?'
|
||||||
# Actually just for x86_64-unknown-linux-musl target
|
# Actually just for x86_64-unknown-linux-musl target
|
||||||
@ -161,8 +182,12 @@ if $os in ['macos-latest'] or $USE_UBUNTU {
|
|||||||
let releaseStem = $'($bin)-($version)-($target)'
|
let releaseStem = $'($bin)-($version)-($target)'
|
||||||
|
|
||||||
print $'(char nl)Download less related stuffs...'; hr-line
|
print $'(char nl)Download less related stuffs...'; hr-line
|
||||||
|
# todo: less-v661 is out but is released as a zip file. maybe we should switch to that and extract it?
|
||||||
aria2c https://github.com/jftuga/less-Windows/releases/download/less-v608/less.exe -o less.exe
|
aria2c https://github.com/jftuga/less-Windows/releases/download/less-v608/less.exe -o less.exe
|
||||||
aria2c https://raw.githubusercontent.com/jftuga/less-Windows/master/LICENSE -o LICENSE-for-less.txt
|
# the below was renamed because it was failing to download for darren. it should work but it wasn't
|
||||||
|
# todo: maybe we should get rid of this aria2c dependency and just use http get?
|
||||||
|
#aria2c https://raw.githubusercontent.com/jftuga/less-Windows/master/LICENSE -o LICENSE-for-less.txt
|
||||||
|
aria2c https://github.com/jftuga/less-Windows/blob/master/LICENSE -o LICENSE-for-less.txt
|
||||||
|
|
||||||
# Create Windows msi release package
|
# Create Windows msi release package
|
||||||
if (get-env _EXTRA_) == 'msi' {
|
if (get-env _EXTRA_) == 'msi' {
|
||||||
|
54
.github/workflows/release.yml
vendored
54
.github/workflows/release.yml
vendored
@ -14,8 +14,8 @@ defaults:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
standard:
|
release:
|
||||||
name: Std
|
name: Nu
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@ -28,8 +28,11 @@ jobs:
|
|||||||
- x86_64-unknown-linux-gnu
|
- x86_64-unknown-linux-gnu
|
||||||
- x86_64-unknown-linux-musl
|
- x86_64-unknown-linux-musl
|
||||||
- aarch64-unknown-linux-gnu
|
- aarch64-unknown-linux-gnu
|
||||||
|
- aarch64-unknown-linux-musl
|
||||||
- armv7-unknown-linux-gnueabihf
|
- armv7-unknown-linux-gnueabihf
|
||||||
|
- armv7-unknown-linux-musleabihf
|
||||||
- riscv64gc-unknown-linux-gnu
|
- riscv64gc-unknown-linux-gnu
|
||||||
|
- loongarch64-unknown-linux-gnu
|
||||||
extra: ['bin']
|
extra: ['bin']
|
||||||
include:
|
include:
|
||||||
- target: aarch64-apple-darwin
|
- target: aarch64-apple-darwin
|
||||||
@ -49,36 +52,42 @@ jobs:
|
|||||||
extra: msi
|
extra: msi
|
||||||
os: windows-latest
|
os: windows-latest
|
||||||
- target: x86_64-unknown-linux-gnu
|
- target: x86_64-unknown-linux-gnu
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
- target: x86_64-unknown-linux-musl
|
- target: x86_64-unknown-linux-musl
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
- target: aarch64-unknown-linux-gnu
|
- target: aarch64-unknown-linux-gnu
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
|
- target: aarch64-unknown-linux-musl
|
||||||
|
os: ubuntu-22.04
|
||||||
- target: armv7-unknown-linux-gnueabihf
|
- target: armv7-unknown-linux-gnueabihf
|
||||||
os: ubuntu-20.04
|
os: ubuntu-22.04
|
||||||
|
- target: armv7-unknown-linux-musleabihf
|
||||||
|
os: ubuntu-22.04
|
||||||
- target: riscv64gc-unknown-linux-gnu
|
- target: riscv64gc-unknown-linux-gnu
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
|
- target: loongarch64-unknown-linux-gnu
|
||||||
|
os: ubuntu-22.04
|
||||||
|
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Update Rust Toolchain Target
|
- name: Update Rust Toolchain Target
|
||||||
run: |
|
run: |
|
||||||
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
|
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
|
||||||
|
|
||||||
- name: Setup Rust toolchain
|
- name: Setup Rust toolchain
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
|
||||||
# WARN: Keep the rustflags to prevent from the winget submission error: `CAQuietExec: Error 0xc0000135`
|
# WARN: Keep the rustflags to prevent from the winget submission error: `CAQuietExec: Error 0xc0000135`
|
||||||
with:
|
with:
|
||||||
cache: false
|
cache: false
|
||||||
rustflags: ''
|
rustflags: ''
|
||||||
|
|
||||||
- name: Setup Nushell
|
- name: Setup Nushell
|
||||||
uses: hustcer/setup-nu@v3.10
|
uses: hustcer/setup-nu@v3
|
||||||
with:
|
with:
|
||||||
version: 0.93.0
|
version: 0.98.0
|
||||||
|
|
||||||
- name: Release Nu Binary
|
- name: Release Nu Binary
|
||||||
id: nu
|
id: nu
|
||||||
@ -91,10 +100,33 @@ jobs:
|
|||||||
|
|
||||||
# REF: https://github.com/marketplace/actions/gh-release
|
# REF: https://github.com/marketplace/actions/gh-release
|
||||||
- name: Publish Archive
|
- name: Publish Archive
|
||||||
uses: softprops/action-gh-release@v2.0.5
|
uses: softprops/action-gh-release@v2.0.8
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||||
with:
|
with:
|
||||||
draft: true
|
draft: true
|
||||||
files: ${{ steps.nu.outputs.archive }}
|
files: ${{ steps.nu.outputs.archive }}
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
sha256sum:
|
||||||
|
needs: release
|
||||||
|
name: Create Sha256sum
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Download Release Archives
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: >-
|
||||||
|
gh release download ${{ github.ref_name }}
|
||||||
|
--repo ${{ github.repository }}
|
||||||
|
--pattern '*'
|
||||||
|
--dir release
|
||||||
|
- name: Create Checksums
|
||||||
|
run: cd release && shasum -a 256 * > ../SHA256SUMS
|
||||||
|
- name: Publish Checksums
|
||||||
|
uses: softprops/action-gh-release@v2.0.8
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
files: SHA256SUMS
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
4
.github/workflows/typos.yml
vendored
4
.github/workflows/typos.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Actions Repository
|
- name: Checkout Actions Repository
|
||||||
uses: actions/checkout@v4.1.6
|
uses: actions/checkout@v4.1.7
|
||||||
|
|
||||||
- name: Check spelling
|
- name: Check spelling
|
||||||
uses: crate-ci/typos@v1.21.0
|
uses: crate-ci/typos@v1.26.0
|
||||||
|
26
CITATION.cff
Normal file
26
CITATION.cff
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
cff-version: 1.2.0
|
||||||
|
title: 'Nushell'
|
||||||
|
message: >-
|
||||||
|
If you use this software and wish to cite it,
|
||||||
|
you can use the metadata from this file.
|
||||||
|
type: software
|
||||||
|
authors:
|
||||||
|
- name: "The Nushell Project Team"
|
||||||
|
identifiers:
|
||||||
|
- type: url
|
||||||
|
value: 'https://github.com/nushell/nushell'
|
||||||
|
description: Repository
|
||||||
|
repository-code: 'https://github.com/nushell/nushell'
|
||||||
|
url: 'https://www.nushell.sh/'
|
||||||
|
abstract: >-
|
||||||
|
The goal of the Nushell project is to take the Unix
|
||||||
|
philosophy of shells, where pipes connect simple commands
|
||||||
|
together, and bring it to the modern style of development.
|
||||||
|
Thus, rather than being either a shell, or a programming
|
||||||
|
language, Nushell connects both by bringing a rich
|
||||||
|
programming language and a full-featured shell together
|
||||||
|
into one package.
|
||||||
|
keywords:
|
||||||
|
- nushell
|
||||||
|
- shell
|
||||||
|
license: MIT
|
2144
Cargo.lock
generated
2144
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
147
Cargo.toml
147
Cargo.toml
@ -10,8 +10,8 @@ homepage = "https://www.nushell.sh"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "nu"
|
name = "nu"
|
||||||
repository = "https://github.com/nushell/nushell"
|
repository = "https://github.com/nushell/nushell"
|
||||||
rust-version = "1.77.2"
|
rust-version = "1.80.1"
|
||||||
version = "0.94.2"
|
version = "0.99.1"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ members = [
|
|||||||
"crates/nu-lsp",
|
"crates/nu-lsp",
|
||||||
"crates/nu-pretty-hex",
|
"crates/nu-pretty-hex",
|
||||||
"crates/nu-protocol",
|
"crates/nu-protocol",
|
||||||
|
"crates/nu-derive-value",
|
||||||
"crates/nu-plugin",
|
"crates/nu-plugin",
|
||||||
"crates/nu-plugin-core",
|
"crates/nu-plugin-core",
|
||||||
"crates/nu-plugin-engine",
|
"crates/nu-plugin-engine",
|
||||||
@ -68,6 +69,7 @@ base64 = "0.22.1"
|
|||||||
bracoxide = "0.1.2"
|
bracoxide = "0.1.2"
|
||||||
brotli = "5.0"
|
brotli = "5.0"
|
||||||
byteorder = "1.5"
|
byteorder = "1.5"
|
||||||
|
bytes = "1"
|
||||||
bytesize = "1.3"
|
bytesize = "1.3"
|
||||||
calamine = "0.24.0"
|
calamine = "0.24.0"
|
||||||
chardetng = "0.1.17"
|
chardetng = "0.1.17"
|
||||||
@ -75,27 +77,26 @@ chrono = { default-features = false, version = "0.4.34" }
|
|||||||
chrono-humanize = "0.2.3"
|
chrono-humanize = "0.2.3"
|
||||||
chrono-tz = "0.8"
|
chrono-tz = "0.8"
|
||||||
crossbeam-channel = "0.5.8"
|
crossbeam-channel = "0.5.8"
|
||||||
crossterm = "0.27"
|
crossterm = "0.28.1"
|
||||||
csv = "1.3"
|
csv = "1.3"
|
||||||
ctrlc = "3.4"
|
ctrlc = "3.4"
|
||||||
dialoguer = { default-features = false, version = "0.11" }
|
dialoguer = { default-features = false, version = "0.11" }
|
||||||
digest = { default-features = false, version = "0.10" }
|
digest = { default-features = false, version = "0.10" }
|
||||||
dirs-next = "2.0"
|
dirs = "5.0"
|
||||||
|
dirs-sys = "0.4"
|
||||||
dtparse = "2.0"
|
dtparse = "2.0"
|
||||||
encoding_rs = "0.8"
|
encoding_rs = "0.8"
|
||||||
fancy-regex = "0.13"
|
fancy-regex = "0.13"
|
||||||
filesize = "0.2"
|
filesize = "0.2"
|
||||||
filetime = "0.2"
|
filetime = "0.2"
|
||||||
fs_extra = "1.3"
|
|
||||||
fuzzy-matcher = "0.3"
|
fuzzy-matcher = "0.3"
|
||||||
hamcrest2 = "0.3"
|
|
||||||
heck = "0.5.0"
|
heck = "0.5.0"
|
||||||
human-date-parser = "0.1.1"
|
human-date-parser = "0.2.0"
|
||||||
indexmap = "2.2"
|
indexmap = "2.6"
|
||||||
indicatif = "0.17"
|
indicatif = "0.17"
|
||||||
interprocess = "2.1.0"
|
interprocess = "2.2.0"
|
||||||
is_executable = "1.0"
|
is_executable = "1.0"
|
||||||
itertools = "0.12"
|
itertools = "0.13"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
libproc = "0.14"
|
libproc = "0.14"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
@ -106,32 +107,37 @@ lsp-types = "0.95.0"
|
|||||||
mach2 = "0.4"
|
mach2 = "0.4"
|
||||||
md5 = { version = "0.10", package = "md-5" }
|
md5 = { version = "0.10", package = "md-5" }
|
||||||
miette = "7.2"
|
miette = "7.2"
|
||||||
mime = "0.3"
|
mime = "0.3.17"
|
||||||
mime_guess = "2.0"
|
mime_guess = "2.0"
|
||||||
mockito = { version = "1.4", default-features = false }
|
mockito = { version = "1.5", default-features = false }
|
||||||
|
multipart-rs = "0.1.11"
|
||||||
native-tls = "0.2"
|
native-tls = "0.2"
|
||||||
nix = { version = "0.28", default-features = false }
|
nix = { version = "0.29", default-features = false }
|
||||||
notify-debouncer-full = { version = "0.3", default-features = false }
|
notify-debouncer-full = { version = "0.3", default-features = false }
|
||||||
nu-ansi-term = "0.50.0"
|
nu-ansi-term = "0.50.1"
|
||||||
num-format = "0.4"
|
num-format = "0.4"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
omnipath = "0.1"
|
omnipath = "0.1"
|
||||||
once_cell = "1.18"
|
once_cell = "1.20"
|
||||||
open = "5.1"
|
open = "5.3"
|
||||||
os_pipe = { version = "1.1", features = ["io_safety"] }
|
os_pipe = { version = "1.2", features = ["io_safety"] }
|
||||||
pathdiff = "0.2"
|
pathdiff = "0.2"
|
||||||
percent-encoding = "2"
|
percent-encoding = "2"
|
||||||
pretty_assertions = "1.4"
|
pretty_assertions = "1.4"
|
||||||
print-positions = "0.6"
|
print-positions = "0.6"
|
||||||
|
proc-macro-error = { version = "1.0", default-features = false }
|
||||||
|
proc-macro2 = "1.0"
|
||||||
procfs = "0.16.0"
|
procfs = "0.16.0"
|
||||||
pwd = "1.3"
|
pwd = "1.3"
|
||||||
quick-xml = "0.31.0"
|
quick-xml = "0.32.0"
|
||||||
quickcheck = "1.0"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "1.0"
|
quickcheck_macros = "1.0"
|
||||||
|
quote = "1.0"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
rand_chacha = "0.3.1"
|
||||||
ratatui = "0.26"
|
ratatui = "0.26"
|
||||||
rayon = "1.10"
|
rayon = "1.10"
|
||||||
reedline = "0.32.0"
|
reedline = "0.36.0"
|
||||||
regex = "1.9.5"
|
regex = "1.9.5"
|
||||||
rmp = "0.8"
|
rmp = "0.8"
|
||||||
rmp-serde = "1.3"
|
rmp-serde = "1.3"
|
||||||
@ -139,65 +145,75 @@ ropey = "1.6.1"
|
|||||||
roxmltree = "0.19"
|
roxmltree = "0.19"
|
||||||
rstest = { version = "0.18", default-features = false }
|
rstest = { version = "0.18", default-features = false }
|
||||||
rusqlite = "0.31"
|
rusqlite = "0.31"
|
||||||
rust-embed = "8.4.0"
|
rust-embed = "8.5.0"
|
||||||
same-file = "1.0"
|
serde = { version = "1.0" }
|
||||||
serde = { version = "1.0", default-features = false }
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_urlencoded = "0.7.1"
|
serde_urlencoded = "0.7.1"
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
strip-ansi-escapes = "0.2.0"
|
strip-ansi-escapes = "0.2.0"
|
||||||
sysinfo = "0.30"
|
syn = "2.0"
|
||||||
tabled = { version = "0.14.0", default-features = false }
|
sysinfo = "0.32"
|
||||||
tempfile = "3.10"
|
tabled = { version = "0.16.0", default-features = false }
|
||||||
|
tempfile = "3.13"
|
||||||
terminal_size = "0.3"
|
terminal_size = "0.3"
|
||||||
titlecase = "2.0"
|
titlecase = "2.0"
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
trash = "3.3"
|
trash = "5.1"
|
||||||
umask = "2.1"
|
umask = "2.1"
|
||||||
unicode-segmentation = "1.11"
|
unicode-segmentation = "1.12"
|
||||||
unicode-width = "0.1"
|
unicode-width = "0.1"
|
||||||
ureq = { version = "2.9", default-features = false }
|
ureq = { version = "2.10", default-features = false }
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
uu_cp = "0.0.25"
|
uu_cp = "0.0.27"
|
||||||
uu_mkdir = "0.0.25"
|
uu_mkdir = "0.0.27"
|
||||||
uu_mktemp = "0.0.25"
|
uu_mktemp = "0.0.27"
|
||||||
uu_mv = "0.0.25"
|
uu_mv = "0.0.27"
|
||||||
uu_whoami = "0.0.25"
|
uu_whoami = "0.0.27"
|
||||||
uu_uname = "0.0.25"
|
uu_uname = "0.0.27"
|
||||||
uucore = "0.0.25"
|
uucore = "0.0.27"
|
||||||
uuid = "1.8.0"
|
uuid = "1.10.0"
|
||||||
v_htmlescape = "0.15.0"
|
v_htmlescape = "0.15.0"
|
||||||
wax = "0.6"
|
wax = "0.6"
|
||||||
which = "6.0.0"
|
which = "6.0.0"
|
||||||
windows = "0.54"
|
windows = "0.56"
|
||||||
|
windows-sys = "0.48"
|
||||||
winreg = "0.52"
|
winreg = "0.52"
|
||||||
|
|
||||||
[dependencies]
|
[workspace.lints.clippy]
|
||||||
nu-cli = { path = "./crates/nu-cli", version = "0.94.2" }
|
# Warning: workspace lints affect library code as well as tests, so don't enable lints that would be too noisy in tests like that.
|
||||||
nu-cmd-base = { path = "./crates/nu-cmd-base", version = "0.94.2" }
|
# todo = "warn"
|
||||||
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.94.2" }
|
unchecked_duration_subtraction = "warn"
|
||||||
nu-cmd-plugin = { path = "./crates/nu-cmd-plugin", version = "0.94.2", optional = true }
|
|
||||||
nu-cmd-extra = { path = "./crates/nu-cmd-extra", version = "0.94.2" }
|
|
||||||
nu-command = { path = "./crates/nu-command", version = "0.94.2" }
|
|
||||||
nu-engine = { path = "./crates/nu-engine", version = "0.94.2" }
|
|
||||||
nu-explore = { path = "./crates/nu-explore", version = "0.94.2" }
|
|
||||||
nu-lsp = { path = "./crates/nu-lsp/", version = "0.94.2" }
|
|
||||||
nu-parser = { path = "./crates/nu-parser", version = "0.94.2" }
|
|
||||||
nu-path = { path = "./crates/nu-path", version = "0.94.2" }
|
|
||||||
nu-plugin-engine = { path = "./crates/nu-plugin-engine", optional = true, version = "0.94.2" }
|
|
||||||
nu-protocol = { path = "./crates/nu-protocol", version = "0.94.2" }
|
|
||||||
nu-std = { path = "./crates/nu-std", version = "0.94.2" }
|
|
||||||
nu-system = { path = "./crates/nu-system", version = "0.94.2" }
|
|
||||||
nu-utils = { path = "./crates/nu-utils", version = "0.94.2" }
|
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nu-cli = { path = "./crates/nu-cli", version = "0.99.1" }
|
||||||
|
nu-cmd-base = { path = "./crates/nu-cmd-base", version = "0.99.1" }
|
||||||
|
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.99.1" }
|
||||||
|
nu-cmd-plugin = { path = "./crates/nu-cmd-plugin", version = "0.99.1", optional = true }
|
||||||
|
nu-cmd-extra = { path = "./crates/nu-cmd-extra", version = "0.99.1" }
|
||||||
|
nu-command = { path = "./crates/nu-command", version = "0.99.1" }
|
||||||
|
nu-engine = { path = "./crates/nu-engine", version = "0.99.1" }
|
||||||
|
nu-explore = { path = "./crates/nu-explore", version = "0.99.1" }
|
||||||
|
nu-lsp = { path = "./crates/nu-lsp/", version = "0.99.1" }
|
||||||
|
nu-parser = { path = "./crates/nu-parser", version = "0.99.1" }
|
||||||
|
nu-path = { path = "./crates/nu-path", version = "0.99.1" }
|
||||||
|
nu-plugin-engine = { path = "./crates/nu-plugin-engine", optional = true, version = "0.99.1" }
|
||||||
|
nu-protocol = { path = "./crates/nu-protocol", version = "0.99.1" }
|
||||||
|
nu-std = { path = "./crates/nu-std", version = "0.99.1" }
|
||||||
|
nu-system = { path = "./crates/nu-system", version = "0.99.1" }
|
||||||
|
nu-utils = { path = "./crates/nu-utils", version = "0.99.1" }
|
||||||
reedline = { workspace = true, features = ["bashisms", "sqlite"] }
|
reedline = { workspace = true, features = ["bashisms", "sqlite"] }
|
||||||
|
|
||||||
crossterm = { workspace = true }
|
crossterm = { workspace = true }
|
||||||
ctrlc = { workspace = true }
|
ctrlc = { workspace = true }
|
||||||
|
dirs = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
miette = { workspace = true, features = ["fancy-no-backtrace", "fancy"] }
|
miette = { workspace = true, features = ["fancy-no-backtrace", "fancy"] }
|
||||||
mimalloc = { version = "0.1.42", default-features = false, optional = true }
|
mimalloc = { version = "0.1.42", default-features = false, optional = true }
|
||||||
|
multipart-rs = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
simplelog = "0.12"
|
simplelog = "0.12"
|
||||||
time = "0.3"
|
time = "0.3"
|
||||||
@ -218,13 +234,14 @@ nix = { workspace = true, default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
nu-test-support = { path = "./crates/nu-test-support", version = "0.94.2" }
|
nu-test-support = { path = "./crates/nu-test-support", version = "0.99.1" }
|
||||||
nu-plugin-protocol = { path = "./crates/nu-plugin-protocol", version = "0.94.2" }
|
nu-plugin-protocol = { path = "./crates/nu-plugin-protocol", version = "0.99.1" }
|
||||||
nu-plugin-core = { path = "./crates/nu-plugin-core", version = "0.94.2" }
|
nu-plugin-core = { path = "./crates/nu-plugin-core", version = "0.99.1" }
|
||||||
assert_cmd = "2.0"
|
assert_cmd = "2.0"
|
||||||
dirs-next = { workspace = true }
|
dirs = { workspace = true }
|
||||||
tango-bench = "0.5"
|
tango-bench = "0.6"
|
||||||
pretty_assertions = { workspace = true }
|
pretty_assertions = { workspace = true }
|
||||||
|
regex = { workspace = true }
|
||||||
rstest = { workspace = true, default-features = false }
|
rstest = { workspace = true, default-features = false }
|
||||||
serial_test = "3.1"
|
serial_test = "3.1"
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
@ -239,12 +256,9 @@ plugin = [
|
|||||||
"nu-protocol/plugin",
|
"nu-protocol/plugin",
|
||||||
"nu-engine/plugin",
|
"nu-engine/plugin",
|
||||||
]
|
]
|
||||||
default = ["default-no-clipboard", "system-clipboard"]
|
|
||||||
# Enables convenient omitting of the system-clipboard feature, as it leads to problems in ci on linux
|
default = [
|
||||||
# See https://github.com/nushell/nushell/pull/11535
|
|
||||||
default-no-clipboard = [
|
|
||||||
"plugin",
|
"plugin",
|
||||||
"which-support",
|
|
||||||
"trash-support",
|
"trash-support",
|
||||||
"sqlite",
|
"sqlite",
|
||||||
"mimalloc",
|
"mimalloc",
|
||||||
@ -257,6 +271,8 @@ stable = ["default"]
|
|||||||
static-link-openssl = ["dep:openssl", "nu-cmd-lang/static-link-openssl"]
|
static-link-openssl = ["dep:openssl", "nu-cmd-lang/static-link-openssl"]
|
||||||
|
|
||||||
mimalloc = ["nu-cmd-lang/mimalloc", "dep:mimalloc"]
|
mimalloc = ["nu-cmd-lang/mimalloc", "dep:mimalloc"]
|
||||||
|
# Optional system clipboard support in `reedline`, this behavior has problematic compatibility with some systems.
|
||||||
|
# Missing X server/ Wayland can cause issues
|
||||||
system-clipboard = [
|
system-clipboard = [
|
||||||
"reedline/system_clipboard",
|
"reedline/system_clipboard",
|
||||||
"nu-cli/system-clipboard",
|
"nu-cli/system-clipboard",
|
||||||
@ -264,7 +280,6 @@ system-clipboard = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Stable (Default)
|
# Stable (Default)
|
||||||
which-support = ["nu-command/which-support", "nu-cmd-lang/which-support"]
|
|
||||||
trash-support = ["nu-command/trash-support", "nu-cmd-lang/trash-support"]
|
trash-support = ["nu-command/trash-support", "nu-cmd-lang/trash-support"]
|
||||||
|
|
||||||
# SQLite commands for nushell
|
# SQLite commands for nushell
|
||||||
@ -305,4 +320,4 @@ bench = false
|
|||||||
# Run individual benchmarks like `cargo bench -- <regex>` e.g. `cargo bench -- parse`
|
# Run individual benchmarks like `cargo bench -- <regex>` e.g. `cargo bench -- parse`
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "benchmarks"
|
name = "benchmarks"
|
||||||
harness = false
|
harness = false
|
||||||
|
@ -52,7 +52,7 @@ To use `Nu` in GitHub Action, check [setup-nu](https://github.com/marketplace/ac
|
|||||||
|
|
||||||
Detailed installation instructions can be found in the [installation chapter of the book](https://www.nushell.sh/book/installation.html). Nu is available via many package managers:
|
Detailed installation instructions can be found in the [installation chapter of the book](https://www.nushell.sh/book/installation.html). Nu is available via many package managers:
|
||||||
|
|
||||||
[](https://repology.org/project/nushell/versions)
|
[](https://repology.org/project/nushell/versions)
|
||||||
|
|
||||||
For details about which platforms the Nushell team actively supports, see [our platform support policy](devdocs/PLATFORM_SUPPORT.md).
|
For details about which platforms the Nushell team actively supports, see [our platform support policy](devdocs/PLATFORM_SUPPORT.md).
|
||||||
|
|
||||||
@ -222,6 +222,7 @@ Please submit an issue or PR to be added to this list.
|
|||||||
- [clap](https://github.com/clap-rs/clap/tree/master/clap_complete_nushell)
|
- [clap](https://github.com/clap-rs/clap/tree/master/clap_complete_nushell)
|
||||||
- [Dorothy](http://github.com/bevry/dorothy)
|
- [Dorothy](http://github.com/bevry/dorothy)
|
||||||
- [Direnv](https://github.com/direnv/direnv/blob/master/docs/hook.md#nushell)
|
- [Direnv](https://github.com/direnv/direnv/blob/master/docs/hook.md#nushell)
|
||||||
|
- [x-cmd](https://x-cmd.com/mod/nu)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
29
SECURITY.md
Normal file
29
SECURITY.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
As a shell and programming language Nushell provides you with great powers and the potential to do dangerous things to your computer and data. Whenever there is a risk that a malicious actor can abuse a bug or a violation of documented behavior/assumptions in Nushell to harm you this is a *security* risk.
|
||||||
|
We want to fix those issues without exposing our users to unnecessary risk. Thus we want to explain our security policy.
|
||||||
|
Additional issues may be part of *safety* where the behavior of Nushell as designed and implemented can cause unintended harm or a bug causes damage without the involvement of a third party.
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
As Nushell is still under very active pre-stable development, the only version the core team prioritizes for security and safety fixes is the [most recent version as published on GitHub](https://github.com/nushell/nushell/releases/latest).
|
||||||
|
Only if you provide a strong reasoning and the necessary resources, will we consider blessing a backported fix with an official patch release for a previous version.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you suspect that a bug or behavior of Nushell can affect security or may be potentially exploitable, please report the issue to us in private.
|
||||||
|
Either reach out to the core team on [our Discord server](https://discord.gg/NtAbbGn) to arrange a private channel or use the [GitHub vulnerability reporting form](https://github.com/nushell/nushell/security/advisories/new).
|
||||||
|
Please try to answer the following questions:
|
||||||
|
- How can we reach you for further questions?
|
||||||
|
- What is the bug? Which system of Nushell may be affected?
|
||||||
|
- Do you have proof-of-concept for a potential exploit or have you observed an exploit in the wild?
|
||||||
|
- What is your assessment of the severity based on what could be impacted should the bug be exploited?
|
||||||
|
- Are additional people aware of the issue or deserve credit for identifying the issue?
|
||||||
|
|
||||||
|
We will try to get back to you within a week with:
|
||||||
|
- acknowledging the receipt of the report
|
||||||
|
- an initial plan of how we want to address this including the primary points of contact for further communication
|
||||||
|
- our preliminary assessment of how severe we judge the issue
|
||||||
|
- a proposal for how we can coordinate responsible disclosure (e.g. how we ship the bugfix, if we need to coordinate with distribution maintainers, when you can release a blog post if you want to etc.)
|
||||||
|
|
||||||
|
For purely *safety* related issues where the impact is severe by direct user action instead of malicious input or third parties, feel free to open a regular issue. If we deem that there may be an additional *security* risk on a *safety* issue we may continue discussions in a restricted forum.
|
@ -4,11 +4,14 @@ use nu_plugin_protocol::{PluginCallResponse, PluginOutput};
|
|||||||
|
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
PipelineData, Span, Spanned, Value,
|
PipelineData, Signals, Span, Spanned, Value,
|
||||||
};
|
};
|
||||||
use nu_std::load_standard_library;
|
use nu_std::load_standard_library;
|
||||||
use nu_utils::{get_default_config, get_default_env};
|
use nu_utils::{get_default_config, get_default_env};
|
||||||
use std::rc::Rc;
|
use std::{
|
||||||
|
rc::Rc,
|
||||||
|
sync::{atomic::AtomicBool, Arc},
|
||||||
|
};
|
||||||
|
|
||||||
use std::hint::black_box;
|
use std::hint::black_box;
|
||||||
|
|
||||||
@ -42,13 +45,16 @@ fn setup_stack_and_engine_from_command(command: &str) -> (Stack, EngineState) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut stack = Stack::new();
|
let mut stack = Stack::new();
|
||||||
|
|
||||||
|
// Support running benchmarks without IR mode
|
||||||
|
stack.use_ir = std::env::var_os("NU_DISABLE_IR").is_none();
|
||||||
|
|
||||||
evaluate_commands(
|
evaluate_commands(
|
||||||
&commands,
|
&commands,
|
||||||
&mut engine,
|
&mut engine,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
PipelineData::empty(),
|
PipelineData::empty(),
|
||||||
None,
|
Default::default(),
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -90,8 +96,7 @@ fn bench_command(
|
|||||||
&mut engine,
|
&mut engine,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
PipelineData::empty(),
|
PipelineData::empty(),
|
||||||
None,
|
Default::default(),
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
@ -250,14 +255,12 @@ fn bench_eval_interleave(n: i32) -> impl IntoBenchmarks {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bench_eval_interleave_with_ctrlc(n: i32) -> impl IntoBenchmarks {
|
fn bench_eval_interleave_with_interrupt(n: i32) -> impl IntoBenchmarks {
|
||||||
let mut engine = setup_engine();
|
let mut engine = setup_engine();
|
||||||
engine.ctrlc = Some(std::sync::Arc::new(std::sync::atomic::AtomicBool::new(
|
engine.set_signals(Signals::new(Arc::new(AtomicBool::new(false))));
|
||||||
false,
|
|
||||||
)));
|
|
||||||
let stack = Stack::new();
|
let stack = Stack::new();
|
||||||
bench_command(
|
bench_command(
|
||||||
&format!("eval_interleave_with_ctrlc_{n}"),
|
&format!("eval_interleave_with_interrupt_{n}"),
|
||||||
&format!("seq 1 {n} | wrap a | interleave {{ seq 1 {n} | wrap b }} | ignore"),
|
&format!("seq 1 {n} | wrap a | interleave {{ seq 1 {n} | wrap b }} | ignore"),
|
||||||
stack,
|
stack,
|
||||||
engine,
|
engine,
|
||||||
@ -445,9 +448,9 @@ tango_benchmarks!(
|
|||||||
bench_eval_interleave(100),
|
bench_eval_interleave(100),
|
||||||
bench_eval_interleave(1_000),
|
bench_eval_interleave(1_000),
|
||||||
bench_eval_interleave(10_000),
|
bench_eval_interleave(10_000),
|
||||||
bench_eval_interleave_with_ctrlc(100),
|
bench_eval_interleave_with_interrupt(100),
|
||||||
bench_eval_interleave_with_ctrlc(1_000),
|
bench_eval_interleave_with_interrupt(1_000),
|
||||||
bench_eval_interleave_with_ctrlc(10_000),
|
bench_eval_interleave_with_interrupt(10_000),
|
||||||
// For
|
// For
|
||||||
bench_eval_for(1),
|
bench_eval_for(1),
|
||||||
bench_eval_for(10),
|
bench_eval_for(10),
|
||||||
|
@ -5,27 +5,27 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cli"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "nu-cli"
|
name = "nu-cli"
|
||||||
version = "0.94.2"
|
version = "0.99.1"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.94.2" }
|
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.99.1" }
|
||||||
nu-command = { path = "../nu-command", version = "0.94.2" }
|
nu-command = { path = "../nu-command", version = "0.99.1" }
|
||||||
nu-test-support = { path = "../nu-test-support", version = "0.94.2" }
|
nu-test-support = { path = "../nu-test-support", version = "0.99.1" }
|
||||||
rstest = { workspace = true, default-features = false }
|
rstest = { workspace = true, default-features = false }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nu-cmd-base = { path = "../nu-cmd-base", version = "0.94.2" }
|
nu-cmd-base = { path = "../nu-cmd-base", version = "0.99.1" }
|
||||||
nu-engine = { path = "../nu-engine", version = "0.94.2" }
|
nu-engine = { path = "../nu-engine", version = "0.99.1" }
|
||||||
nu-path = { path = "../nu-path", version = "0.94.2" }
|
nu-path = { path = "../nu-path", version = "0.99.1" }
|
||||||
nu-parser = { path = "../nu-parser", version = "0.94.2" }
|
nu-parser = { path = "../nu-parser", version = "0.99.1" }
|
||||||
nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.94.2", optional = true }
|
nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.99.1", optional = true }
|
||||||
nu-protocol = { path = "../nu-protocol", version = "0.94.2" }
|
nu-protocol = { path = "../nu-protocol", version = "0.99.1" }
|
||||||
nu-utils = { path = "../nu-utils", version = "0.94.2" }
|
nu-utils = { path = "../nu-utils", version = "0.99.1" }
|
||||||
nu-color-config = { path = "../nu-color-config", version = "0.94.2" }
|
nu-color-config = { path = "../nu-color-config", version = "0.99.1" }
|
||||||
nu-ansi-term = { workspace = true }
|
nu-ansi-term = { workspace = true }
|
||||||
reedline = { workspace = true, features = ["bashisms", "sqlite"] }
|
reedline = { workspace = true, features = ["bashisms", "sqlite"] }
|
||||||
|
|
||||||
@ -46,4 +46,7 @@ which = { workspace = true }
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
plugin = ["nu-plugin-engine"]
|
plugin = ["nu-plugin-engine"]
|
||||||
system-clipboard = ["reedline/system_clipboard"]
|
system-clipboard = ["reedline/system_clipboard"]
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
7
crates/nu-cli/README.md
Normal file
7
crates/nu-cli/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
This crate implements the core functionality of the interactive Nushell REPL and interfaces with `reedline`.
|
||||||
|
Currently implements the syntax highlighting and completions logic.
|
||||||
|
Furthermore includes a few commands that are specific to `reedline`
|
||||||
|
|
||||||
|
## Internal Nushell crate
|
||||||
|
|
||||||
|
This crate implements components of Nushell and is not designed to support plugin authors or other users directly.
|
@ -14,7 +14,7 @@ impl Command for Commandline {
|
|||||||
.category(Category::Core)
|
.category(Category::Core)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"View the current command line input buffer."
|
"View the current command line input buffer."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Core)
|
.category(Category::Core)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Modify the current command line input buffer."
|
"Modify the current command line input buffer."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Core)
|
.category(Category::Core)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Get the current cursor position."
|
"Get the current cursor position."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Core)
|
.category(Category::Core)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Set the current cursor position."
|
"Set the current cursor position."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ impl Command for History {
|
|||||||
"history"
|
"history"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Get the command history."
|
"Get the command history."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,91 +42,75 @@ impl Command for History {
|
|||||||
let Some(history) = engine_state.history_config() else {
|
let Some(history) = engine_state.history_config() else {
|
||||||
return Ok(PipelineData::empty());
|
return Ok(PipelineData::empty());
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo for sqlite history this command should be an alias to `open ~/.config/nushell/history.sqlite3 | get history`
|
// todo for sqlite history this command should be an alias to `open ~/.config/nushell/history.sqlite3 | get history`
|
||||||
if let Some(config_path) = nu_path::config_dir() {
|
let Some(history_path) = history.file_path() else {
|
||||||
let clear = call.has_flag(engine_state, stack, "clear")?;
|
return Err(ShellError::ConfigDirNotFound { span: Some(head) });
|
||||||
let long = call.has_flag(engine_state, stack, "long")?;
|
};
|
||||||
let ctrlc = engine_state.ctrlc.clone();
|
|
||||||
|
|
||||||
let mut history_path = config_path;
|
if call.has_flag(engine_state, stack, "clear")? {
|
||||||
history_path.push("nushell");
|
let _ = std::fs::remove_file(history_path);
|
||||||
match history.file_format {
|
// TODO: FIXME also clear the auxiliary files when using sqlite
|
||||||
HistoryFileFormat::Sqlite => {
|
return Ok(PipelineData::empty());
|
||||||
history_path.push("history.sqlite3");
|
}
|
||||||
}
|
|
||||||
HistoryFileFormat::PlainText => {
|
|
||||||
history_path.push("history.txt");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if clear {
|
let long = call.has_flag(engine_state, stack, "long")?;
|
||||||
let _ = std::fs::remove_file(history_path);
|
let signals = engine_state.signals().clone();
|
||||||
// TODO: FIXME also clear the auxiliary files when using sqlite
|
let history_reader: Option<Box<dyn ReedlineHistory>> = match history.file_format {
|
||||||
Ok(PipelineData::empty())
|
HistoryFileFormat::Sqlite => {
|
||||||
} else {
|
SqliteBackedHistory::with_file(history_path.clone(), None, None)
|
||||||
let history_reader: Option<Box<dyn ReedlineHistory>> = match history.file_format {
|
|
||||||
HistoryFileFormat::Sqlite => {
|
|
||||||
SqliteBackedHistory::with_file(history_path.clone(), None, None)
|
|
||||||
.map(|inner| {
|
|
||||||
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
|
|
||||||
boxed
|
|
||||||
})
|
|
||||||
.ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
HistoryFileFormat::PlainText => FileBackedHistory::with_file(
|
|
||||||
history.max_size as usize,
|
|
||||||
history_path.clone(),
|
|
||||||
)
|
|
||||||
.map(|inner| {
|
.map(|inner| {
|
||||||
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
|
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
|
||||||
boxed
|
boxed
|
||||||
})
|
})
|
||||||
.ok(),
|
.ok()
|
||||||
};
|
|
||||||
|
|
||||||
match history.file_format {
|
|
||||||
HistoryFileFormat::PlainText => Ok(history_reader
|
|
||||||
.and_then(|h| {
|
|
||||||
h.search(SearchQuery::everything(SearchDirection::Forward, None))
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.map(move |entries| {
|
|
||||||
entries.into_iter().enumerate().map(move |(idx, entry)| {
|
|
||||||
Value::record(
|
|
||||||
record! {
|
|
||||||
"command" => Value::string(entry.command_line, head),
|
|
||||||
"index" => Value::int(idx as i64, head),
|
|
||||||
},
|
|
||||||
head,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.ok_or(ShellError::FileNotFound {
|
|
||||||
file: history_path.display().to_string(),
|
|
||||||
span: head,
|
|
||||||
})?
|
|
||||||
.into_pipeline_data(head, ctrlc)),
|
|
||||||
HistoryFileFormat::Sqlite => Ok(history_reader
|
|
||||||
.and_then(|h| {
|
|
||||||
h.search(SearchQuery::everything(SearchDirection::Forward, None))
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.map(move |entries| {
|
|
||||||
entries.into_iter().enumerate().map(move |(idx, entry)| {
|
|
||||||
create_history_record(idx, entry, long, head)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.ok_or(ShellError::FileNotFound {
|
|
||||||
file: history_path.display().to_string(),
|
|
||||||
span: head,
|
|
||||||
})?
|
|
||||||
.into_pipeline_data(head, ctrlc)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
HistoryFileFormat::Plaintext => {
|
||||||
Err(ShellError::ConfigDirNotFound { span: Some(head) })
|
FileBackedHistory::with_file(history.max_size as usize, history_path.clone())
|
||||||
|
.map(|inner| {
|
||||||
|
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
|
||||||
|
boxed
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match history.file_format {
|
||||||
|
HistoryFileFormat::Plaintext => Ok(history_reader
|
||||||
|
.and_then(|h| {
|
||||||
|
h.search(SearchQuery::everything(SearchDirection::Forward, None))
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
.map(move |entries| {
|
||||||
|
entries.into_iter().enumerate().map(move |(idx, entry)| {
|
||||||
|
Value::record(
|
||||||
|
record! {
|
||||||
|
"command" => Value::string(entry.command_line, head),
|
||||||
|
"index" => Value::int(idx as i64, head),
|
||||||
|
},
|
||||||
|
head,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.ok_or(ShellError::FileNotFound {
|
||||||
|
file: history_path.display().to_string(),
|
||||||
|
span: head,
|
||||||
|
})?
|
||||||
|
.into_pipeline_data(head, signals)),
|
||||||
|
HistoryFileFormat::Sqlite => Ok(history_reader
|
||||||
|
.and_then(|h| {
|
||||||
|
h.search(SearchQuery::everything(SearchDirection::Forward, None))
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
.map(move |entries| {
|
||||||
|
entries
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(move |(idx, entry)| create_history_record(idx, entry, long, head))
|
||||||
|
})
|
||||||
|
.ok_or(ShellError::FileNotFound {
|
||||||
|
file: history_path.display().to_string(),
|
||||||
|
span: head,
|
||||||
|
})?
|
||||||
|
.into_pipeline_data(head, signals)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,58 +140,34 @@ fn create_history_record(idx: usize, entry: HistoryItem, long: bool, head: Span)
|
|||||||
//2. Create a record of either short or long columns and values
|
//2. Create a record of either short or long columns and values
|
||||||
|
|
||||||
let item_id_value = Value::int(
|
let item_id_value = Value::int(
|
||||||
match entry.id {
|
entry
|
||||||
Some(id) => {
|
.id
|
||||||
let ids = id.to_string();
|
.and_then(|id| id.to_string().parse::<i64>().ok())
|
||||||
match ids.parse::<i64>() {
|
.unwrap_or_default(),
|
||||||
Ok(i) => i,
|
|
||||||
_ => 0i64,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0i64,
|
|
||||||
},
|
|
||||||
head,
|
head,
|
||||||
);
|
);
|
||||||
let start_timestamp_value = Value::string(
|
let start_timestamp_value = Value::string(
|
||||||
match entry.start_timestamp {
|
entry
|
||||||
Some(time) => time.to_string(),
|
.start_timestamp
|
||||||
None => "".into(),
|
.map(|time| time.to_string())
|
||||||
},
|
.unwrap_or_default(),
|
||||||
head,
|
head,
|
||||||
);
|
);
|
||||||
let command_value = Value::string(entry.command_line, head);
|
let command_value = Value::string(entry.command_line, head);
|
||||||
let session_id_value = Value::int(
|
let session_id_value = Value::int(
|
||||||
match entry.session_id {
|
entry
|
||||||
Some(sid) => {
|
.session_id
|
||||||
let sids = sid.to_string();
|
.and_then(|id| id.to_string().parse::<i64>().ok())
|
||||||
match sids.parse::<i64>() {
|
.unwrap_or_default(),
|
||||||
Ok(i) => i,
|
|
||||||
_ => 0i64,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0i64,
|
|
||||||
},
|
|
||||||
head,
|
|
||||||
);
|
|
||||||
let hostname_value = Value::string(
|
|
||||||
match entry.hostname {
|
|
||||||
Some(host) => host,
|
|
||||||
None => "".into(),
|
|
||||||
},
|
|
||||||
head,
|
|
||||||
);
|
|
||||||
let cwd_value = Value::string(
|
|
||||||
match entry.cwd {
|
|
||||||
Some(cwd) => cwd,
|
|
||||||
None => "".into(),
|
|
||||||
},
|
|
||||||
head,
|
head,
|
||||||
);
|
);
|
||||||
|
let hostname_value = Value::string(entry.hostname.unwrap_or_default(), head);
|
||||||
|
let cwd_value = Value::string(entry.cwd.unwrap_or_default(), head);
|
||||||
let duration_value = Value::duration(
|
let duration_value = Value::duration(
|
||||||
match entry.duration {
|
entry
|
||||||
Some(d) => d.as_nanos().try_into().unwrap_or(0),
|
.duration
|
||||||
None => 0,
|
.and_then(|d| d.as_nanos().try_into().ok())
|
||||||
},
|
.unwrap_or(0),
|
||||||
head,
|
head,
|
||||||
);
|
);
|
||||||
let exit_status_value = Value::int(entry.exit_status.unwrap_or(0), head);
|
let exit_status_value = Value::int(entry.exit_status.unwrap_or(0), head);
|
||||||
|
@ -8,7 +8,7 @@ impl Command for HistorySession {
|
|||||||
"history session"
|
"history session"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Get the command history session."
|
"Get the command history session."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ impl Command for Keybindings {
|
|||||||
.input_output_types(vec![(Type::Nothing, Type::String)])
|
.input_output_types(vec![(Type::Nothing, Type::String)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Keybindings related commands."
|
"Keybindings related commands."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_usage(&self) -> &str {
|
fn extra_description(&self) -> &str {
|
||||||
r#"You must use one of the following subcommands. Using this command as-is will only produce this help message.
|
r#"You must use one of the following subcommands. Using this command as-is will only produce this help message.
|
||||||
|
|
||||||
For more information on input and keybindings, check:
|
For more information on input and keybindings, check:
|
||||||
|
@ -15,7 +15,7 @@ impl Command for KeybindingsDefault {
|
|||||||
.input_output_types(vec![(Type::Nothing, Type::table())])
|
.input_output_types(vec![(Type::Nothing, Type::table())])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"List default keybindings."
|
"List default keybindings."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ impl Command for KeybindingsList {
|
|||||||
.category(Category::Platform)
|
.category(Category::Platform)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"List available options that can be used to create keybindings."
|
"List available options that can be used to create keybindings."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,22 +49,26 @@ impl Command for KeybindingsList {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&self,
|
&self,
|
||||||
_engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
_stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
_input: PipelineData,
|
_input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let records = if call.named_len() == 0 {
|
let all_options = ["modifiers", "keycodes", "edits", "modes", "events"];
|
||||||
let all_options = ["modifiers", "keycodes", "edits", "modes", "events"];
|
|
||||||
all_options
|
let presence = all_options
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|argument| get_records(argument, call.head))
|
.map(|option| call.has_flag(engine_state, stack, option))
|
||||||
.collect()
|
.collect::<Result<Vec<_>, ShellError>>()?;
|
||||||
} else {
|
|
||||||
call.named_iter()
|
let no_option_specified = presence.iter().all(|present| !*present);
|
||||||
.flat_map(|(argument, _, _)| get_records(argument.item.as_str(), call.head))
|
|
||||||
.collect()
|
let records = all_options
|
||||||
};
|
.iter()
|
||||||
|
.zip(presence)
|
||||||
|
.filter(|(_, present)| no_option_specified || *present)
|
||||||
|
.flat_map(|(option, _)| get_records(option, call.head))
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(Value::list(records, call.head).into_pipeline_data())
|
Ok(Value::list(records, call.head).into_pipeline_data())
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ impl Command for KeybindingsListen {
|
|||||||
"keybindings listen"
|
"keybindings listen"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Get input from the user."
|
"Get input from the user."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_usage(&self) -> &str {
|
fn extra_description(&self) -> &str {
|
||||||
"This is an internal debugging tool. For better output, try `input listen --types [key]`"
|
"This is an internal debugging tool. For better output, try `input listen --types [key]`"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,50 +1,23 @@
|
|||||||
use crate::completions::{CompletionOptions, SortBy};
|
use crate::completions::CompletionOptions;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{Stack, StateWorkingSet},
|
engine::{Stack, StateWorkingSet},
|
||||||
levenshtein_distance, Span,
|
Span,
|
||||||
};
|
};
|
||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
|
|
||||||
// Completer trait represents the three stages of the completion
|
|
||||||
// fetch, filter and sort
|
|
||||||
pub trait Completer {
|
pub trait Completer {
|
||||||
|
/// Fetch, filter, and sort completions
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn fetch(
|
fn fetch(
|
||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
stack: &Stack,
|
stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
options: &CompletionOptions,
|
options: &CompletionOptions,
|
||||||
) -> Vec<SemanticSuggestion>;
|
) -> Vec<SemanticSuggestion>;
|
||||||
|
|
||||||
fn get_sort_by(&self) -> SortBy {
|
|
||||||
SortBy::Ascending
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sort(&self, items: Vec<SemanticSuggestion>, prefix: Vec<u8>) -> Vec<SemanticSuggestion> {
|
|
||||||
let prefix_str = String::from_utf8_lossy(&prefix).to_string();
|
|
||||||
let mut filtered_items = items;
|
|
||||||
|
|
||||||
// Sort items
|
|
||||||
match self.get_sort_by() {
|
|
||||||
SortBy::LevenshteinDistance => {
|
|
||||||
filtered_items.sort_by(|a, b| {
|
|
||||||
let a_distance = levenshtein_distance(&prefix_str, &a.suggestion.value);
|
|
||||||
let b_distance = levenshtein_distance(&prefix_str, &b.suggestion.value);
|
|
||||||
a_distance.cmp(&b_distance)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
SortBy::Ascending => {
|
|
||||||
filtered_items.sort_by(|a, b| a.suggestion.value.cmp(&b.suggestion.value));
|
|
||||||
}
|
|
||||||
SortBy::None => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
filtered_items
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq)]
|
#[derive(Debug, Default, PartialEq)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
completions::{Completer, CompletionOptions, MatchAlgorithm, SortBy},
|
completions::{Completer, CompletionOptions, MatchAlgorithm},
|
||||||
SuggestionKind,
|
SuggestionKind,
|
||||||
};
|
};
|
||||||
use nu_parser::FlatShape;
|
use nu_parser::FlatShape;
|
||||||
@ -9,7 +9,7 @@ use nu_protocol::{
|
|||||||
};
|
};
|
||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
|
|
||||||
use super::SemanticSuggestion;
|
use super::{completion_common::sort_suggestions, SemanticSuggestion};
|
||||||
|
|
||||||
pub struct CommandCompletion {
|
pub struct CommandCompletion {
|
||||||
flattened: Vec<(Span, FlatShape)>,
|
flattened: Vec<(Span, FlatShape)>,
|
||||||
@ -51,7 +51,9 @@ impl CommandCompletion {
|
|||||||
if working_set
|
if working_set
|
||||||
.permanent_state
|
.permanent_state
|
||||||
.config
|
.config
|
||||||
.max_external_completion_results
|
.completions
|
||||||
|
.external
|
||||||
|
.max_results
|
||||||
> executables.len() as i64
|
> executables.len() as i64
|
||||||
&& !executables.contains(
|
&& !executables.contains(
|
||||||
&item
|
&item
|
||||||
@ -99,10 +101,9 @@ impl CommandCompletion {
|
|||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: String::from_utf8_lossy(&x.0).to_string(),
|
value: String::from_utf8_lossy(&x.0).to_string(),
|
||||||
description: x.1,
|
description: x.1,
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span::new(span.start - offset, span.end - offset),
|
span: reedline::Span::new(span.start - offset, span.end - offset),
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(SuggestionKind::Command(x.2)),
|
kind: Some(SuggestionKind::Command(x.2)),
|
||||||
})
|
})
|
||||||
@ -118,11 +119,9 @@ impl CommandCompletion {
|
|||||||
.map(move |x| SemanticSuggestion {
|
.map(move |x| SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: x,
|
value: x,
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span::new(span.start - offset, span.end - offset),
|
span: reedline::Span::new(span.start - offset, span.end - offset),
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO: is there a way to create a test?
|
// TODO: is there a way to create a test?
|
||||||
kind: None,
|
kind: None,
|
||||||
@ -136,11 +135,9 @@ impl CommandCompletion {
|
|||||||
results.push(SemanticSuggestion {
|
results.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: format!("^{}", external.suggestion.value),
|
value: format!("^{}", external.suggestion.value),
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: external.suggestion.span,
|
span: external.suggestion.span,
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: external.kind,
|
kind: external.kind,
|
||||||
})
|
})
|
||||||
@ -161,7 +158,7 @@ impl Completer for CommandCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
_stack: &Stack,
|
_stack: &Stack,
|
||||||
_prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
@ -198,7 +195,7 @@ impl Completer for CommandCompletion {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if !subcommands.is_empty() {
|
if !subcommands.is_empty() {
|
||||||
return subcommands;
|
return sort_suggestions(&String::from_utf8_lossy(prefix), subcommands, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = working_set.get_config();
|
let config = working_set.get_config();
|
||||||
@ -216,18 +213,14 @@ impl Completer for CommandCompletion {
|
|||||||
working_set,
|
working_set,
|
||||||
span,
|
span,
|
||||||
offset,
|
offset,
|
||||||
config.enable_external_completion,
|
config.completions.external.enable,
|
||||||
options.match_algorithm,
|
options.match_algorithm,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
subcommands.into_iter().chain(commands).collect::<Vec<_>>()
|
sort_suggestions(&String::from_utf8_lossy(prefix), commands, options)
|
||||||
}
|
|
||||||
|
|
||||||
fn get_sort_by(&self) -> SortBy {
|
|
||||||
SortBy::LevenshteinDistance
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::completions::{
|
use crate::completions::{
|
||||||
CommandCompletion, Completer, CompletionOptions, CustomCompletion, DirectoryCompletion,
|
CommandCompletion, Completer, CompletionOptions, CustomCompletion, DirectoryCompletion,
|
||||||
DotNuCompletion, FileCompletion, FlagCompletion, VariableCompletion,
|
DotNuCompletion, FileCompletion, FlagCompletion, OperatorCompletion, VariableCompletion,
|
||||||
};
|
};
|
||||||
use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style};
|
use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style};
|
||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
@ -25,7 +25,7 @@ impl NuCompleter {
|
|||||||
pub fn new(engine_state: Arc<EngineState>, stack: Arc<Stack>) -> Self {
|
pub fn new(engine_state: Arc<EngineState>, stack: Arc<Stack>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
engine_state,
|
engine_state,
|
||||||
stack: Stack::with_parent(stack).reset_out_dest().capture(),
|
stack: Stack::with_parent(stack).reset_out_dest().collect_value(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ impl NuCompleter {
|
|||||||
&self,
|
&self,
|
||||||
completer: &mut T,
|
completer: &mut T,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
new_span: Span,
|
new_span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
@ -46,26 +46,21 @@ impl NuCompleter {
|
|||||||
let config = self.engine_state.get_config();
|
let config = self.engine_state.get_config();
|
||||||
|
|
||||||
let options = CompletionOptions {
|
let options = CompletionOptions {
|
||||||
case_sensitive: config.case_sensitive_completions,
|
case_sensitive: config.completions.case_sensitive,
|
||||||
match_algorithm: config.completion_algorithm.into(),
|
match_algorithm: config.completions.algorithm.into(),
|
||||||
|
sort: config.completions.sort,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch
|
completer.fetch(
|
||||||
let mut suggestions = completer.fetch(
|
|
||||||
working_set,
|
working_set,
|
||||||
&self.stack,
|
&self.stack,
|
||||||
prefix.clone(),
|
prefix,
|
||||||
new_span,
|
new_span,
|
||||||
offset,
|
offset,
|
||||||
pos,
|
pos,
|
||||||
&options,
|
&options,
|
||||||
);
|
)
|
||||||
|
|
||||||
// Sort
|
|
||||||
suggestions = completer.sort(suggestions, prefix);
|
|
||||||
|
|
||||||
suggestions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn external_completion(
|
fn external_completion(
|
||||||
@ -175,23 +170,38 @@ impl NuCompleter {
|
|||||||
let new_span = Span::new(flat.0.start, flat.0.end - 1);
|
let new_span = Span::new(flat.0.start, flat.0.end - 1);
|
||||||
|
|
||||||
// Parses the prefix. Completion should look up to the cursor position, not after.
|
// Parses the prefix. Completion should look up to the cursor position, not after.
|
||||||
let mut prefix = working_set.get_span_contents(flat.0).to_vec();
|
let mut prefix = working_set.get_span_contents(flat.0);
|
||||||
let index = pos - flat.0.start;
|
let index = pos - flat.0.start;
|
||||||
prefix.drain(index..);
|
prefix = &prefix[..index];
|
||||||
|
|
||||||
// Variables completion
|
// Variables completion
|
||||||
if prefix.starts_with(b"$") || most_left_var.is_some() {
|
if prefix.starts_with(b"$") || most_left_var.is_some() {
|
||||||
let mut completer =
|
let mut variable_names_completer =
|
||||||
VariableCompletion::new(most_left_var.unwrap_or((vec![], vec![])));
|
VariableCompletion::new(most_left_var.unwrap_or((vec![], vec![])));
|
||||||
|
|
||||||
return self.process_completion(
|
let mut variable_completions = self.process_completion(
|
||||||
&mut completer,
|
&mut variable_names_completer,
|
||||||
&working_set,
|
&working_set,
|
||||||
prefix,
|
prefix,
|
||||||
new_span,
|
new_span,
|
||||||
fake_offset,
|
fake_offset,
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut variable_operations_completer =
|
||||||
|
OperatorCompletion::new(pipeline_element.expr.clone());
|
||||||
|
|
||||||
|
let mut variable_operations_completions = self.process_completion(
|
||||||
|
&mut variable_operations_completer,
|
||||||
|
&working_set,
|
||||||
|
prefix,
|
||||||
|
new_span,
|
||||||
|
fake_offset,
|
||||||
|
pos,
|
||||||
|
);
|
||||||
|
|
||||||
|
variable_completions.append(&mut variable_operations_completions);
|
||||||
|
return variable_completions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flags completion
|
// Flags completion
|
||||||
@ -201,7 +211,7 @@ impl NuCompleter {
|
|||||||
let result = self.process_completion(
|
let result = self.process_completion(
|
||||||
&mut completer,
|
&mut completer,
|
||||||
&working_set,
|
&working_set,
|
||||||
prefix.clone(),
|
prefix,
|
||||||
new_span,
|
new_span,
|
||||||
fake_offset,
|
fake_offset,
|
||||||
pos,
|
pos,
|
||||||
@ -213,7 +223,7 @@ impl NuCompleter {
|
|||||||
|
|
||||||
// We got no results for internal completion
|
// We got no results for internal completion
|
||||||
// now we can check if external completer is set and use it
|
// now we can check if external completer is set and use it
|
||||||
if let Some(closure) = config.external_completer.as_ref() {
|
if let Some(closure) = config.completions.external.completer.as_ref() {
|
||||||
if let Some(external_result) =
|
if let Some(external_result) =
|
||||||
self.external_completion(closure, &spans, fake_offset, new_span)
|
self.external_completion(closure, &spans, fake_offset, new_span)
|
||||||
{
|
{
|
||||||
@ -267,6 +277,26 @@ impl NuCompleter {
|
|||||||
} else if prev_expr_str == b"ls" {
|
} else if prev_expr_str == b"ls" {
|
||||||
let mut completer = FileCompletion::new();
|
let mut completer = FileCompletion::new();
|
||||||
|
|
||||||
|
return self.process_completion(
|
||||||
|
&mut completer,
|
||||||
|
&working_set,
|
||||||
|
prefix,
|
||||||
|
new_span,
|
||||||
|
fake_offset,
|
||||||
|
pos,
|
||||||
|
);
|
||||||
|
} else if matches!(
|
||||||
|
previous_expr.1,
|
||||||
|
FlatShape::Float
|
||||||
|
| FlatShape::Int
|
||||||
|
| FlatShape::String
|
||||||
|
| FlatShape::List
|
||||||
|
| FlatShape::Bool
|
||||||
|
| FlatShape::Variable(_)
|
||||||
|
) {
|
||||||
|
let mut completer =
|
||||||
|
OperatorCompletion::new(pipeline_element.expr.clone());
|
||||||
|
|
||||||
return self.process_completion(
|
return self.process_completion(
|
||||||
&mut completer,
|
&mut completer,
|
||||||
&working_set,
|
&working_set,
|
||||||
@ -332,7 +362,7 @@ impl NuCompleter {
|
|||||||
let mut out: Vec<_> = self.process_completion(
|
let mut out: Vec<_> = self.process_completion(
|
||||||
&mut completer,
|
&mut completer,
|
||||||
&working_set,
|
&working_set,
|
||||||
prefix.clone(),
|
prefix,
|
||||||
new_span,
|
new_span,
|
||||||
fake_offset,
|
fake_offset,
|
||||||
pos,
|
pos,
|
||||||
@ -343,7 +373,9 @@ impl NuCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to complete using an external completer (if set)
|
// Try to complete using an external completer (if set)
|
||||||
if let Some(closure) = config.external_completer.as_ref() {
|
if let Some(closure) =
|
||||||
|
config.completions.external.completer.as_ref()
|
||||||
|
{
|
||||||
if let Some(external_result) = self.external_completion(
|
if let Some(external_result) = self.external_completion(
|
||||||
closure,
|
closure,
|
||||||
&spans,
|
&spans,
|
||||||
@ -449,14 +481,11 @@ pub fn map_value_completions<'a>(
|
|||||||
return Some(SemanticSuggestion {
|
return Some(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: s,
|
value: s,
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: span.start - offset,
|
start: span.start - offset,
|
||||||
end: span.end - offset,
|
end: span.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(SuggestionKind::Type(x.get_type())),
|
kind: Some(SuggestionKind::Type(x.get_type())),
|
||||||
});
|
});
|
||||||
@ -466,14 +495,11 @@ pub fn map_value_completions<'a>(
|
|||||||
if let Ok(record) = x.as_record() {
|
if let Ok(record) = x.as_record() {
|
||||||
let mut suggestion = Suggestion {
|
let mut suggestion = Suggestion {
|
||||||
value: String::from(""), // Initialize with empty string
|
value: String::from(""), // Initialize with empty string
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: span.start - offset,
|
start: span.start - offset,
|
||||||
end: span.end - offset,
|
end: span.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Iterate the cols looking for `value` and `description`
|
// Iterate the cols looking for `value` and `description`
|
||||||
@ -542,6 +568,11 @@ mod completer_tests {
|
|||||||
|
|
||||||
let mut completer = NuCompleter::new(engine_state.into(), Arc::new(Stack::new()));
|
let mut completer = NuCompleter::new(engine_state.into(), Arc::new(Stack::new()));
|
||||||
let dataset = [
|
let dataset = [
|
||||||
|
("1 bit-sh", true, "b", vec!["bit-shl", "bit-shr"]),
|
||||||
|
("1.0 bit-sh", false, "b", vec![]),
|
||||||
|
("1 m", true, "m", vec!["mod"]),
|
||||||
|
("1.0 m", true, "m", vec!["mod"]),
|
||||||
|
("\"a\" s", true, "s", vec!["starts-with"]),
|
||||||
("sudo", false, "", Vec::new()),
|
("sudo", false, "", Vec::new()),
|
||||||
("sudo l", true, "l", vec!["ls", "let", "lines", "loop"]),
|
("sudo l", true, "l", vec!["ls", "let", "lines", "loop"]),
|
||||||
(" sudo", false, "", Vec::new()),
|
(" sudo", false, "", Vec::new()),
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
use crate::completions::{matches, CompletionOptions};
|
use super::MatchAlgorithm;
|
||||||
|
use crate::{
|
||||||
|
completions::{matches, CompletionOptions},
|
||||||
|
SemanticSuggestion,
|
||||||
|
};
|
||||||
|
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
use nu_engine::env_to_string;
|
use nu_engine::env_to_string;
|
||||||
use nu_path::home_dir;
|
use nu_path::dots::expand_ndots;
|
||||||
|
use nu_path::{expand_to_real_path, home_dir};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
Span,
|
CompletionSort, Span,
|
||||||
};
|
};
|
||||||
use nu_utils::get_ls_colors;
|
use nu_utils::get_ls_colors;
|
||||||
use std::path::{
|
use std::path::{is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP};
|
||||||
is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PathBuiltFromString {
|
pub struct PathBuiltFromString {
|
||||||
@ -17,22 +21,31 @@ pub struct PathBuiltFromString {
|
|||||||
isdir: bool,
|
isdir: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_rec(
|
/// Recursively goes through paths that match a given `partial`.
|
||||||
|
/// built: State struct for a valid matching path built so far.
|
||||||
|
///
|
||||||
|
/// `isdir`: whether the current partial path has a trailing slash.
|
||||||
|
/// Parsing a path string into a pathbuf loses that bit of information.
|
||||||
|
///
|
||||||
|
/// want_directory: Whether we want only directories as completion matches.
|
||||||
|
/// Some commands like `cd` can only be run on directories whereas others
|
||||||
|
/// like `ls` can be run on regular files as well.
|
||||||
|
pub fn complete_rec(
|
||||||
partial: &[&str],
|
partial: &[&str],
|
||||||
built: &PathBuiltFromString,
|
built: &PathBuiltFromString,
|
||||||
cwd: &Path,
|
cwd: &Path,
|
||||||
options: &CompletionOptions,
|
options: &CompletionOptions,
|
||||||
dir: bool,
|
want_directory: bool,
|
||||||
isdir: bool,
|
isdir: bool,
|
||||||
) -> Vec<PathBuiltFromString> {
|
) -> Vec<PathBuiltFromString> {
|
||||||
let mut completions = vec![];
|
let mut completions = vec![];
|
||||||
|
|
||||||
if let Some((&base, rest)) = partial.split_first() {
|
if let Some((&base, rest)) = partial.split_first() {
|
||||||
if (base == "." || base == "..") && (isdir || !rest.is_empty()) {
|
if base.chars().all(|c| c == '.') && (isdir || !rest.is_empty()) {
|
||||||
let mut built = built.clone();
|
let mut built = built.clone();
|
||||||
built.parts.push(base.to_string());
|
built.parts.push(base.to_string());
|
||||||
built.isdir = true;
|
built.isdir = true;
|
||||||
return complete_rec(rest, &built, cwd, options, dir, isdir);
|
return complete_rec(rest, &built, cwd, options, want_directory, isdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +58,7 @@ fn complete_rec(
|
|||||||
return completions;
|
return completions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut entries = Vec::new();
|
||||||
for entry in result.filter_map(|e| e.ok()) {
|
for entry in result.filter_map(|e| e.ok()) {
|
||||||
let entry_name = entry.file_name().to_string_lossy().into_owned();
|
let entry_name = entry.file_name().to_string_lossy().into_owned();
|
||||||
let entry_isdir = entry.path().is_dir();
|
let entry_isdir = entry.path().is_dir();
|
||||||
@ -52,22 +66,45 @@ fn complete_rec(
|
|||||||
built.parts.push(entry_name.clone());
|
built.parts.push(entry_name.clone());
|
||||||
built.isdir = entry_isdir;
|
built.isdir = entry_isdir;
|
||||||
|
|
||||||
if !dir || entry_isdir {
|
if !want_directory || entry_isdir {
|
||||||
match partial.split_first() {
|
entries.push((entry_name, built));
|
||||||
Some((base, rest)) => {
|
}
|
||||||
if matches(base, &entry_name, options) {
|
}
|
||||||
if !rest.is_empty() || isdir {
|
|
||||||
completions
|
let prefix = partial.first().unwrap_or(&"");
|
||||||
.extend(complete_rec(rest, &built, cwd, options, dir, isdir));
|
let sorted_entries = sort_completions(prefix, entries, options, |(entry, _)| entry);
|
||||||
} else {
|
|
||||||
completions.push(built);
|
for (entry_name, built) in sorted_entries {
|
||||||
}
|
match partial.split_first() {
|
||||||
|
Some((base, rest)) => {
|
||||||
|
if matches(base, &entry_name, options) {
|
||||||
|
// We use `isdir` to confirm that the current component has
|
||||||
|
// at least one next component or a slash.
|
||||||
|
// Serves as confirmation to ignore longer completions for
|
||||||
|
// components in between.
|
||||||
|
if !rest.is_empty() || isdir {
|
||||||
|
completions.extend(complete_rec(
|
||||||
|
rest,
|
||||||
|
&built,
|
||||||
|
cwd,
|
||||||
|
options,
|
||||||
|
want_directory,
|
||||||
|
isdir,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
completions.push(built);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
if entry_name.eq(base)
|
||||||
completions.push(built);
|
&& matches!(options.match_algorithm, MatchAlgorithm::Prefix)
|
||||||
|
&& isdir
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
completions.push(built);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
completions
|
completions
|
||||||
@ -81,16 +118,16 @@ enum OriginalCwd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl OriginalCwd {
|
impl OriginalCwd {
|
||||||
fn apply(&self, mut p: PathBuiltFromString) -> String {
|
fn apply(&self, mut p: PathBuiltFromString, path_separator: char) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::None => {}
|
Self::None => {}
|
||||||
Self::Home => p.parts.insert(0, "~".to_string()),
|
Self::Home => p.parts.insert(0, "~".to_string()),
|
||||||
Self::Prefix(s) => p.parts.insert(0, s.clone()),
|
Self::Prefix(s) => p.parts.insert(0, s.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ret = p.parts.join(MAIN_SEPARATOR_STR);
|
let mut ret = p.parts.join(&path_separator.to_string());
|
||||||
if p.isdir {
|
if p.isdir {
|
||||||
ret.push(SEP);
|
ret.push(path_separator);
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
@ -119,14 +156,31 @@ pub fn complete_item(
|
|||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &Stack,
|
stack: &Stack,
|
||||||
) -> Vec<(nu_protocol::Span, String, Option<Style>)> {
|
) -> Vec<(nu_protocol::Span, String, Option<Style>)> {
|
||||||
let partial = surround_remove(partial);
|
let cleaned_partial = surround_remove(partial);
|
||||||
let isdir = partial.ends_with(is_separator);
|
let isdir = cleaned_partial.ends_with(is_separator);
|
||||||
|
let expanded_partial = expand_ndots(Path::new(&cleaned_partial));
|
||||||
|
let should_collapse_dots = expanded_partial != Path::new(&cleaned_partial);
|
||||||
|
let mut partial = expanded_partial.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
let path_separator = SEP;
|
||||||
|
#[cfg(windows)]
|
||||||
|
let path_separator = cleaned_partial
|
||||||
|
.chars()
|
||||||
|
.rfind(|c: &char| is_separator(*c))
|
||||||
|
.unwrap_or(SEP);
|
||||||
|
|
||||||
|
// Handle the trailing dot case
|
||||||
|
if cleaned_partial.ends_with(&format!("{path_separator}.")) {
|
||||||
|
partial.push_str(&format!("{path_separator}."));
|
||||||
|
}
|
||||||
|
|
||||||
let cwd_pathbuf = Path::new(cwd).to_path_buf();
|
let cwd_pathbuf = Path::new(cwd).to_path_buf();
|
||||||
let ls_colors = (engine_state.config.use_ls_colors_completions
|
let ls_colors = (engine_state.config.completions.use_ls_colors
|
||||||
&& engine_state.config.use_ansi_coloring)
|
&& engine_state.config.use_ansi_coloring)
|
||||||
.then(|| {
|
.then(|| {
|
||||||
let ls_colors_env_str = match stack.get_env_var(engine_state, "LS_COLORS") {
|
let ls_colors_env_str = match stack.get_env_var(engine_state, "LS_COLORS") {
|
||||||
Some(v) => env_to_string("LS_COLORS", &v, engine_state, stack).ok(),
|
Some(v) => env_to_string("LS_COLORS", v, engine_state, stack).ok(),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
get_ls_colors(ls_colors_env_str)
|
get_ls_colors(ls_colors_env_str)
|
||||||
@ -140,16 +194,11 @@ pub fn complete_item(
|
|||||||
match components.peek().cloned() {
|
match components.peek().cloned() {
|
||||||
Some(c @ Component::Prefix(..)) => {
|
Some(c @ Component::Prefix(..)) => {
|
||||||
// windows only by definition
|
// windows only by definition
|
||||||
components.next();
|
|
||||||
if let Some(Component::RootDir) = components.peek().cloned() {
|
|
||||||
components.next();
|
|
||||||
};
|
|
||||||
cwd = [c, Component::RootDir].iter().collect();
|
cwd = [c, Component::RootDir].iter().collect();
|
||||||
prefix_len = c.as_os_str().len();
|
prefix_len = c.as_os_str().len();
|
||||||
original_cwd = OriginalCwd::Prefix(c.as_os_str().to_string_lossy().into_owned());
|
original_cwd = OriginalCwd::Prefix(c.as_os_str().to_string_lossy().into_owned());
|
||||||
}
|
}
|
||||||
Some(c @ Component::RootDir) => {
|
Some(c @ Component::RootDir) => {
|
||||||
components.next();
|
|
||||||
// This is kind of a hack. When joining an empty string with the rest,
|
// This is kind of a hack. When joining an empty string with the rest,
|
||||||
// we add the slash automagically
|
// we add the slash automagically
|
||||||
cwd = PathBuf::from(c.as_os_str());
|
cwd = PathBuf::from(c.as_os_str());
|
||||||
@ -157,8 +206,7 @@ pub fn complete_item(
|
|||||||
original_cwd = OriginalCwd::Prefix(String::new());
|
original_cwd = OriginalCwd::Prefix(String::new());
|
||||||
}
|
}
|
||||||
Some(Component::Normal(home)) if home.to_string_lossy() == "~" => {
|
Some(Component::Normal(home)) if home.to_string_lossy() == "~" => {
|
||||||
components.next();
|
cwd = home_dir().map(Into::into).unwrap_or(cwd_pathbuf);
|
||||||
cwd = home_dir().unwrap_or(cwd_pathbuf);
|
|
||||||
prefix_len = 1;
|
prefix_len = 1;
|
||||||
original_cwd = OriginalCwd::Home;
|
original_cwd = OriginalCwd::Home;
|
||||||
}
|
}
|
||||||
@ -182,12 +230,20 @@ pub fn complete_item(
|
|||||||
isdir,
|
isdir,
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| {
|
.map(|mut p| {
|
||||||
let path = original_cwd.apply(p);
|
if should_collapse_dots {
|
||||||
|
p = collapse_ndots(p);
|
||||||
|
}
|
||||||
|
let path = original_cwd.apply(p, path_separator);
|
||||||
let style = ls_colors.as_ref().map(|lsc| {
|
let style = ls_colors.as_ref().map(|lsc| {
|
||||||
lsc.style_for_path_with_metadata(&path, std::fs::symlink_metadata(&path).ok().as_ref())
|
lsc.style_for_path_with_metadata(
|
||||||
.map(lscolors::Style::to_nu_ansi_term_style)
|
&path,
|
||||||
.unwrap_or_default()
|
std::fs::symlink_metadata(expand_to_real_path(&path))
|
||||||
|
.ok()
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.map(lscolors::Style::to_nu_ansi_term_style)
|
||||||
|
.unwrap_or_default()
|
||||||
});
|
});
|
||||||
(span, escape_path(path, want_directory), style)
|
(span, escape_path(path, want_directory), style)
|
||||||
})
|
})
|
||||||
@ -211,8 +267,10 @@ pub fn escape_path(path: String, dir: bool) -> String {
|
|||||||
let filename_contaminated = !dir && path.contains(['\'', '"', ' ', '#', '(', ')']);
|
let filename_contaminated = !dir && path.contains(['\'', '"', ' ', '#', '(', ')']);
|
||||||
let dirname_contaminated = dir && path.contains(['\'', '"', ' ', '#']);
|
let dirname_contaminated = dir && path.contains(['\'', '"', ' ', '#']);
|
||||||
let maybe_flag = path.starts_with('-');
|
let maybe_flag = path.starts_with('-');
|
||||||
|
let maybe_variable = path.starts_with('$');
|
||||||
let maybe_number = path.parse::<f64>().is_ok();
|
let maybe_number = path.parse::<f64>().is_ok();
|
||||||
if filename_contaminated || dirname_contaminated || maybe_flag || maybe_number {
|
if filename_contaminated || dirname_contaminated || maybe_flag || maybe_variable || maybe_number
|
||||||
|
{
|
||||||
format!("`{path}`")
|
format!("`{path}`")
|
||||||
} else {
|
} else {
|
||||||
path
|
path
|
||||||
@ -251,3 +309,76 @@ pub fn adjust_if_intermediate(
|
|||||||
readjusted,
|
readjusted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience function to sort suggestions using [`sort_completions`]
|
||||||
|
pub fn sort_suggestions(
|
||||||
|
prefix: &str,
|
||||||
|
items: Vec<SemanticSuggestion>,
|
||||||
|
options: &CompletionOptions,
|
||||||
|
) -> Vec<SemanticSuggestion> {
|
||||||
|
sort_completions(prefix, items, options, |it| &it.suggestion.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Arguments
|
||||||
|
/// * `prefix` - What the user's typed, for sorting by fuzzy matcher score
|
||||||
|
pub fn sort_completions<T>(
|
||||||
|
prefix: &str,
|
||||||
|
mut items: Vec<T>,
|
||||||
|
options: &CompletionOptions,
|
||||||
|
get_value: fn(&T) -> &str,
|
||||||
|
) -> Vec<T> {
|
||||||
|
// Sort items
|
||||||
|
if options.sort == CompletionSort::Smart && options.match_algorithm == MatchAlgorithm::Fuzzy {
|
||||||
|
let mut matcher = SkimMatcherV2::default();
|
||||||
|
if options.case_sensitive {
|
||||||
|
matcher = matcher.respect_case();
|
||||||
|
} else {
|
||||||
|
matcher = matcher.ignore_case();
|
||||||
|
};
|
||||||
|
items.sort_unstable_by(|a, b| {
|
||||||
|
let a_str = get_value(a);
|
||||||
|
let b_str = get_value(b);
|
||||||
|
let a_score = matcher.fuzzy_match(a_str, prefix).unwrap_or_default();
|
||||||
|
let b_score = matcher.fuzzy_match(b_str, prefix).unwrap_or_default();
|
||||||
|
b_score.cmp(&a_score).then(a_str.cmp(b_str))
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
items.sort_unstable_by(|a, b| get_value(a).cmp(get_value(b)));
|
||||||
|
}
|
||||||
|
|
||||||
|
items
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Collapse multiple ".." components into n-dots.
|
||||||
|
///
|
||||||
|
/// It performs the reverse operation of `expand_ndots`, collapsing sequences of ".." into n-dots,
|
||||||
|
/// such as "..." and "....".
|
||||||
|
///
|
||||||
|
/// The resulting path will use platform-specific path separators, regardless of what path separators were used in the input.
|
||||||
|
fn collapse_ndots(path: PathBuiltFromString) -> PathBuiltFromString {
|
||||||
|
let mut result = PathBuiltFromString {
|
||||||
|
parts: Vec::with_capacity(path.parts.len()),
|
||||||
|
isdir: path.isdir,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut dot_count = 0;
|
||||||
|
|
||||||
|
for part in path.parts {
|
||||||
|
if part == ".." {
|
||||||
|
dot_count += 1;
|
||||||
|
} else {
|
||||||
|
if dot_count > 0 {
|
||||||
|
result.parts.push(".".repeat(dot_count + 1));
|
||||||
|
dot_count = 0;
|
||||||
|
}
|
||||||
|
result.parts.push(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any remaining dots
|
||||||
|
if dot_count > 0 {
|
||||||
|
result.parts.push(".".repeat(dot_count + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
|
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
|
||||||
use nu_parser::trim_quotes_str;
|
use nu_parser::trim_quotes_str;
|
||||||
use nu_protocol::CompletionAlgorithm;
|
use nu_protocol::{CompletionAlgorithm, CompletionSort};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub enum SortBy {
|
|
||||||
LevenshteinDistance,
|
|
||||||
Ascending,
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Describes how suggestions should be matched.
|
/// Describes how suggestions should be matched.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub enum MatchAlgorithm {
|
pub enum MatchAlgorithm {
|
||||||
/// Only show suggestions which begin with the given input
|
/// Only show suggestions which begin with the given input
|
||||||
///
|
///
|
||||||
@ -96,6 +89,7 @@ pub struct CompletionOptions {
|
|||||||
pub case_sensitive: bool,
|
pub case_sensitive: bool,
|
||||||
pub positional: bool,
|
pub positional: bool,
|
||||||
pub match_algorithm: MatchAlgorithm,
|
pub match_algorithm: MatchAlgorithm,
|
||||||
|
pub sort: CompletionSort,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CompletionOptions {
|
impl Default for CompletionOptions {
|
||||||
@ -104,6 +98,7 @@ impl Default for CompletionOptions {
|
|||||||
case_sensitive: true,
|
case_sensitive: true,
|
||||||
positional: true,
|
positional: true,
|
||||||
match_algorithm: MatchAlgorithm::Prefix,
|
match_algorithm: MatchAlgorithm::Prefix,
|
||||||
|
sort: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
use crate::completions::{
|
use crate::completions::{
|
||||||
completer::map_value_completions, Completer, CompletionOptions, MatchAlgorithm,
|
completer::map_value_completions, Completer, CompletionOptions, MatchAlgorithm,
|
||||||
SemanticSuggestion, SortBy,
|
SemanticSuggestion,
|
||||||
};
|
};
|
||||||
use nu_engine::eval_call;
|
use nu_engine::eval_call;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Argument, Call, Expr, Expression},
|
ast::{Argument, Call, Expr, Expression},
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{Stack, StateWorkingSet},
|
engine::{Stack, StateWorkingSet},
|
||||||
PipelineData, Span, Type, Value,
|
CompletionSort, DeclId, PipelineData, Span, Type, Value,
|
||||||
};
|
};
|
||||||
use nu_utils::IgnoreCaseExt;
|
use nu_utils::IgnoreCaseExt;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use super::completion_common::sort_suggestions;
|
||||||
|
|
||||||
pub struct CustomCompletion {
|
pub struct CustomCompletion {
|
||||||
stack: Stack,
|
stack: Stack,
|
||||||
decl_id: usize,
|
decl_id: DeclId,
|
||||||
line: String,
|
line: String,
|
||||||
sort_by: SortBy,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomCompletion {
|
impl CustomCompletion {
|
||||||
pub fn new(stack: Stack, decl_id: usize, line: String) -> Self {
|
pub fn new(stack: Stack, decl_id: DeclId, line: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stack,
|
stack,
|
||||||
decl_id,
|
decl_id,
|
||||||
line,
|
line,
|
||||||
sort_by: SortBy::None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ impl Completer for CustomCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
_stack: &Stack,
|
_stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
@ -52,18 +52,16 @@ impl Completer for CustomCompletion {
|
|||||||
decl_id: self.decl_id,
|
decl_id: self.decl_id,
|
||||||
head: span,
|
head: span,
|
||||||
arguments: vec![
|
arguments: vec![
|
||||||
Argument::Positional(Expression {
|
Argument::Positional(Expression::new_unknown(
|
||||||
span: Span::unknown(),
|
Expr::String(self.line.clone()),
|
||||||
ty: Type::String,
|
Span::unknown(),
|
||||||
expr: Expr::String(self.line.clone()),
|
Type::String,
|
||||||
custom_completion: None,
|
)),
|
||||||
}),
|
Argument::Positional(Expression::new_unknown(
|
||||||
Argument::Positional(Expression {
|
Expr::Int(line_pos as i64),
|
||||||
span: Span::unknown(),
|
Span::unknown(),
|
||||||
ty: Type::Int,
|
Type::Int,
|
||||||
expr: Expr::Int(line_pos as i64),
|
)),
|
||||||
custom_completion: None,
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
parser_info: HashMap::new(),
|
parser_info: HashMap::new(),
|
||||||
},
|
},
|
||||||
@ -93,10 +91,6 @@ impl Completer for CustomCompletion {
|
|||||||
.and_then(|val| val.as_bool().ok())
|
.and_then(|val| val.as_bool().ok())
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
if should_sort {
|
|
||||||
self.sort_by = SortBy::Ascending;
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_completion_options = Some(CompletionOptions {
|
custom_completion_options = Some(CompletionOptions {
|
||||||
case_sensitive: options
|
case_sensitive: options
|
||||||
.get("case_sensitive")
|
.get("case_sensitive")
|
||||||
@ -114,6 +108,11 @@ impl Completer for CustomCompletion {
|
|||||||
.unwrap_or(MatchAlgorithm::Prefix),
|
.unwrap_or(MatchAlgorithm::Prefix),
|
||||||
None => completion_options.match_algorithm,
|
None => completion_options.match_algorithm,
|
||||||
},
|
},
|
||||||
|
sort: if should_sort {
|
||||||
|
CompletionSort::Alphabetical
|
||||||
|
} else {
|
||||||
|
CompletionSort::Smart
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,15 +123,11 @@ impl Completer for CustomCompletion {
|
|||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if let Some(custom_completion_options) = custom_completion_options {
|
let options = custom_completion_options
|
||||||
filter(&prefix, suggestions, &custom_completion_options)
|
.as_ref()
|
||||||
} else {
|
.unwrap_or(completion_options);
|
||||||
filter(&prefix, suggestions, completion_options)
|
let suggestions = filter(prefix, suggestions, options);
|
||||||
}
|
sort_suggestions(&String::from_utf8_lossy(prefix), suggestions, options)
|
||||||
}
|
|
||||||
|
|
||||||
fn get_sort_by(&self) -> SortBy {
|
|
||||||
self.sort_by
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use crate::completions::{
|
use crate::completions::{
|
||||||
completion_common::{adjust_if_intermediate, complete_item, AdjustView},
|
completion_common::{adjust_if_intermediate, complete_item, AdjustView},
|
||||||
Completer, CompletionOptions, SortBy,
|
Completer, CompletionOptions,
|
||||||
};
|
};
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
levenshtein_distance, Span,
|
Span,
|
||||||
};
|
};
|
||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
use std::path::{Path, MAIN_SEPARATOR as SEP};
|
use std::path::Path;
|
||||||
|
|
||||||
use super::SemanticSuggestion;
|
use super::SemanticSuggestion;
|
||||||
|
|
||||||
@ -26,17 +26,17 @@ impl Completer for DirectoryCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
stack: &Stack,
|
stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_pos: usize,
|
_pos: usize,
|
||||||
options: &CompletionOptions,
|
options: &CompletionOptions,
|
||||||
) -> Vec<SemanticSuggestion> {
|
) -> Vec<SemanticSuggestion> {
|
||||||
let AdjustView { prefix, span, .. } = adjust_if_intermediate(&prefix, working_set, span);
|
let AdjustView { prefix, span, .. } = adjust_if_intermediate(prefix, working_set, span);
|
||||||
|
|
||||||
// Filter only the folders
|
// Filter only the folders
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let output: Vec<_> = directory_completion(
|
let items: Vec<_> = directory_completion(
|
||||||
span,
|
span,
|
||||||
&prefix,
|
&prefix,
|
||||||
&working_set.permanent_state.current_work_dir(),
|
&working_set.permanent_state.current_work_dir(),
|
||||||
@ -48,55 +48,23 @@ impl Completer for DirectoryCompletion {
|
|||||||
.map(move |x| SemanticSuggestion {
|
.map(move |x| SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: x.1,
|
value: x.1,
|
||||||
description: None,
|
|
||||||
style: x.2,
|
style: x.2,
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: x.0.start - offset,
|
start: x.0.start - offset,
|
||||||
end: x.0.end - offset,
|
end: x.0.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO????
|
// TODO????
|
||||||
kind: None,
|
kind: None,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
output
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort results prioritizing the non hidden folders
|
|
||||||
fn sort(&self, items: Vec<SemanticSuggestion>, prefix: Vec<u8>) -> Vec<SemanticSuggestion> {
|
|
||||||
let prefix_str = String::from_utf8_lossy(&prefix).to_string();
|
|
||||||
|
|
||||||
// Sort items
|
|
||||||
let mut sorted_items = items;
|
|
||||||
|
|
||||||
match self.get_sort_by() {
|
|
||||||
SortBy::Ascending => {
|
|
||||||
sorted_items.sort_by(|a, b| {
|
|
||||||
// Ignore trailing slashes in folder names when sorting
|
|
||||||
a.suggestion
|
|
||||||
.value
|
|
||||||
.trim_end_matches(SEP)
|
|
||||||
.cmp(b.suggestion.value.trim_end_matches(SEP))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
SortBy::LevenshteinDistance => {
|
|
||||||
sorted_items.sort_by(|a, b| {
|
|
||||||
let a_distance = levenshtein_distance(&prefix_str, &a.suggestion.value);
|
|
||||||
let b_distance = levenshtein_distance(&prefix_str, &b.suggestion.value);
|
|
||||||
a_distance.cmp(&b_distance)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Separate the results between hidden and non hidden
|
// Separate the results between hidden and non hidden
|
||||||
let mut hidden: Vec<SemanticSuggestion> = vec![];
|
let mut hidden: Vec<SemanticSuggestion> = vec![];
|
||||||
let mut non_hidden: Vec<SemanticSuggestion> = vec![];
|
let mut non_hidden: Vec<SemanticSuggestion> = vec![];
|
||||||
|
|
||||||
for item in sorted_items.into_iter() {
|
for item in items.into_iter() {
|
||||||
let item_path = Path::new(&item.suggestion.value);
|
let item_path = Path::new(&item.suggestion.value);
|
||||||
|
|
||||||
if let Some(value) = item_path.file_name() {
|
if let Some(value) = item_path.file_name() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::completions::{file_path_completion, Completer, CompletionOptions, SortBy};
|
use crate::completions::{file_path_completion, Completer, CompletionOptions};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{Stack, StateWorkingSet},
|
engine::{Stack, StateWorkingSet},
|
||||||
Span,
|
Span,
|
||||||
@ -6,7 +6,7 @@ use nu_protocol::{
|
|||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
use std::path::{is_separator, Path, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR};
|
use std::path::{is_separator, Path, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR};
|
||||||
|
|
||||||
use super::SemanticSuggestion;
|
use super::{completion_common::sort_suggestions, SemanticSuggestion};
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct DotNuCompletion {}
|
pub struct DotNuCompletion {}
|
||||||
@ -22,13 +22,13 @@ impl Completer for DotNuCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
stack: &Stack,
|
stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_pos: usize,
|
_pos: usize,
|
||||||
options: &CompletionOptions,
|
options: &CompletionOptions,
|
||||||
) -> Vec<SemanticSuggestion> {
|
) -> Vec<SemanticSuggestion> {
|
||||||
let prefix_str = String::from_utf8_lossy(&prefix).replace('`', "");
|
let prefix_str = String::from_utf8_lossy(prefix).replace('`', "");
|
||||||
let mut search_dirs: Vec<String> = vec![];
|
let mut search_dirs: Vec<String> = vec![];
|
||||||
|
|
||||||
// If prefix_str is only a word we want to search in the current dir
|
// If prefix_str is only a word we want to search in the current dir
|
||||||
@ -116,14 +116,13 @@ impl Completer for DotNuCompletion {
|
|||||||
.map(move |x| SemanticSuggestion {
|
.map(move |x| SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: x.1,
|
value: x.1,
|
||||||
description: None,
|
|
||||||
style: x.2,
|
style: x.2,
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: x.0.start - offset,
|
start: x.0.start - offset,
|
||||||
end: x.0.end - offset,
|
end: x.0.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO????
|
// TODO????
|
||||||
kind: None,
|
kind: None,
|
||||||
@ -131,10 +130,6 @@ impl Completer for DotNuCompletion {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
output
|
sort_suggestions(&prefix_str, output, options)
|
||||||
}
|
|
||||||
|
|
||||||
fn get_sort_by(&self) -> SortBy {
|
|
||||||
SortBy::LevenshteinDistance
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
use crate::completions::{
|
use crate::completions::{
|
||||||
completion_common::{adjust_if_intermediate, complete_item, AdjustView},
|
completion_common::{adjust_if_intermediate, complete_item, AdjustView},
|
||||||
Completer, CompletionOptions, SortBy,
|
Completer, CompletionOptions,
|
||||||
};
|
};
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
levenshtein_distance, Span,
|
Span,
|
||||||
};
|
};
|
||||||
use nu_utils::IgnoreCaseExt;
|
use nu_utils::IgnoreCaseExt;
|
||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
use std::path::{Path, MAIN_SEPARATOR as SEP};
|
use std::path::Path;
|
||||||
|
|
||||||
use super::SemanticSuggestion;
|
use super::SemanticSuggestion;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ impl Completer for FileCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
stack: &Stack,
|
stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_pos: usize,
|
_pos: usize,
|
||||||
@ -37,10 +37,10 @@ impl Completer for FileCompletion {
|
|||||||
prefix,
|
prefix,
|
||||||
span,
|
span,
|
||||||
readjusted,
|
readjusted,
|
||||||
} = adjust_if_intermediate(&prefix, working_set, span);
|
} = adjust_if_intermediate(prefix, working_set, span);
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let output: Vec<_> = complete_item(
|
let items: Vec<_> = complete_item(
|
||||||
readjusted,
|
readjusted,
|
||||||
span,
|
span,
|
||||||
&prefix,
|
&prefix,
|
||||||
@ -53,55 +53,25 @@ impl Completer for FileCompletion {
|
|||||||
.map(move |x| SemanticSuggestion {
|
.map(move |x| SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: x.1,
|
value: x.1,
|
||||||
description: None,
|
|
||||||
style: x.2,
|
style: x.2,
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: x.0.start - offset,
|
start: x.0.start - offset,
|
||||||
end: x.0.end - offset,
|
end: x.0.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO????
|
// TODO????
|
||||||
kind: None,
|
kind: None,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
output
|
// Sort results prioritizing the non hidden folders
|
||||||
}
|
|
||||||
|
|
||||||
// Sort results prioritizing the non hidden folders
|
|
||||||
fn sort(&self, items: Vec<SemanticSuggestion>, prefix: Vec<u8>) -> Vec<SemanticSuggestion> {
|
|
||||||
let prefix_str = String::from_utf8_lossy(&prefix).to_string();
|
|
||||||
|
|
||||||
// Sort items
|
|
||||||
let mut sorted_items = items;
|
|
||||||
|
|
||||||
match self.get_sort_by() {
|
|
||||||
SortBy::Ascending => {
|
|
||||||
sorted_items.sort_by(|a, b| {
|
|
||||||
// Ignore trailing slashes in folder names when sorting
|
|
||||||
a.suggestion
|
|
||||||
.value
|
|
||||||
.trim_end_matches(SEP)
|
|
||||||
.cmp(b.suggestion.value.trim_end_matches(SEP))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
SortBy::LevenshteinDistance => {
|
|
||||||
sorted_items.sort_by(|a, b| {
|
|
||||||
let a_distance = levenshtein_distance(&prefix_str, &a.suggestion.value);
|
|
||||||
let b_distance = levenshtein_distance(&prefix_str, &b.suggestion.value);
|
|
||||||
a_distance.cmp(&b_distance)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Separate the results between hidden and non hidden
|
// Separate the results between hidden and non hidden
|
||||||
let mut hidden: Vec<SemanticSuggestion> = vec![];
|
let mut hidden: Vec<SemanticSuggestion> = vec![];
|
||||||
let mut non_hidden: Vec<SemanticSuggestion> = vec![];
|
let mut non_hidden: Vec<SemanticSuggestion> = vec![];
|
||||||
|
|
||||||
for item in sorted_items.into_iter() {
|
for item in items.into_iter() {
|
||||||
let item_path = Path::new(&item.suggestion.value);
|
let item_path = Path::new(&item.suggestion.value);
|
||||||
|
|
||||||
if let Some(value) = item_path.file_name() {
|
if let Some(value) = item_path.file_name() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::completions::{Completer, CompletionOptions};
|
use crate::completions::{completion_common::sort_suggestions, Completer, CompletionOptions};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Expr, Expression},
|
ast::{Expr, Expression},
|
||||||
engine::{Stack, StateWorkingSet},
|
engine::{Stack, StateWorkingSet},
|
||||||
@ -24,7 +24,7 @@ impl Completer for FlagCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
_stack: &Stack,
|
_stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_pos: usize,
|
_pos: usize,
|
||||||
@ -44,18 +44,17 @@ impl Completer for FlagCompletion {
|
|||||||
short.encode_utf8(&mut named);
|
short.encode_utf8(&mut named);
|
||||||
named.insert(0, b'-');
|
named.insert(0, b'-');
|
||||||
|
|
||||||
if options.match_algorithm.matches_u8(&named, &prefix) {
|
if options.match_algorithm.matches_u8(&named, prefix) {
|
||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: String::from_utf8_lossy(&named).to_string(),
|
value: String::from_utf8_lossy(&named).to_string(),
|
||||||
description: Some(flag_desc.to_string()),
|
description: Some(flag_desc.to_string()),
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: span.start - offset,
|
start: span.start - offset,
|
||||||
end: span.end - offset,
|
end: span.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO????
|
// TODO????
|
||||||
kind: None,
|
kind: None,
|
||||||
@ -71,18 +70,17 @@ impl Completer for FlagCompletion {
|
|||||||
named.insert(0, b'-');
|
named.insert(0, b'-');
|
||||||
named.insert(0, b'-');
|
named.insert(0, b'-');
|
||||||
|
|
||||||
if options.match_algorithm.matches_u8(&named, &prefix) {
|
if options.match_algorithm.matches_u8(&named, prefix) {
|
||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: String::from_utf8_lossy(&named).to_string(),
|
value: String::from_utf8_lossy(&named).to_string(),
|
||||||
description: Some(flag_desc.to_string()),
|
description: Some(flag_desc.to_string()),
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: span.start - offset,
|
start: span.start - offset,
|
||||||
end: span.end - offset,
|
end: span.end - offset,
|
||||||
},
|
},
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO????
|
// TODO????
|
||||||
kind: None,
|
kind: None,
|
||||||
@ -90,7 +88,7 @@ impl Completer for FlagCompletion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return sort_suggestions(&String::from_utf8_lossy(prefix), output, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec![]
|
vec![]
|
||||||
|
@ -8,15 +8,17 @@ mod directory_completions;
|
|||||||
mod dotnu_completions;
|
mod dotnu_completions;
|
||||||
mod file_completions;
|
mod file_completions;
|
||||||
mod flag_completions;
|
mod flag_completions;
|
||||||
|
mod operator_completions;
|
||||||
mod variable_completions;
|
mod variable_completions;
|
||||||
|
|
||||||
pub use base::{Completer, SemanticSuggestion, SuggestionKind};
|
pub use base::{Completer, SemanticSuggestion, SuggestionKind};
|
||||||
pub use command_completions::CommandCompletion;
|
pub use command_completions::CommandCompletion;
|
||||||
pub use completer::NuCompleter;
|
pub use completer::NuCompleter;
|
||||||
pub use completion_options::{CompletionOptions, MatchAlgorithm, SortBy};
|
pub use completion_options::{CompletionOptions, MatchAlgorithm};
|
||||||
pub use custom_completions::CustomCompletion;
|
pub use custom_completions::CustomCompletion;
|
||||||
pub use directory_completions::DirectoryCompletion;
|
pub use directory_completions::DirectoryCompletion;
|
||||||
pub use dotnu_completions::DotNuCompletion;
|
pub use dotnu_completions::DotNuCompletion;
|
||||||
pub use file_completions::{file_path_completion, matches, FileCompletion};
|
pub use file_completions::{file_path_completion, matches, FileCompletion};
|
||||||
pub use flag_completions::FlagCompletion;
|
pub use flag_completions::FlagCompletion;
|
||||||
|
pub use operator_completions::OperatorCompletion;
|
||||||
pub use variable_completions::VariableCompletion;
|
pub use variable_completions::VariableCompletion;
|
||||||
|
182
crates/nu-cli/src/completions/operator_completions.rs
Normal file
182
crates/nu-cli/src/completions/operator_completions.rs
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
use crate::completions::{
|
||||||
|
Completer, CompletionOptions, MatchAlgorithm, SemanticSuggestion, SuggestionKind,
|
||||||
|
};
|
||||||
|
use nu_protocol::{
|
||||||
|
ast::{Expr, Expression},
|
||||||
|
engine::{Stack, StateWorkingSet},
|
||||||
|
Span, Type,
|
||||||
|
};
|
||||||
|
use reedline::Suggestion;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct OperatorCompletion {
|
||||||
|
previous_expr: Expression,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OperatorCompletion {
|
||||||
|
pub fn new(previous_expr: Expression) -> Self {
|
||||||
|
OperatorCompletion { previous_expr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Completer for OperatorCompletion {
|
||||||
|
fn fetch(
|
||||||
|
&mut self,
|
||||||
|
working_set: &StateWorkingSet,
|
||||||
|
_stack: &Stack,
|
||||||
|
_prefix: &[u8],
|
||||||
|
span: Span,
|
||||||
|
offset: usize,
|
||||||
|
_pos: usize,
|
||||||
|
_options: &CompletionOptions,
|
||||||
|
) -> Vec<SemanticSuggestion> {
|
||||||
|
//Check if int, float, or string
|
||||||
|
let partial = std::str::from_utf8(working_set.get_span_contents(span)).unwrap_or("");
|
||||||
|
let op = match &self.previous_expr.expr {
|
||||||
|
Expr::BinaryOp(x, _, _) => &x.expr,
|
||||||
|
_ => {
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let possible_operations = match op {
|
||||||
|
Expr::Int(_) => vec![
|
||||||
|
("+", "Add (Plus)"),
|
||||||
|
("-", "Subtract (Minus)"),
|
||||||
|
("*", "Multiply"),
|
||||||
|
("/", "Divide"),
|
||||||
|
("==", "Equal to"),
|
||||||
|
("!=", "Not equal to"),
|
||||||
|
("//", "Floor division"),
|
||||||
|
("<", "Less than"),
|
||||||
|
(">", "Greater than"),
|
||||||
|
("<=", "Less than or equal to"),
|
||||||
|
(">=", "Greater than or equal to"),
|
||||||
|
("mod", "Floor division remainder (Modulo)"),
|
||||||
|
("**", "Power of"),
|
||||||
|
("bit-or", "Bitwise OR"),
|
||||||
|
("bit-xor", "Bitwise exclusive OR"),
|
||||||
|
("bit-and", "Bitwise AND"),
|
||||||
|
("bit-shl", "Bitwise shift left"),
|
||||||
|
("bit-shr", "Bitwise shift right"),
|
||||||
|
("in", "Is a member of (doesn't use regex)"),
|
||||||
|
("not-in", "Is not a member of (doesn't use regex)"),
|
||||||
|
(
|
||||||
|
"++",
|
||||||
|
"Appends two lists, a list and a value, two strings, or two binary values",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
Expr::String(_) => vec![
|
||||||
|
("=~", "Contains regex match"),
|
||||||
|
("like", "Contains regex match"),
|
||||||
|
("!~", "Does not contain regex match"),
|
||||||
|
("not-like", "Does not contain regex match"),
|
||||||
|
(
|
||||||
|
"++",
|
||||||
|
"Appends two lists, a list and a value, two strings, or two binary values",
|
||||||
|
),
|
||||||
|
("in", "Is a member of (doesn't use regex)"),
|
||||||
|
("not-in", "Is not a member of (doesn't use regex)"),
|
||||||
|
("starts-with", "Starts with"),
|
||||||
|
("ends-with", "Ends with"),
|
||||||
|
],
|
||||||
|
Expr::Float(_) => vec![
|
||||||
|
("+", "Add (Plus)"),
|
||||||
|
("-", "Subtract (Minus)"),
|
||||||
|
("*", "Multiply"),
|
||||||
|
("/", "Divide"),
|
||||||
|
("==", "Equal to"),
|
||||||
|
("!=", "Not equal to"),
|
||||||
|
("//", "Floor division"),
|
||||||
|
("<", "Less than"),
|
||||||
|
(">", "Greater than"),
|
||||||
|
("<=", "Less than or equal to"),
|
||||||
|
(">=", "Greater than or equal to"),
|
||||||
|
("mod", "Floor division remainder (Modulo)"),
|
||||||
|
("**", "Power of"),
|
||||||
|
("in", "Is a member of (doesn't use regex)"),
|
||||||
|
("not-in", "Is not a member of (doesn't use regex)"),
|
||||||
|
(
|
||||||
|
"++",
|
||||||
|
"Appends two lists, a list and a value, two strings, or two binary values",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
Expr::Bool(_) => vec![
|
||||||
|
(
|
||||||
|
"and",
|
||||||
|
"Both values are true (short-circuits when first value is false)",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"or",
|
||||||
|
"Either value is true (short-circuits when first value is true)",
|
||||||
|
),
|
||||||
|
("xor", "One value is true and the other is false"),
|
||||||
|
("not", "Negates a value or expression"),
|
||||||
|
("in", "Is a member of (doesn't use regex)"),
|
||||||
|
("not-in", "Is not a member of (doesn't use regex)"),
|
||||||
|
(
|
||||||
|
"++",
|
||||||
|
"Appends two lists, a list and a value, two strings, or two binary values",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
Expr::FullCellPath(path) => match path.head.expr {
|
||||||
|
Expr::List(_) => vec![(
|
||||||
|
"++",
|
||||||
|
"Appends two lists, a list and a value, two strings, or two binary values",
|
||||||
|
)],
|
||||||
|
Expr::Var(id) => get_variable_completions(id, working_set),
|
||||||
|
_ => vec![],
|
||||||
|
},
|
||||||
|
_ => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
let match_algorithm = MatchAlgorithm::Prefix;
|
||||||
|
let input_fuzzy_search =
|
||||||
|
|(operator, _): &(&str, &str)| match_algorithm.matches_str(operator, partial);
|
||||||
|
|
||||||
|
possible_operations
|
||||||
|
.into_iter()
|
||||||
|
.filter(input_fuzzy_search)
|
||||||
|
.map(move |x| SemanticSuggestion {
|
||||||
|
suggestion: Suggestion {
|
||||||
|
value: x.0.to_string(),
|
||||||
|
description: Some(x.1.to_string()),
|
||||||
|
span: reedline::Span::new(span.start - offset, span.end - offset),
|
||||||
|
append_whitespace: true,
|
||||||
|
..Suggestion::default()
|
||||||
|
},
|
||||||
|
kind: Some(SuggestionKind::Command(
|
||||||
|
nu_protocol::engine::CommandType::Builtin,
|
||||||
|
)),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_variable_completions<'a>(
|
||||||
|
id: nu_protocol::Id<nu_protocol::marker::Var>,
|
||||||
|
working_set: &StateWorkingSet,
|
||||||
|
) -> Vec<(&'a str, &'a str)> {
|
||||||
|
let var = working_set.get_variable(id);
|
||||||
|
if !var.mutable {
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
|
||||||
|
match var.ty {
|
||||||
|
Type::List(_) | Type::String | Type::Binary => vec![
|
||||||
|
(
|
||||||
|
"++=",
|
||||||
|
"Appends a list, a value, a string, or a binary value to a variable.",
|
||||||
|
),
|
||||||
|
("=", "Assigns a value to a variable."),
|
||||||
|
],
|
||||||
|
|
||||||
|
Type::Int | Type::Float => vec![
|
||||||
|
("=", "Assigns a value to a variable."),
|
||||||
|
("+=", "Adds a value to a variable."),
|
||||||
|
("-=", "Subtracts a value from a variable."),
|
||||||
|
("*=", "Multiplies a variable by a value"),
|
||||||
|
("/=", "Divides a variable by a value."),
|
||||||
|
],
|
||||||
|
_ => vec![],
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,8 @@ use nu_protocol::{
|
|||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
|
use super::completion_common::sort_suggestions;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct VariableCompletion {
|
pub struct VariableCompletion {
|
||||||
var_context: (Vec<u8>, Vec<Vec<u8>>), // tuple with $var and the sublevels (.b.c.d)
|
var_context: (Vec<u8>, Vec<Vec<u8>>), // tuple with $var and the sublevels (.b.c.d)
|
||||||
@ -25,7 +27,7 @@ impl Completer for VariableCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
stack: &Stack,
|
stack: &Stack,
|
||||||
prefix: Vec<u8>,
|
prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_pos: usize,
|
_pos: usize,
|
||||||
@ -40,6 +42,7 @@ impl Completer for VariableCompletion {
|
|||||||
end: span.end - offset,
|
end: span.end - offset,
|
||||||
};
|
};
|
||||||
let sublevels_count = self.var_context.1.len();
|
let sublevels_count = self.var_context.1.len();
|
||||||
|
let prefix_str = String::from_utf8_lossy(prefix);
|
||||||
|
|
||||||
// Completions for the given variable
|
// Completions for the given variable
|
||||||
if !var_str.is_empty() {
|
if !var_str.is_empty() {
|
||||||
@ -63,13 +66,13 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
suggestion.suggestion.value.as_bytes(),
|
suggestion.suggestion.value.as_bytes(),
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(suggestion);
|
output.push(suggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return sort_suggestions(&prefix_str, output, options);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No nesting provided, return all env vars
|
// No nesting provided, return all env vars
|
||||||
@ -77,23 +80,20 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
env_var.0.as_bytes(),
|
env_var.0.as_bytes(),
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: env_var.0,
|
value: env_var.0,
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: current_span,
|
span: current_span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(SuggestionKind::Type(env_var.1.get_type())),
|
kind: Some(SuggestionKind::Type(env_var.1.get_type())),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return sort_suggestions(&prefix_str, output, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,13 +111,13 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
suggestion.suggestion.value.as_bytes(),
|
suggestion.suggestion.value.as_bytes(),
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(suggestion);
|
output.push(suggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return sort_suggestions(&prefix_str, output, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,13 +133,13 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
suggestion.suggestion.value.as_bytes(),
|
suggestion.suggestion.value.as_bytes(),
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(suggestion);
|
output.push(suggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return sort_suggestions(&prefix_str, output, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,16 +149,13 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
builtin.as_bytes(),
|
builtin.as_bytes(),
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: builtin.to_string(),
|
value: builtin.to_string(),
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: current_span,
|
span: current_span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
// TODO is there a way to get the VarId to get the type???
|
// TODO is there a way to get the VarId to get the type???
|
||||||
kind: None,
|
kind: None,
|
||||||
@ -176,16 +173,13 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
v.0,
|
v.0,
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: String::from_utf8_lossy(v.0).to_string(),
|
value: String::from_utf8_lossy(v.0).to_string(),
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: current_span,
|
span: current_span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(SuggestionKind::Type(
|
kind: Some(SuggestionKind::Type(
|
||||||
working_set.get_variable(*v.1).ty.clone(),
|
working_set.get_variable(*v.1).ty.clone(),
|
||||||
@ -207,16 +201,13 @@ impl Completer for VariableCompletion {
|
|||||||
if options.match_algorithm.matches_u8_insensitive(
|
if options.match_algorithm.matches_u8_insensitive(
|
||||||
options.case_sensitive,
|
options.case_sensitive,
|
||||||
v.0,
|
v.0,
|
||||||
&prefix,
|
prefix,
|
||||||
) {
|
) {
|
||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: String::from_utf8_lossy(v.0).to_string(),
|
value: String::from_utf8_lossy(v.0).to_string(),
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: current_span,
|
span: current_span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(SuggestionKind::Type(
|
kind: Some(SuggestionKind::Type(
|
||||||
working_set.get_variable(*v.1).ty.clone(),
|
working_set.get_variable(*v.1).ty.clone(),
|
||||||
@ -226,6 +217,8 @@ impl Completer for VariableCompletion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output = sort_suggestions(&prefix_str, output, options);
|
||||||
|
|
||||||
output.dedup(); // TODO: Removes only consecutive duplicates, is it intended?
|
output.dedup(); // TODO: Removes only consecutive duplicates, is it intended?
|
||||||
|
|
||||||
output
|
output
|
||||||
@ -250,11 +243,8 @@ fn nested_suggestions(
|
|||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: col.clone(),
|
value: col.clone(),
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: current_span,
|
span: current_span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(kind.clone()),
|
kind: Some(kind.clone()),
|
||||||
});
|
});
|
||||||
@ -267,11 +257,8 @@ fn nested_suggestions(
|
|||||||
output.push(SemanticSuggestion {
|
output.push(SemanticSuggestion {
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: column_name,
|
value: column_name,
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: current_span,
|
span: current_span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
},
|
},
|
||||||
kind: Some(kind.clone()),
|
kind: Some(kind.clone()),
|
||||||
});
|
});
|
||||||
|
@ -2,13 +2,13 @@ use crate::util::eval_source;
|
|||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::canonicalize_with;
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
use nu_protocol::{engine::StateWorkingSet, report_error, ParseError, PluginRegistryFile, Spanned};
|
use nu_protocol::{engine::StateWorkingSet, ParseError, PluginRegistryFile, Spanned};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
report_error_new, HistoryFileFormat, PipelineData,
|
report_shell_error, PipelineData,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
use nu_utils::utils::perf;
|
use nu_utils::perf;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
@ -16,15 +16,8 @@ const PLUGIN_FILE: &str = "plugin.msgpackz";
|
|||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
const OLD_PLUGIN_FILE: &str = "plugin.nu";
|
const OLD_PLUGIN_FILE: &str = "plugin.nu";
|
||||||
|
|
||||||
const HISTORY_FILE_TXT: &str = "history.txt";
|
|
||||||
const HISTORY_FILE_SQLITE: &str = "history.sqlite3";
|
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
pub fn read_plugin_file(
|
pub fn read_plugin_file(engine_state: &mut EngineState, plugin_file: Option<Spanned<String>>) {
|
||||||
engine_state: &mut EngineState,
|
|
||||||
plugin_file: Option<Spanned<String>>,
|
|
||||||
storage_path: &str,
|
|
||||||
) {
|
|
||||||
use nu_protocol::ShellError;
|
use nu_protocol::ShellError;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
@ -36,7 +29,7 @@ pub fn read_plugin_file(
|
|||||||
.and_then(|p| Path::new(&p.item).extension())
|
.and_then(|p| Path::new(&p.item).extension())
|
||||||
.is_some_and(|ext| ext == "nu")
|
.is_some_and(|ext| ext == "nu")
|
||||||
{
|
{
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
engine_state,
|
engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: "Wrong plugin file format".into(),
|
error: "Wrong plugin file format".into(),
|
||||||
@ -52,14 +45,11 @@ pub fn read_plugin_file(
|
|||||||
let mut start_time = std::time::Instant::now();
|
let mut start_time = std::time::Instant::now();
|
||||||
// Reading signatures from plugin registry file
|
// Reading signatures from plugin registry file
|
||||||
// The plugin.msgpackz file stores the parsed signature collected from each registered plugin
|
// The plugin.msgpackz file stores the parsed signature collected from each registered plugin
|
||||||
add_plugin_file(engine_state, plugin_file.clone(), storage_path);
|
add_plugin_file(engine_state, plugin_file.clone());
|
||||||
perf(
|
perf!(
|
||||||
"add plugin file to engine_state",
|
"add plugin file to engine_state",
|
||||||
start_time,
|
start_time,
|
||||||
file!(),
|
engine_state.get_config().use_ansi_coloring
|
||||||
line!(),
|
|
||||||
column!(),
|
|
||||||
engine_state.get_config().use_ansi_coloring,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
start_time = std::time::Instant::now();
|
start_time = std::time::Instant::now();
|
||||||
@ -73,8 +63,7 @@ pub fn read_plugin_file(
|
|||||||
log::warn!("Plugin file not found: {}", plugin_path.display());
|
log::warn!("Plugin file not found: {}", plugin_path.display());
|
||||||
|
|
||||||
// Try migration of an old plugin file if this wasn't a custom plugin file
|
// Try migration of an old plugin file if this wasn't a custom plugin file
|
||||||
if plugin_file.is_none() && migrate_old_plugin_file(engine_state, storage_path)
|
if plugin_file.is_none() && migrate_old_plugin_file(engine_state) {
|
||||||
{
|
|
||||||
let Ok(file) = std::fs::File::open(&plugin_path) else {
|
let Ok(file) = std::fs::File::open(&plugin_path) else {
|
||||||
log::warn!("Failed to load newly migrated plugin file");
|
log::warn!("Failed to load newly migrated plugin file");
|
||||||
return;
|
return;
|
||||||
@ -84,7 +73,7 @@ pub fn read_plugin_file(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
engine_state,
|
engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: format!(
|
error: format!(
|
||||||
@ -116,7 +105,7 @@ pub fn read_plugin_file(
|
|||||||
Ok(contents) => contents,
|
Ok(contents) => contents,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!("Failed to read plugin registry file: {err:?}");
|
log::warn!("Failed to read plugin registry file: {err:?}");
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
engine_state,
|
engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: format!(
|
error: format!(
|
||||||
@ -137,13 +126,10 @@ pub fn read_plugin_file(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
perf(
|
perf!(
|
||||||
&format!("read plugin file {}", plugin_path.display()),
|
&format!("read plugin file {}", plugin_path.display()),
|
||||||
start_time,
|
start_time,
|
||||||
file!(),
|
engine_state.get_config().use_ansi_coloring
|
||||||
line!(),
|
|
||||||
column!(),
|
|
||||||
engine_state.get_config().use_ansi_coloring,
|
|
||||||
);
|
);
|
||||||
start_time = std::time::Instant::now();
|
start_time = std::time::Instant::now();
|
||||||
|
|
||||||
@ -152,30 +138,23 @@ pub fn read_plugin_file(
|
|||||||
nu_plugin_engine::load_plugin_file(&mut working_set, &contents, span);
|
nu_plugin_engine::load_plugin_file(&mut working_set, &contents, span);
|
||||||
|
|
||||||
if let Err(err) = engine_state.merge_delta(working_set.render()) {
|
if let Err(err) = engine_state.merge_delta(working_set.render()) {
|
||||||
report_error_new(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
perf(
|
perf!(
|
||||||
&format!("load plugin file {}", plugin_path.display()),
|
&format!("load plugin file {}", plugin_path.display()),
|
||||||
start_time,
|
start_time,
|
||||||
file!(),
|
engine_state.get_config().use_ansi_coloring
|
||||||
line!(),
|
|
||||||
column!(),
|
|
||||||
engine_state.get_config().use_ansi_coloring,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
pub fn add_plugin_file(
|
pub fn add_plugin_file(engine_state: &mut EngineState, plugin_file: Option<Spanned<String>>) {
|
||||||
engine_state: &mut EngineState,
|
|
||||||
plugin_file: Option<Spanned<String>>,
|
|
||||||
storage_path: &str,
|
|
||||||
) {
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
use nu_protocol::report_parse_error;
|
||||||
|
|
||||||
if let Ok(cwd) = engine_state.cwd_as_string(None) {
|
if let Ok(cwd) = engine_state.cwd_as_string(None) {
|
||||||
if let Some(plugin_file) = plugin_file {
|
if let Some(plugin_file) = plugin_file {
|
||||||
@ -190,18 +169,18 @@ pub fn add_plugin_file(
|
|||||||
engine_state.plugin_path = Some(path)
|
engine_state.plugin_path = Some(path)
|
||||||
} else {
|
} else {
|
||||||
// It's an error if the directory for the plugin file doesn't exist.
|
// It's an error if the directory for the plugin file doesn't exist.
|
||||||
report_error(
|
report_parse_error(
|
||||||
&working_set,
|
&StateWorkingSet::new(engine_state),
|
||||||
&ParseError::FileNotFound(
|
&ParseError::FileNotFound(
|
||||||
path_dir.to_string_lossy().into_owned(),
|
path_dir.to_string_lossy().into_owned(),
|
||||||
plugin_file.span,
|
plugin_file.span,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if let Some(mut plugin_path) = nu_path::config_dir() {
|
} else if let Some(plugin_path) = nu_path::nu_config_dir() {
|
||||||
// Path to store plugins signatures
|
// Path to store plugins signatures
|
||||||
plugin_path.push(storage_path);
|
let mut plugin_path =
|
||||||
let mut plugin_path = canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path);
|
canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path.into());
|
||||||
plugin_path.push(PLUGIN_FILE);
|
plugin_path.push(PLUGIN_FILE);
|
||||||
let plugin_path = canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path);
|
let plugin_path = canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path);
|
||||||
engine_state.plugin_path = Some(plugin_path);
|
engine_state.plugin_path = Some(plugin_path);
|
||||||
@ -222,7 +201,8 @@ pub fn eval_config_contents(
|
|||||||
let prev_file = engine_state.file.take();
|
let prev_file = engine_state.file.take();
|
||||||
engine_state.file = Some(config_path.clone());
|
engine_state.file = Some(config_path.clone());
|
||||||
|
|
||||||
eval_source(
|
// TODO: ignore this error?
|
||||||
|
let _ = eval_source(
|
||||||
engine_state,
|
engine_state,
|
||||||
stack,
|
stack,
|
||||||
&contents,
|
&contents,
|
||||||
@ -235,33 +215,15 @@ pub fn eval_config_contents(
|
|||||||
engine_state.file = prev_file;
|
engine_state.file = prev_file;
|
||||||
|
|
||||||
// Merge the environment in case env vars changed in the config
|
// Merge the environment in case env vars changed in the config
|
||||||
match engine_state.cwd(Some(stack)) {
|
if let Err(e) = engine_state.merge_env(stack) {
|
||||||
Ok(cwd) => {
|
report_shell_error(engine_state, &e);
|
||||||
if let Err(e) = engine_state.merge_env(stack, cwd) {
|
|
||||||
report_error_new(engine_state, &e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
report_error_new(engine_state, &e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_history_path(storage_path: &str, mode: HistoryFileFormat) -> Option<PathBuf> {
|
|
||||||
nu_path::config_dir().map(|mut history_path| {
|
|
||||||
history_path.push(storage_path);
|
|
||||||
history_path.push(match mode {
|
|
||||||
HistoryFileFormat::PlainText => HISTORY_FILE_TXT,
|
|
||||||
HistoryFileFormat::Sqlite => HISTORY_FILE_SQLITE,
|
|
||||||
});
|
|
||||||
history_path
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -> bool {
|
pub fn migrate_old_plugin_file(engine_state: &EngineState) -> bool {
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
PluginExample, PluginIdentity, PluginRegistryItem, PluginRegistryItemData, PluginSignature,
|
PluginExample, PluginIdentity, PluginRegistryItem, PluginRegistryItemData, PluginSignature,
|
||||||
ShellError,
|
ShellError,
|
||||||
@ -274,10 +236,9 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(config_dir) = nu_path::config_dir().and_then(|mut dir| {
|
let Some(config_dir) =
|
||||||
dir.push(storage_path);
|
nu_path::nu_config_dir().and_then(|dir| nu_path::canonicalize_with(dir, &cwd).ok())
|
||||||
nu_path::canonicalize_with(dir, &cwd).ok()
|
else {
|
||||||
}) else {
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -288,7 +249,7 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
|
|||||||
let old_contents = match std::fs::read(&old_plugin_file_path) {
|
let old_contents = match std::fs::read(&old_plugin_file_path) {
|
||||||
Ok(old_contents) => old_contents,
|
Ok(old_contents) => old_contents,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
engine_state,
|
engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: "Can't read old plugin file to migrate".into(),
|
error: "Can't read old plugin file to migrate".into(),
|
||||||
@ -344,7 +305,10 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
|
|||||||
name: identity.name().to_owned(),
|
name: identity.name().to_owned(),
|
||||||
filename: identity.filename().to_owned(),
|
filename: identity.filename().to_owned(),
|
||||||
shell: identity.shell().map(|p| p.to_owned()),
|
shell: identity.shell().map(|p| p.to_owned()),
|
||||||
data: PluginRegistryItemData::Valid { commands },
|
data: PluginRegistryItemData::Valid {
|
||||||
|
metadata: Default::default(),
|
||||||
|
commands,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +318,7 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
|
|||||||
.map_err(|e| e.into())
|
.map_err(|e| e.into())
|
||||||
.and_then(|file| contents.write_to(file, None))
|
.and_then(|file| contents.write_to(file, None))
|
||||||
{
|
{
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
&engine_state,
|
&engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: "Failed to save migrated plugin file".into(),
|
error: "Failed to save migrated plugin file".into(),
|
||||||
@ -378,13 +342,10 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
perf(
|
perf!(
|
||||||
"migrate old plugin file",
|
"migrate old plugin file",
|
||||||
start_time,
|
start_time,
|
||||||
file!(),
|
engine_state.get_config().use_ansi_coloring
|
||||||
line!(),
|
|
||||||
column!(),
|
|
||||||
engine_state.get_config().use_ansi_coloring,
|
|
||||||
);
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -2,44 +2,79 @@ use log::info;
|
|||||||
use nu_engine::{convert_env_values, eval_block};
|
use nu_engine::{convert_env_values, eval_block};
|
||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
|
cli_error::report_compile_error,
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
report_error, PipelineData, ShellError, Spanned, Value,
|
report_parse_error, report_parse_warning, PipelineData, ShellError, Spanned, Value,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct EvaluateCommandsOpts {
|
||||||
|
pub table_mode: Option<Value>,
|
||||||
|
pub error_style: Option<Value>,
|
||||||
|
pub no_newline: bool,
|
||||||
|
}
|
||||||
|
|
||||||
/// Run a command (or commands) given to us by the user
|
/// Run a command (or commands) given to us by the user
|
||||||
pub fn evaluate_commands(
|
pub fn evaluate_commands(
|
||||||
commands: &Spanned<String>,
|
commands: &Spanned<String>,
|
||||||
engine_state: &mut EngineState,
|
engine_state: &mut EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
table_mode: Option<Value>,
|
opts: EvaluateCommandsOpts,
|
||||||
no_newline: bool,
|
|
||||||
) -> Result<(), ShellError> {
|
) -> Result<(), ShellError> {
|
||||||
|
let EvaluateCommandsOpts {
|
||||||
|
table_mode,
|
||||||
|
error_style,
|
||||||
|
no_newline,
|
||||||
|
} = opts;
|
||||||
|
|
||||||
|
// Handle the configured error style early
|
||||||
|
if let Some(e_style) = error_style {
|
||||||
|
match e_style.coerce_str()?.parse() {
|
||||||
|
Ok(e_style) => {
|
||||||
|
Arc::make_mut(&mut engine_state.config).error_style = e_style;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(ShellError::GenericError {
|
||||||
|
error: "Invalid value for `--error-style`".into(),
|
||||||
|
msg: err.into(),
|
||||||
|
span: Some(e_style.span()),
|
||||||
|
help: None,
|
||||||
|
inner: vec![],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Translate environment variables from Strings to Values
|
// Translate environment variables from Strings to Values
|
||||||
convert_env_values(engine_state, stack)?;
|
convert_env_values(engine_state, stack)?;
|
||||||
|
|
||||||
// Parse the source code
|
// Parse the source code
|
||||||
let (block, delta) = {
|
let (block, delta) = {
|
||||||
if let Some(ref t_mode) = table_mode {
|
if let Some(ref t_mode) = table_mode {
|
||||||
let mut config = engine_state.get_config().clone();
|
Arc::make_mut(&mut engine_state.config).table.mode =
|
||||||
config.table_mode = t_mode.coerce_str()?.parse().unwrap_or_default();
|
t_mode.coerce_str()?.parse().unwrap_or_default();
|
||||||
engine_state.set_config(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut working_set = StateWorkingSet::new(engine_state);
|
let mut working_set = StateWorkingSet::new(engine_state);
|
||||||
|
|
||||||
let output = parse(&mut working_set, None, commands.item.as_bytes(), false);
|
let output = parse(&mut working_set, None, commands.item.as_bytes(), false);
|
||||||
if let Some(warning) = working_set.parse_warnings.first() {
|
if let Some(warning) = working_set.parse_warnings.first() {
|
||||||
report_error(&working_set, warning);
|
report_parse_warning(&working_set, warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(err) = working_set.parse_errors.first() {
|
if let Some(err) = working_set.parse_errors.first() {
|
||||||
report_error(&working_set, err);
|
report_parse_error(&working_set, err);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(err) = working_set.compile_errors.first() {
|
||||||
|
report_compile_error(&working_set, err);
|
||||||
|
// Not a fatal error, for now
|
||||||
|
}
|
||||||
|
|
||||||
(output, working_set.render())
|
(output, working_set.render())
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,15 +89,11 @@ pub fn evaluate_commands(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(t_mode) = table_mode {
|
if let Some(t_mode) = table_mode {
|
||||||
Arc::make_mut(&mut engine_state.config).table_mode =
|
Arc::make_mut(&mut engine_state.config).table.mode =
|
||||||
t_mode.coerce_str()?.parse().unwrap_or_default();
|
t_mode.coerce_str()?.parse().unwrap_or_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(status) = pipeline.print(engine_state, stack, no_newline, false)? {
|
pipeline.print(engine_state, stack, no_newline, false)?;
|
||||||
if status.code() != 0 {
|
|
||||||
std::process::exit(status.code())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("evaluate {}:{}:{}", file!(), line!(), column!());
|
info!("evaluate {}:{}:{}", file!(), line!(), column!());
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ use nu_engine::{convert_env_values, eval_block};
|
|||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::canonicalize_with;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
|
cli_error::report_compile_error,
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
report_error, PipelineData, ShellError, Span, Value,
|
report_parse_error, report_parse_warning, PipelineData, ShellError, Span, Value,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -76,12 +77,21 @@ pub fn evaluate_file(
|
|||||||
trace!("parsing file: {}", file_path_str);
|
trace!("parsing file: {}", file_path_str);
|
||||||
let block = parse(&mut working_set, Some(file_path_str), &file, false);
|
let block = parse(&mut working_set, Some(file_path_str), &file, false);
|
||||||
|
|
||||||
|
if let Some(warning) = working_set.parse_warnings.first() {
|
||||||
|
report_parse_warning(&working_set, warning);
|
||||||
|
}
|
||||||
|
|
||||||
// If any parse errors were found, report the first error and exit.
|
// If any parse errors were found, report the first error and exit.
|
||||||
if let Some(err) = working_set.parse_errors.first() {
|
if let Some(err) = working_set.parse_errors.first() {
|
||||||
report_error(&working_set, err);
|
report_parse_error(&working_set, err);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(err) = working_set.compile_errors.first() {
|
||||||
|
report_compile_error(&working_set, err);
|
||||||
|
// Not a fatal error, for now
|
||||||
|
}
|
||||||
|
|
||||||
// Look for blocks whose name starts with "main" and replace it with the filename.
|
// Look for blocks whose name starts with "main" and replace it with the filename.
|
||||||
for block in working_set.delta.blocks.iter_mut().map(Arc::make_mut) {
|
for block in working_set.delta.blocks.iter_mut().map(Arc::make_mut) {
|
||||||
if block.signature.name == "main" {
|
if block.signature.name == "main" {
|
||||||
@ -109,11 +119,7 @@ pub fn evaluate_file(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Print the pipeline output of the last command of the file.
|
// Print the pipeline output of the last command of the file.
|
||||||
if let Some(status) = pipeline.print(engine_state, stack, true, false)? {
|
pipeline.print(engine_state, stack, true, false)?;
|
||||||
if status.code() != 0 {
|
|
||||||
std::process::exit(status.code())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invoke the main command with arguments.
|
// Invoke the main command with arguments.
|
||||||
// Arguments with whitespaces are quoted, thus can be safely concatenated by whitespace.
|
// Arguments with whitespaces are quoted, thus can be safely concatenated by whitespace.
|
||||||
@ -131,7 +137,7 @@ pub fn evaluate_file(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if exit_code != 0 {
|
if exit_code != 0 {
|
||||||
std::process::exit(exit_code)
|
std::process::exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("evaluate {}:{}:{}", file!(), line!(), column!());
|
info!("evaluate {}:{}:{}", file!(), line!(), column!());
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![doc = include_str!("../README.md")]
|
||||||
mod commands;
|
mod commands;
|
||||||
mod completions;
|
mod completions;
|
||||||
mod config_files;
|
mod config_files;
|
||||||
@ -17,10 +18,9 @@ mod validation;
|
|||||||
pub use commands::add_cli_context;
|
pub use commands::add_cli_context;
|
||||||
pub use completions::{FileCompletion, NuCompleter, SemanticSuggestion, SuggestionKind};
|
pub use completions::{FileCompletion, NuCompleter, SemanticSuggestion, SuggestionKind};
|
||||||
pub use config_files::eval_config_contents;
|
pub use config_files::eval_config_contents;
|
||||||
pub use eval_cmds::evaluate_commands;
|
pub use eval_cmds::{evaluate_commands, EvaluateCommandsOpts};
|
||||||
pub use eval_file::evaluate_file;
|
pub use eval_file::evaluate_file;
|
||||||
pub use menus::NuHelpCompleter;
|
pub use menus::NuHelpCompleter;
|
||||||
pub use nu_cmd_base::util::get_init_cwd;
|
|
||||||
pub use nu_highlight::NuHighlight;
|
pub use nu_highlight::NuHighlight;
|
||||||
pub use print::Print;
|
pub use print::Print;
|
||||||
pub use prompt::NushellPrompt;
|
pub use prompt::NushellPrompt;
|
||||||
|
@ -1,32 +1,44 @@
|
|||||||
use nu_engine::documentation::get_flags_section;
|
use nu_engine::documentation::{get_flags_section, HelpStyle};
|
||||||
use nu_protocol::{engine::EngineState, levenshtein_distance};
|
use nu_protocol::{engine::EngineState, levenshtein_distance, Config};
|
||||||
use nu_utils::IgnoreCaseExt;
|
use nu_utils::IgnoreCaseExt;
|
||||||
use reedline::{Completer, Suggestion};
|
use reedline::{Completer, Suggestion};
|
||||||
use std::{fmt::Write, sync::Arc};
|
use std::{fmt::Write, sync::Arc};
|
||||||
|
|
||||||
pub struct NuHelpCompleter(Arc<EngineState>);
|
pub struct NuHelpCompleter {
|
||||||
|
engine_state: Arc<EngineState>,
|
||||||
|
config: Arc<Config>,
|
||||||
|
}
|
||||||
|
|
||||||
impl NuHelpCompleter {
|
impl NuHelpCompleter {
|
||||||
pub fn new(engine_state: Arc<EngineState>) -> Self {
|
pub fn new(engine_state: Arc<EngineState>, config: Arc<Config>) -> Self {
|
||||||
Self(engine_state)
|
Self {
|
||||||
|
engine_state,
|
||||||
|
config,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completion_helper(&self, line: &str, pos: usize) -> Vec<Suggestion> {
|
fn completion_helper(&self, line: &str, pos: usize) -> Vec<Suggestion> {
|
||||||
let folded_line = line.to_folded_case();
|
let folded_line = line.to_folded_case();
|
||||||
|
|
||||||
|
let mut help_style = HelpStyle::default();
|
||||||
|
help_style.update_from_config(&self.engine_state, &self.config);
|
||||||
|
|
||||||
let mut commands = self
|
let mut commands = self
|
||||||
.0
|
.engine_state
|
||||||
.get_decls_sorted(false)
|
.get_decls_sorted(false)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(_, decl_id)| {
|
.filter_map(|(_, decl_id)| {
|
||||||
let decl = self.0.get_decl(decl_id);
|
let decl = self.engine_state.get_decl(decl_id);
|
||||||
(decl.name().to_folded_case().contains(&folded_line)
|
(decl.name().to_folded_case().contains(&folded_line)
|
||||||
|| decl.usage().to_folded_case().contains(&folded_line)
|
|| decl.description().to_folded_case().contains(&folded_line)
|
||||||
|| decl
|
|| decl
|
||||||
.search_terms()
|
.search_terms()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.any(|term| term.to_folded_case().contains(&folded_line))
|
.any(|term| term.to_folded_case().contains(&folded_line))
|
||||||
|| decl.extra_usage().to_folded_case().contains(&folded_line))
|
|| decl
|
||||||
|
.extra_description()
|
||||||
|
.to_folded_case()
|
||||||
|
.contains(&folded_line))
|
||||||
.then_some(decl)
|
.then_some(decl)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -38,15 +50,15 @@ impl NuHelpCompleter {
|
|||||||
.map(|decl| {
|
.map(|decl| {
|
||||||
let mut long_desc = String::new();
|
let mut long_desc = String::new();
|
||||||
|
|
||||||
let usage = decl.usage();
|
let description = decl.description();
|
||||||
if !usage.is_empty() {
|
if !description.is_empty() {
|
||||||
long_desc.push_str(usage);
|
long_desc.push_str(description);
|
||||||
long_desc.push_str("\r\n\r\n");
|
long_desc.push_str("\r\n\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
let extra_usage = decl.extra_usage();
|
let extra_desc = decl.extra_description();
|
||||||
if !extra_usage.is_empty() {
|
if !extra_desc.is_empty() {
|
||||||
long_desc.push_str(extra_usage);
|
long_desc.push_str(extra_desc);
|
||||||
long_desc.push_str("\r\n\r\n");
|
long_desc.push_str("\r\n\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +66,8 @@ impl NuHelpCompleter {
|
|||||||
let _ = write!(long_desc, "Usage:\r\n > {}\r\n", sig.call_signature());
|
let _ = write!(long_desc, "Usage:\r\n > {}\r\n", sig.call_signature());
|
||||||
|
|
||||||
if !sig.named.is_empty() {
|
if !sig.named.is_empty() {
|
||||||
long_desc.push_str(&get_flags_section(Some(&*self.0.clone()), &sig, |v| {
|
long_desc.push_str(&get_flags_section(&sig, &help_style, |v| {
|
||||||
v.to_parsable_string(", ", &self.0.config)
|
v.to_parsable_string(", ", &self.config)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +83,7 @@ impl NuHelpCompleter {
|
|||||||
let opt_suffix = if let Some(value) = &positional.default_value {
|
let opt_suffix = if let Some(value) = &positional.default_value {
|
||||||
format!(
|
format!(
|
||||||
" (optional, default: {})",
|
" (optional, default: {})",
|
||||||
&value.to_parsable_string(", ", &self.0.config),
|
&value.to_parsable_string(", ", &self.config),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(" (optional)").to_string()
|
(" (optional)").to_string()
|
||||||
@ -101,13 +113,12 @@ impl NuHelpCompleter {
|
|||||||
Suggestion {
|
Suggestion {
|
||||||
value: decl.name().into(),
|
value: decl.name().into(),
|
||||||
description: Some(long_desc),
|
description: Some(long_desc),
|
||||||
style: None,
|
|
||||||
extra: Some(extra),
|
extra: Some(extra),
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: pos - line.len(),
|
start: pos - line.len(),
|
||||||
end: pos,
|
end: pos,
|
||||||
},
|
},
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@ -138,7 +149,8 @@ mod test {
|
|||||||
) {
|
) {
|
||||||
let engine_state =
|
let engine_state =
|
||||||
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context());
|
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context());
|
||||||
let mut completer = NuHelpCompleter::new(engine_state.into());
|
let config = engine_state.get_config().clone();
|
||||||
|
let mut completer = NuHelpCompleter::new(engine_state.into(), config);
|
||||||
let suggestions = completer.complete(line, end);
|
let suggestions = completer.complete(line, end);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2,7 +2,7 @@ use nu_engine::eval_block;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
IntoPipelineData, Span, Value,
|
BlockId, IntoPipelineData, Span, Value,
|
||||||
};
|
};
|
||||||
use reedline::{menu_functions::parse_selection_char, Completer, Suggestion};
|
use reedline::{menu_functions::parse_selection_char, Completer, Suggestion};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -10,7 +10,7 @@ use std::sync::Arc;
|
|||||||
const SELECTION_CHAR: char = '!';
|
const SELECTION_CHAR: char = '!';
|
||||||
|
|
||||||
pub struct NuMenuCompleter {
|
pub struct NuMenuCompleter {
|
||||||
block_id: usize,
|
block_id: BlockId,
|
||||||
span: Span,
|
span: Span,
|
||||||
stack: Stack,
|
stack: Stack,
|
||||||
engine_state: Arc<EngineState>,
|
engine_state: Arc<EngineState>,
|
||||||
@ -19,7 +19,7 @@ pub struct NuMenuCompleter {
|
|||||||
|
|
||||||
impl NuMenuCompleter {
|
impl NuMenuCompleter {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
block_id: usize,
|
block_id: BlockId,
|
||||||
span: Span,
|
span: Span,
|
||||||
stack: Stack,
|
stack: Stack,
|
||||||
engine_state: Arc<EngineState>,
|
engine_state: Arc<EngineState>,
|
||||||
@ -28,7 +28,7 @@ impl NuMenuCompleter {
|
|||||||
Self {
|
Self {
|
||||||
block_id,
|
block_id,
|
||||||
span,
|
span,
|
||||||
stack: stack.reset_out_dest().capture(),
|
stack: stack.reset_out_dest().collect_value(),
|
||||||
engine_state,
|
engine_state,
|
||||||
only_buffer_difference,
|
only_buffer_difference,
|
||||||
}
|
}
|
||||||
@ -142,10 +142,9 @@ fn convert_to_suggestions(
|
|||||||
vec![Suggestion {
|
vec![Suggestion {
|
||||||
value: text,
|
value: text,
|
||||||
description,
|
description,
|
||||||
style: None,
|
|
||||||
extra,
|
extra,
|
||||||
span,
|
span,
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
Value::List { vals, .. } => vals
|
Value::List { vals, .. } => vals
|
||||||
@ -154,9 +153,6 @@ fn convert_to_suggestions(
|
|||||||
.collect(),
|
.collect(),
|
||||||
_ => vec![Suggestion {
|
_ => vec![Suggestion {
|
||||||
value: format!("Not a record: {value:?}"),
|
value: format!("Not a record: {value:?}"),
|
||||||
description: None,
|
|
||||||
style: None,
|
|
||||||
extra: None,
|
|
||||||
span: reedline::Span {
|
span: reedline::Span {
|
||||||
start: if only_buffer_difference {
|
start: if only_buffer_difference {
|
||||||
pos - line.len()
|
pos - line.len()
|
||||||
@ -169,7 +165,7 @@ fn convert_to_suggestions(
|
|||||||
line.len()
|
line.len()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
append_whitespace: false,
|
..Suggestion::default()
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
use reedline::{Highlighter, StyledText};
|
use reedline::{Highlighter, StyledText};
|
||||||
|
|
||||||
@ -15,7 +17,7 @@ impl Command for NuHighlight {
|
|||||||
.input_output_types(vec![(Type::String, Type::String)])
|
.input_output_types(vec![(Type::String, Type::String)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Syntax highlight the input string."
|
"Syntax highlight the input string."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,14 +34,11 @@ impl Command for NuHighlight {
|
|||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
|
|
||||||
let ctrlc = engine_state.ctrlc.clone();
|
let signals = engine_state.signals();
|
||||||
let engine_state = std::sync::Arc::new(engine_state.clone());
|
|
||||||
let config = engine_state.get_config().clone();
|
|
||||||
|
|
||||||
let highlighter = crate::NuHighlighter {
|
let highlighter = crate::NuHighlighter {
|
||||||
engine_state,
|
engine_state: Arc::new(engine_state.clone()),
|
||||||
stack: std::sync::Arc::new(stack.clone()),
|
stack: Arc::new(stack.clone()),
|
||||||
config,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
input.map(
|
input.map(
|
||||||
@ -50,7 +49,7 @@ impl Command for NuHighlight {
|
|||||||
}
|
}
|
||||||
Err(err) => Value::error(err, head),
|
Err(err) => Value::error(err, head),
|
||||||
},
|
},
|
||||||
ctrlc,
|
signals,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
|
use nu_protocol::ByteStreamSource;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Print;
|
pub struct Print;
|
||||||
@ -22,14 +23,19 @@ impl Command for Print {
|
|||||||
Some('n'),
|
Some('n'),
|
||||||
)
|
)
|
||||||
.switch("stderr", "print to stderr instead of stdout", Some('e'))
|
.switch("stderr", "print to stderr instead of stdout", Some('e'))
|
||||||
|
.switch(
|
||||||
|
"raw",
|
||||||
|
"print without formatting (including binary data)",
|
||||||
|
Some('r'),
|
||||||
|
)
|
||||||
.category(Category::Strings)
|
.category(Category::Strings)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Print the given values to stdout."
|
"Print the given values to stdout."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_usage(&self) -> &str {
|
fn extra_description(&self) -> &str {
|
||||||
r#"Unlike `echo`, this command does not return any value (`print | describe` will return "nothing").
|
r#"Unlike `echo`, this command does not return any value (`print | describe` will return "nothing").
|
||||||
Since this command has no output, there is no point in piping it with other commands.
|
Since this command has no output, there is no point in piping it with other commands.
|
||||||
|
|
||||||
@ -45,20 +51,35 @@ Since this command has no output, there is no point in piping it with other comm
|
|||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
mut input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let args: Vec<Value> = call.rest(engine_state, stack, 0)?;
|
let args: Vec<Value> = call.rest(engine_state, stack, 0)?;
|
||||||
let no_newline = call.has_flag(engine_state, stack, "no-newline")?;
|
let no_newline = call.has_flag(engine_state, stack, "no-newline")?;
|
||||||
let to_stderr = call.has_flag(engine_state, stack, "stderr")?;
|
let to_stderr = call.has_flag(engine_state, stack, "stderr")?;
|
||||||
|
let raw = call.has_flag(engine_state, stack, "raw")?;
|
||||||
|
|
||||||
// This will allow for easy printing of pipelines as well
|
// This will allow for easy printing of pipelines as well
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
arg.into_pipeline_data()
|
if raw {
|
||||||
.print(engine_state, stack, no_newline, to_stderr)?;
|
arg.into_pipeline_data()
|
||||||
|
.print_raw(engine_state, no_newline, to_stderr)?;
|
||||||
|
} else {
|
||||||
|
arg.into_pipeline_data()
|
||||||
|
.print(engine_state, stack, no_newline, to_stderr)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if !input.is_nothing() {
|
} else if !input.is_nothing() {
|
||||||
input.print(engine_state, stack, no_newline, to_stderr)?;
|
if let PipelineData::ByteStream(stream, _) = &mut input {
|
||||||
|
if let ByteStreamSource::Child(child) = stream.source_mut() {
|
||||||
|
child.ignore_error(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if raw {
|
||||||
|
input.print_raw(engine_state, no_newline, to_stderr)?;
|
||||||
|
} else {
|
||||||
|
input.print(engine_state, stack, no_newline, to_stderr)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(PipelineData::empty())
|
Ok(PipelineData::empty())
|
||||||
@ -76,6 +97,11 @@ Since this command has no output, there is no point in piping it with other comm
|
|||||||
example: r#"print (2 + 3)"#,
|
example: r#"print (2 + 3)"#,
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Print 'ABC' from binary data",
|
||||||
|
example: r#"0x[41 42 43] | print --raw"#,
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
use crate::prompt_update::{
|
use crate::prompt_update::{
|
||||||
POST_PROMPT_MARKER, PRE_PROMPT_MARKER, VSCODE_POST_PROMPT_MARKER, VSCODE_PRE_PROMPT_MARKER,
|
POST_PROMPT_MARKER, PRE_PROMPT_MARKER, VSCODE_POST_PROMPT_MARKER, VSCODE_PRE_PROMPT_MARKER,
|
||||||
};
|
};
|
||||||
use nu_protocol::{
|
use nu_protocol::engine::{EngineState, Stack};
|
||||||
engine::{EngineState, Stack},
|
|
||||||
Value,
|
|
||||||
};
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use nu_utils::enable_vt_processing;
|
use nu_utils::enable_vt_processing;
|
||||||
use reedline::{
|
use reedline::{
|
||||||
@ -124,8 +121,11 @@ impl Prompt for NushellPrompt {
|
|||||||
.replace('\n', "\r\n");
|
.replace('\n', "\r\n");
|
||||||
|
|
||||||
if self.shell_integration_osc633 {
|
if self.shell_integration_osc633 {
|
||||||
if self.stack.get_env_var(&self.engine_state, "TERM_PROGRAM")
|
if self
|
||||||
== Some(Value::test_string("vscode"))
|
.stack
|
||||||
|
.get_env_var(&self.engine_state, "TERM_PROGRAM")
|
||||||
|
.and_then(|v| v.as_str().ok())
|
||||||
|
== Some("vscode")
|
||||||
{
|
{
|
||||||
// We're in vscode and we have osc633 enabled
|
// We're in vscode and we have osc633 enabled
|
||||||
format!("{VSCODE_PRE_PROMPT_MARKER}{prompt}{VSCODE_POST_PROMPT_MARKER}").into()
|
format!("{VSCODE_PRE_PROMPT_MARKER}{prompt}{VSCODE_POST_PROMPT_MARKER}").into()
|
||||||
|
@ -3,7 +3,7 @@ use log::trace;
|
|||||||
use nu_engine::ClosureEvalOnce;
|
use nu_engine::ClosureEvalOnce;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
report_error_new, Config, PipelineData, Value,
|
report_shell_error, Config, PipelineData, Value,
|
||||||
};
|
};
|
||||||
use reedline::Prompt;
|
use reedline::Prompt;
|
||||||
|
|
||||||
@ -46,7 +46,10 @@ pub(crate) const VSCODE_POST_EXECUTION_MARKER_PREFIX: &str = "\x1b]633;D;";
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) const VSCODE_POST_EXECUTION_MARKER_SUFFIX: &str = "\x1b\\";
|
pub(crate) const VSCODE_POST_EXECUTION_MARKER_SUFFIX: &str = "\x1b\\";
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) const VSCODE_COMMANDLINE_MARKER: &str = "\x1b]633;E\x1b\\";
|
//"\x1b]633;E;{}\x1b\\"
|
||||||
|
pub(crate) const VSCODE_COMMANDLINE_MARKER_PREFIX: &str = "\x1b]633;E;";
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) const VSCODE_COMMANDLINE_MARKER_SUFFIX: &str = "\x1b\\";
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// "\x1b]633;P;Cwd={}\x1b\\"
|
// "\x1b]633;P;Cwd={}\x1b\\"
|
||||||
pub(crate) const VSCODE_CWD_PROPERTY_MARKER_PREFIX: &str = "\x1b]633;P;Cwd=";
|
pub(crate) const VSCODE_CWD_PROPERTY_MARKER_PREFIX: &str = "\x1b]633;P;Cwd=";
|
||||||
@ -65,7 +68,7 @@ fn get_prompt_string(
|
|||||||
.get_env_var(engine_state, prompt)
|
.get_env_var(engine_state, prompt)
|
||||||
.and_then(|v| match v {
|
.and_then(|v| match v {
|
||||||
Value::Closure { val, .. } => {
|
Value::Closure { val, .. } => {
|
||||||
let result = ClosureEvalOnce::new(engine_state, stack, *val)
|
let result = ClosureEvalOnce::new(engine_state, stack, val.as_ref().clone())
|
||||||
.run_with_input(PipelineData::Empty);
|
.run_with_input(PipelineData::Empty);
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
@ -77,7 +80,7 @@ fn get_prompt_string(
|
|||||||
|
|
||||||
result
|
result
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
report_error_new(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
})
|
})
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
@ -115,13 +118,17 @@ pub(crate) fn update_prompt(
|
|||||||
|
|
||||||
// Now that we have the prompt string lets ansify it.
|
// Now that we have the prompt string lets ansify it.
|
||||||
// <133 A><prompt><133 B><command><133 C><command output>
|
// <133 A><prompt><133 B><command><133 C><command output>
|
||||||
let left_prompt_string = if config.shell_integration_osc633 {
|
let left_prompt_string = if config.shell_integration.osc633 {
|
||||||
if stack.get_env_var(engine_state, "TERM_PROGRAM") == Some(Value::test_string("vscode")) {
|
if stack
|
||||||
|
.get_env_var(engine_state, "TERM_PROGRAM")
|
||||||
|
.and_then(|v| v.as_str().ok())
|
||||||
|
== Some("vscode")
|
||||||
|
{
|
||||||
// We're in vscode and we have osc633 enabled
|
// We're in vscode and we have osc633 enabled
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"{VSCODE_PRE_PROMPT_MARKER}{configured_left_prompt_string}{VSCODE_POST_PROMPT_MARKER}"
|
"{VSCODE_PRE_PROMPT_MARKER}{configured_left_prompt_string}{VSCODE_POST_PROMPT_MARKER}"
|
||||||
))
|
))
|
||||||
} else if config.shell_integration_osc133 {
|
} else if config.shell_integration.osc133 {
|
||||||
// If we're in VSCode but we don't find the env var, but we have osc133 set, then use it
|
// If we're in VSCode but we don't find the env var, but we have osc133 set, then use it
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"{PRE_PROMPT_MARKER}{configured_left_prompt_string}{POST_PROMPT_MARKER}"
|
"{PRE_PROMPT_MARKER}{configured_left_prompt_string}{POST_PROMPT_MARKER}"
|
||||||
@ -129,7 +136,7 @@ pub(crate) fn update_prompt(
|
|||||||
} else {
|
} else {
|
||||||
configured_left_prompt_string.into()
|
configured_left_prompt_string.into()
|
||||||
}
|
}
|
||||||
} else if config.shell_integration_osc133 {
|
} else if config.shell_integration.osc133 {
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"{PRE_PROMPT_MARKER}{configured_left_prompt_string}{POST_PROMPT_MARKER}"
|
"{PRE_PROMPT_MARKER}{configured_left_prompt_string}{POST_PROMPT_MARKER}"
|
||||||
))
|
))
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ use nu_parser::{flatten_block, parse, FlatShape};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Block, Expr, Expression, PipelineRedirection, RecordItem},
|
ast::{Block, Expr, Expression, PipelineRedirection, RecordItem},
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
Config, Span,
|
Span,
|
||||||
};
|
};
|
||||||
use reedline::{Highlighter, StyledText};
|
use reedline::{Highlighter, StyledText};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -14,15 +14,14 @@ use std::sync::Arc;
|
|||||||
pub struct NuHighlighter {
|
pub struct NuHighlighter {
|
||||||
pub engine_state: Arc<EngineState>,
|
pub engine_state: Arc<EngineState>,
|
||||||
pub stack: Arc<Stack>,
|
pub stack: Arc<Stack>,
|
||||||
pub config: Config,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Highlighter for NuHighlighter {
|
impl Highlighter for NuHighlighter {
|
||||||
fn highlight(&self, line: &str, _cursor: usize) -> StyledText {
|
fn highlight(&self, line: &str, _cursor: usize) -> StyledText {
|
||||||
trace!("highlighting: {}", line);
|
trace!("highlighting: {}", line);
|
||||||
|
|
||||||
let highlight_resolved_externals =
|
let config = self.stack.get_config(&self.engine_state);
|
||||||
self.engine_state.get_config().highlight_resolved_externals;
|
let highlight_resolved_externals = config.highlight_resolved_externals;
|
||||||
let mut working_set = StateWorkingSet::new(&self.engine_state);
|
let mut working_set = StateWorkingSet::new(&self.engine_state);
|
||||||
let block = parse(&mut working_set, None, line.as_bytes(), false);
|
let block = parse(&mut working_set, None, line.as_bytes(), false);
|
||||||
let (shapes, global_span_offset) = {
|
let (shapes, global_span_offset) = {
|
||||||
@ -88,7 +87,7 @@ impl Highlighter for NuHighlighter {
|
|||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let mut add_colored_token = |shape: &FlatShape, text: String| {
|
let mut add_colored_token = |shape: &FlatShape, text: String| {
|
||||||
output.push((get_shape_color(shape.as_str(), &self.config), text));
|
output.push((get_shape_color(shape.as_str(), &config), text));
|
||||||
};
|
};
|
||||||
|
|
||||||
match shape.1 {
|
match shape.1 {
|
||||||
@ -128,9 +127,9 @@ impl Highlighter for NuHighlighter {
|
|||||||
let start = part.start - span.start;
|
let start = part.start - span.start;
|
||||||
let end = part.end - span.start;
|
let end = part.end - span.start;
|
||||||
let text = next_token[start..end].to_string();
|
let text = next_token[start..end].to_string();
|
||||||
let mut style = get_shape_color(shape.as_str(), &self.config);
|
let mut style = get_shape_color(shape.as_str(), &config);
|
||||||
if highlight {
|
if highlight {
|
||||||
style = get_matching_brackets_style(style, &self.config);
|
style = get_matching_brackets_style(style, &config);
|
||||||
}
|
}
|
||||||
output.push((style, text));
|
output.push((style, text));
|
||||||
}
|
}
|
||||||
@ -138,6 +137,7 @@ impl Highlighter for NuHighlighter {
|
|||||||
|
|
||||||
FlatShape::Filepath => add_colored_token(&shape.1, next_token),
|
FlatShape::Filepath => add_colored_token(&shape.1, next_token),
|
||||||
FlatShape::Directory => add_colored_token(&shape.1, next_token),
|
FlatShape::Directory => add_colored_token(&shape.1, next_token),
|
||||||
|
FlatShape::GlobInterpolation => add_colored_token(&shape.1, next_token),
|
||||||
FlatShape::GlobPattern => add_colored_token(&shape.1, next_token),
|
FlatShape::GlobPattern => add_colored_token(&shape.1, next_token),
|
||||||
FlatShape::Variable(_) | FlatShape::VarDecl(_) => {
|
FlatShape::Variable(_) | FlatShape::VarDecl(_) => {
|
||||||
add_colored_token(&shape.1, next_token)
|
add_colored_token(&shape.1, next_token)
|
||||||
@ -429,6 +429,14 @@ fn find_matching_block_end_in_expr(
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
Expr::Collect(_, expr) => find_matching_block_end_in_expr(
|
||||||
|
line,
|
||||||
|
working_set,
|
||||||
|
expr,
|
||||||
|
global_span_offset,
|
||||||
|
global_cursor_offset,
|
||||||
|
),
|
||||||
|
|
||||||
Expr::Block(block_id)
|
Expr::Block(block_id)
|
||||||
| Expr::Closure(block_id)
|
| Expr::Closure(block_id)
|
||||||
| Expr::RowCondition(block_id)
|
| Expr::RowCondition(block_id)
|
||||||
@ -452,15 +460,17 @@ fn find_matching_block_end_in_expr(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Expr::StringInterpolation(exprs) => exprs.iter().find_map(|expr| {
|
Expr::StringInterpolation(exprs) | Expr::GlobInterpolation(exprs, _) => {
|
||||||
find_matching_block_end_in_expr(
|
exprs.iter().find_map(|expr| {
|
||||||
line,
|
find_matching_block_end_in_expr(
|
||||||
working_set,
|
line,
|
||||||
expr,
|
working_set,
|
||||||
global_span_offset,
|
expr,
|
||||||
global_cursor_offset,
|
global_span_offset,
|
||||||
)
|
global_cursor_offset,
|
||||||
}),
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Expr::List(list) => {
|
Expr::List(list) => {
|
||||||
if expr_last == global_cursor_offset {
|
if expr_last == global_cursor_offset {
|
||||||
|
@ -2,13 +2,15 @@ use nu_cmd_base::hook::eval_hook;
|
|||||||
use nu_engine::{eval_block, eval_block_with_early_return};
|
use nu_engine::{eval_block, eval_block_with_early_return};
|
||||||
use nu_parser::{escape_quote_string, lex, parse, unescape_unquote_string, Token, TokenContents};
|
use nu_parser::{escape_quote_string, lex, parse, unescape_unquote_string, Token, TokenContents};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
|
cli_error::report_compile_error,
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
report_error, report_error_new, PipelineData, ShellError, Span, Value,
|
report_parse_error, report_parse_warning, report_shell_error, PipelineData, ShellError, Span,
|
||||||
|
Value,
|
||||||
};
|
};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use nu_utils::enable_vt_processing;
|
use nu_utils::enable_vt_processing;
|
||||||
use nu_utils::utils::perf;
|
use nu_utils::perf;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
// This will collect environment variables from std::env and adds them to a stack.
|
// This will collect environment variables from std::env and adds them to a stack.
|
||||||
@ -39,7 +41,7 @@ fn gather_env_vars(
|
|||||||
init_cwd: &Path,
|
init_cwd: &Path,
|
||||||
) {
|
) {
|
||||||
fn report_capture_error(engine_state: &EngineState, env_str: &str, msg: &str) {
|
fn report_capture_error(engine_state: &EngineState, env_str: &str, msg: &str) {
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
engine_state,
|
engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: format!("Environment variable was not captured: {env_str}"),
|
error: format!("Environment variable was not captured: {env_str}"),
|
||||||
@ -70,7 +72,7 @@ fn gather_env_vars(
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Could not capture current working directory
|
// Could not capture current working directory
|
||||||
report_error_new(
|
report_shell_error(
|
||||||
engine_state,
|
engine_state,
|
||||||
&ShellError::GenericError {
|
&ShellError::GenericError {
|
||||||
error: "Current directory is not a valid utf-8 path".into(),
|
error: "Current directory is not a valid utf-8 path".into(),
|
||||||
@ -210,31 +212,29 @@ pub fn eval_source(
|
|||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
|
|
||||||
let exit_code = match evaluate_source(engine_state, stack, source, fname, input, allow_return) {
|
let exit_code = match evaluate_source(engine_state, stack, source, fname, input, allow_return) {
|
||||||
Ok(code) => code.unwrap_or(0),
|
Ok(failed) => {
|
||||||
|
let code = failed.into();
|
||||||
|
stack.set_last_exit_code(code, Span::unknown());
|
||||||
|
code
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
report_error_new(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
1
|
let code = err.exit_code();
|
||||||
|
stack.set_last_error(&err);
|
||||||
|
code.unwrap_or(0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
stack.add_env_var(
|
|
||||||
"LAST_EXIT_CODE".to_string(),
|
|
||||||
Value::int(exit_code.into(), Span::unknown()),
|
|
||||||
);
|
|
||||||
|
|
||||||
// reset vt processing, aka ansi because illbehaved externals can break it
|
// reset vt processing, aka ansi because illbehaved externals can break it
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
let _ = enable_vt_processing();
|
let _ = enable_vt_processing();
|
||||||
}
|
}
|
||||||
|
|
||||||
perf(
|
perf!(
|
||||||
&format!("eval_source {}", &fname),
|
&format!("eval_source {}", &fname),
|
||||||
start_time,
|
start_time,
|
||||||
file!(),
|
engine_state.get_config().use_ansi_coloring
|
||||||
line!(),
|
|
||||||
column!(),
|
|
||||||
engine_state.get_config().use_ansi_coloring,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
exit_code
|
exit_code
|
||||||
@ -247,7 +247,7 @@ fn evaluate_source(
|
|||||||
fname: &str,
|
fname: &str,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
allow_return: bool,
|
allow_return: bool,
|
||||||
) -> Result<Option<i32>, ShellError> {
|
) -> Result<bool, ShellError> {
|
||||||
let (block, delta) = {
|
let (block, delta) = {
|
||||||
let mut working_set = StateWorkingSet::new(engine_state);
|
let mut working_set = StateWorkingSet::new(engine_state);
|
||||||
let output = parse(
|
let output = parse(
|
||||||
@ -257,12 +257,17 @@ fn evaluate_source(
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
if let Some(warning) = working_set.parse_warnings.first() {
|
if let Some(warning) = working_set.parse_warnings.first() {
|
||||||
report_error(&working_set, warning);
|
report_parse_warning(&working_set, warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(err) = working_set.parse_errors.first() {
|
if let Some(err) = working_set.parse_errors.first() {
|
||||||
report_error(&working_set, err);
|
report_parse_error(&working_set, err);
|
||||||
return Ok(Some(1));
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(err) = working_set.compile_errors.first() {
|
||||||
|
report_compile_error(&working_set, err);
|
||||||
|
// Not a fatal error, for now
|
||||||
}
|
}
|
||||||
|
|
||||||
(output, working_set.render())
|
(output, working_set.render())
|
||||||
@ -276,25 +281,23 @@ fn evaluate_source(
|
|||||||
eval_block::<WithoutDebug>(engine_state, stack, &block, input)
|
eval_block::<WithoutDebug>(engine_state, stack, &block, input)
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
let status = if let PipelineData::ByteStream(..) = pipeline {
|
if let PipelineData::ByteStream(..) = pipeline {
|
||||||
pipeline.print(engine_state, stack, false, false)?
|
pipeline.print(engine_state, stack, false, false)
|
||||||
|
} else if let Some(hook) = engine_state.get_config().hooks.display_output.clone() {
|
||||||
|
let pipeline = eval_hook(
|
||||||
|
engine_state,
|
||||||
|
stack,
|
||||||
|
Some(pipeline),
|
||||||
|
vec![],
|
||||||
|
&hook,
|
||||||
|
"display_output",
|
||||||
|
)?;
|
||||||
|
pipeline.print(engine_state, stack, false, false)
|
||||||
} else {
|
} else {
|
||||||
if let Some(hook) = engine_state.get_config().hooks.display_output.clone() {
|
pipeline.print(engine_state, stack, true, false)
|
||||||
let pipeline = eval_hook(
|
}?;
|
||||||
engine_state,
|
|
||||||
stack,
|
|
||||||
Some(pipeline),
|
|
||||||
vec![],
|
|
||||||
&hook,
|
|
||||||
"display_output",
|
|
||||||
)?;
|
|
||||||
pipeline.print(engine_state, stack, false, false)
|
|
||||||
} else {
|
|
||||||
pipeline.print(engine_state, stack, true, false)
|
|
||||||
}?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(status.map(|status| status.code()))
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -319,16 +322,10 @@ mod test {
|
|||||||
|
|
||||||
let env = engine_state.render_env_vars();
|
let env = engine_state.render_env_vars();
|
||||||
|
|
||||||
assert!(
|
assert!(matches!(env.get("FOO"), Some(&Value::String { val, .. }) if val == "foo"));
|
||||||
matches!(env.get(&"FOO".to_string()), Some(&Value::String { val, .. }) if val == "foo")
|
assert!(matches!(env.get("SYMBOLS"), Some(&Value::String { val, .. }) if val == symbols));
|
||||||
);
|
assert!(matches!(env.get(symbols), Some(&Value::String { val, .. }) if val == "symbols"));
|
||||||
assert!(
|
assert!(env.contains_key("PWD"));
|
||||||
matches!(env.get(&"SYMBOLS".to_string()), Some(&Value::String { val, .. }) if val == symbols)
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
matches!(env.get(&symbols.to_string()), Some(&Value::String { val, .. }) if val == "symbols")
|
|
||||||
);
|
|
||||||
assert!(env.get(&"PWD".to_string()).is_some());
|
|
||||||
assert_eq!(env.len(), 4);
|
assert_eq!(env.len(), 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
crates/nu-cli/tests/commands/keybindings_list.rs
Normal file
7
crates/nu-cli/tests/commands/keybindings_list.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use nu_test_support::nu;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn not_empty() {
|
||||||
|
let result = nu!("keybindings list | is-not-empty");
|
||||||
|
assert_eq!(result.out, "true");
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
|
mod keybindings_list;
|
||||||
mod nu_highlight;
|
mod nu_highlight;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
|||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
|
use nu_path::{AbsolutePathBuf, PathBuf};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
@ -7,14 +8,14 @@ use nu_protocol::{
|
|||||||
};
|
};
|
||||||
use nu_test_support::fs;
|
use nu_test_support::fs;
|
||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
use std::path::{PathBuf, MAIN_SEPARATOR};
|
use std::path::MAIN_SEPARATOR;
|
||||||
|
|
||||||
fn create_default_context() -> EngineState {
|
fn create_default_context() -> EngineState {
|
||||||
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context())
|
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context())
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a new engine with the current path into the completions fixtures folder
|
// creates a new engine with the current path into the completions fixtures folder
|
||||||
pub fn new_engine() -> (PathBuf, String, EngineState, Stack) {
|
pub fn new_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
|
||||||
// Target folder inside assets
|
// Target folder inside assets
|
||||||
let dir = fs::fixtures().join("completions");
|
let dir = fs::fixtures().join("completions");
|
||||||
let dir_str = dir
|
let dir_str = dir
|
||||||
@ -62,13 +63,59 @@ pub fn new_engine() -> (PathBuf, String, EngineState, Stack) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Merge environment into the permanent state
|
// Merge environment into the permanent state
|
||||||
let merge_result = engine_state.merge_env(&mut stack, &dir);
|
let merge_result = engine_state.merge_env(&mut stack);
|
||||||
assert!(merge_result.is_ok());
|
assert!(merge_result.is_ok());
|
||||||
|
|
||||||
(dir, dir_str, engine_state, stack)
|
(dir, dir_str, engine_state, stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_quote_engine() -> (PathBuf, String, EngineState, Stack) {
|
// creates a new engine with the current path into the completions fixtures folder
|
||||||
|
pub fn new_dotnu_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
|
||||||
|
// Target folder inside assets
|
||||||
|
let dir = fs::fixtures().join("dotnu_completions");
|
||||||
|
let dir_str = dir
|
||||||
|
.clone()
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.unwrap_or_default();
|
||||||
|
let dir_span = nu_protocol::Span::new(0, dir_str.len());
|
||||||
|
|
||||||
|
// Create a new engine with default context
|
||||||
|
let mut engine_state = create_default_context();
|
||||||
|
|
||||||
|
// Add $nu
|
||||||
|
engine_state.generate_nu_constant();
|
||||||
|
|
||||||
|
// New stack
|
||||||
|
let mut stack = Stack::new();
|
||||||
|
|
||||||
|
// Add pwd as env var
|
||||||
|
stack.add_env_var("PWD".to_string(), Value::string(dir_str.clone(), dir_span));
|
||||||
|
stack.add_env_var(
|
||||||
|
"TEST".to_string(),
|
||||||
|
Value::string("NUSHELL".to_string(), dir_span),
|
||||||
|
);
|
||||||
|
|
||||||
|
stack.add_env_var(
|
||||||
|
"NU_LIB_DIRS".to_string(),
|
||||||
|
Value::List {
|
||||||
|
vals: vec![
|
||||||
|
Value::string(file(dir.join("lib-dir1")), dir_span),
|
||||||
|
Value::string(file(dir.join("lib-dir2")), dir_span),
|
||||||
|
Value::string(file(dir.join("lib-dir3")), dir_span),
|
||||||
|
],
|
||||||
|
internal_span: dir_span,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Merge environment into the permanent state
|
||||||
|
let merge_result = engine_state.merge_env(&mut stack);
|
||||||
|
assert!(merge_result.is_ok());
|
||||||
|
|
||||||
|
(dir, dir_str, engine_state, stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_quote_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
|
||||||
// Target folder inside assets
|
// Target folder inside assets
|
||||||
let dir = fs::fixtures().join("quoted_completions");
|
let dir = fs::fixtures().join("quoted_completions");
|
||||||
let dir_str = dir
|
let dir_str = dir
|
||||||
@ -97,13 +144,13 @@ pub fn new_quote_engine() -> (PathBuf, String, EngineState, Stack) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Merge environment into the permanent state
|
// Merge environment into the permanent state
|
||||||
let merge_result = engine_state.merge_env(&mut stack, &dir);
|
let merge_result = engine_state.merge_env(&mut stack);
|
||||||
assert!(merge_result.is_ok());
|
assert!(merge_result.is_ok());
|
||||||
|
|
||||||
(dir, dir_str, engine_state, stack)
|
(dir, dir_str, engine_state, stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_partial_engine() -> (PathBuf, String, EngineState, Stack) {
|
pub fn new_partial_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
|
||||||
// Target folder inside assets
|
// Target folder inside assets
|
||||||
let dir = fs::fixtures().join("partial_completions");
|
let dir = fs::fixtures().join("partial_completions");
|
||||||
let dir_str = dir
|
let dir_str = dir
|
||||||
@ -132,14 +179,14 @@ pub fn new_partial_engine() -> (PathBuf, String, EngineState, Stack) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Merge environment into the permanent state
|
// Merge environment into the permanent state
|
||||||
let merge_result = engine_state.merge_env(&mut stack, &dir);
|
let merge_result = engine_state.merge_env(&mut stack);
|
||||||
assert!(merge_result.is_ok());
|
assert!(merge_result.is_ok());
|
||||||
|
|
||||||
(dir, dir_str, engine_state, stack)
|
(dir, dir_str, engine_state, stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
// match a list of suggestions with the expected values
|
// match a list of suggestions with the expected values
|
||||||
pub fn match_suggestions(expected: Vec<String>, suggestions: Vec<Suggestion>) {
|
pub fn match_suggestions(expected: &Vec<String>, suggestions: &Vec<Suggestion>) {
|
||||||
let expected_len = expected.len();
|
let expected_len = expected.len();
|
||||||
let suggestions_len = suggestions.len();
|
let suggestions_len = suggestions.len();
|
||||||
if expected_len != suggestions_len {
|
if expected_len != suggestions_len {
|
||||||
@ -149,22 +196,25 @@ pub fn match_suggestions(expected: Vec<String>, suggestions: Vec<Suggestion>) {
|
|||||||
Expected: {expected:#?}\n"
|
Expected: {expected:#?}\n"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
expected.iter().zip(suggestions).for_each(|it| {
|
|
||||||
assert_eq!(it.0, &it.1.value);
|
let suggestoins_str = suggestions
|
||||||
});
|
.iter()
|
||||||
|
.map(|it| it.value.clone())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
assert_eq!(expected, &suggestoins_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// append the separator to the converted path
|
// append the separator to the converted path
|
||||||
pub fn folder(path: PathBuf) -> String {
|
pub fn folder(path: impl Into<PathBuf>) -> String {
|
||||||
let mut converted_path = file(path);
|
let mut converted_path = file(path);
|
||||||
converted_path.push(MAIN_SEPARATOR);
|
converted_path.push(MAIN_SEPARATOR);
|
||||||
|
|
||||||
converted_path
|
converted_path
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert a given path to string
|
// convert a given path to string
|
||||||
pub fn file(path: PathBuf) -> String {
|
pub fn file(path: impl Into<PathBuf>) -> String {
|
||||||
path.into_os_string().into_string().unwrap_or_default()
|
path.into().into_os_string().into_string().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge_input executes the given input into the engine
|
// merge_input executes the given input into the engine
|
||||||
@ -173,7 +223,6 @@ pub fn merge_input(
|
|||||||
input: &[u8],
|
input: &[u8],
|
||||||
engine_state: &mut EngineState,
|
engine_state: &mut EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
dir: PathBuf,
|
|
||||||
) -> Result<(), ShellError> {
|
) -> Result<(), ShellError> {
|
||||||
let (block, delta) = {
|
let (block, delta) = {
|
||||||
let mut working_set = StateWorkingSet::new(engine_state);
|
let mut working_set = StateWorkingSet::new(engine_state);
|
||||||
@ -196,5 +245,5 @@ pub fn merge_input(
|
|||||||
.is_ok());
|
.is_ok());
|
||||||
|
|
||||||
// Merge environment into the permanent state
|
// Merge environment into the permanent state
|
||||||
engine_state.merge_env(stack, &dir)
|
engine_state.merge_env(stack)
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,18 @@ edition = "2021"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "nu-cmd-base"
|
name = "nu-cmd-base"
|
||||||
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-base"
|
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-base"
|
||||||
version = "0.94.2"
|
version = "0.99.1"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nu-engine = { path = "../nu-engine", version = "0.94.2" }
|
nu-engine = { path = "../nu-engine", version = "0.99.1" }
|
||||||
nu-parser = { path = "../nu-parser", version = "0.94.2" }
|
nu-parser = { path = "../nu-parser", version = "0.99.1" }
|
||||||
nu-path = { path = "../nu-path", version = "0.94.2" }
|
nu-path = { path = "../nu-path", version = "0.99.1" }
|
||||||
nu-protocol = { path = "../nu-protocol", version = "0.94.2" }
|
nu-protocol = { path = "../nu-protocol", version = "0.99.1" }
|
||||||
|
|
||||||
indexmap = { workspace = true }
|
indexmap = { workspace = true }
|
||||||
miette = { workspace = true }
|
miette = { workspace = true }
|
||||||
|
5
crates/nu-cmd-base/README.md
Normal file
5
crates/nu-cmd-base/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Utilities used by the different `nu-command`/`nu-cmd-*` crates, should not contain any full `Command` implementations.
|
||||||
|
|
||||||
|
## Internal Nushell crate
|
||||||
|
|
||||||
|
This crate implements components of Nushell and is not designed to support plugin authors or other users directly.
|
@ -1,9 +1,8 @@
|
|||||||
use crate::util::get_guaranteed_cwd;
|
|
||||||
use miette::Result;
|
use miette::Result;
|
||||||
use nu_engine::{eval_block, eval_block_with_early_return};
|
use nu_engine::{eval_block, eval_block_with_early_return};
|
||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
cli_error::{report_error, report_error_new},
|
cli_error::{report_parse_error, report_shell_error},
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{Closure, EngineState, Stack, StateWorkingSet},
|
engine::{Closure, EngineState, Stack, StateWorkingSet},
|
||||||
PipelineData, PositionalArg, ShellError, Span, Type, Value, VarId,
|
PipelineData, PositionalArg, ShellError, Span, Type, Value, VarId,
|
||||||
@ -19,17 +18,12 @@ pub fn eval_env_change_hook(
|
|||||||
match hook {
|
match hook {
|
||||||
Value::Record { val, .. } => {
|
Value::Record { val, .. } => {
|
||||||
for (env_name, hook_value) in &*val {
|
for (env_name, hook_value) in &*val {
|
||||||
let before = engine_state
|
let before = engine_state.previous_env_vars.get(env_name);
|
||||||
.previous_env_vars
|
let after = stack.get_env_var(engine_state, env_name);
|
||||||
.get(env_name)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let after = stack
|
|
||||||
.get_env_var(engine_state, env_name)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
if before != after {
|
if before != after {
|
||||||
|
let before = before.cloned().unwrap_or_default();
|
||||||
|
let after = after.cloned().unwrap_or_default();
|
||||||
|
|
||||||
eval_hook(
|
eval_hook(
|
||||||
engine_state,
|
engine_state,
|
||||||
stack,
|
stack,
|
||||||
@ -40,7 +34,7 @@ pub fn eval_env_change_hook(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
Arc::make_mut(&mut engine_state.previous_env_vars)
|
Arc::make_mut(&mut engine_state.previous_env_vars)
|
||||||
.insert(env_name.to_string(), after);
|
.insert(env_name.clone(), after);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,12 +85,13 @@ pub fn eval_hook(
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
if let Some(err) = working_set.parse_errors.first() {
|
if let Some(err) = working_set.parse_errors.first() {
|
||||||
report_error(&working_set, err);
|
report_parse_error(&working_set, err);
|
||||||
|
return Err(ShellError::GenericError {
|
||||||
return Err(ShellError::UnsupportedConfigValue {
|
error: format!("Failed to run {hook_name} hook"),
|
||||||
expected: "valid source code".into(),
|
msg: "source code has errors".into(),
|
||||||
value: "source code with syntax errors".into(),
|
span: Some(span),
|
||||||
span,
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +118,7 @@ pub fn eval_hook(
|
|||||||
output = pipeline_data;
|
output = pipeline_data;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
report_error_new(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,10 +162,10 @@ pub fn eval_hook(
|
|||||||
{
|
{
|
||||||
val
|
val
|
||||||
} else {
|
} else {
|
||||||
return Err(ShellError::UnsupportedConfigValue {
|
return Err(ShellError::RuntimeTypeMismatch {
|
||||||
expected: "boolean output".to_string(),
|
expected: Type::Bool,
|
||||||
value: "other PipelineData variant".to_string(),
|
actual: pipeline_data.get_type(),
|
||||||
span: other_span,
|
span: pipeline_data.span().unwrap_or(other_span),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,9 +174,9 @@ pub fn eval_hook(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(ShellError::UnsupportedConfigValue {
|
return Err(ShellError::RuntimeTypeMismatch {
|
||||||
expected: "block".to_string(),
|
expected: Type::Closure,
|
||||||
value: format!("{}", condition.get_type()),
|
actual: condition.get_type(),
|
||||||
span: other_span,
|
span: other_span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -194,7 +189,7 @@ pub fn eval_hook(
|
|||||||
let Some(follow) = val.get("code") else {
|
let Some(follow) = val.get("code") else {
|
||||||
return Err(ShellError::CantFindColumn {
|
return Err(ShellError::CantFindColumn {
|
||||||
col_name: "code".into(),
|
col_name: "code".into(),
|
||||||
span,
|
span: Some(span),
|
||||||
src_span: span,
|
src_span: span,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -223,12 +218,13 @@ pub fn eval_hook(
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
if let Some(err) = working_set.parse_errors.first() {
|
if let Some(err) = working_set.parse_errors.first() {
|
||||||
report_error(&working_set, err);
|
report_parse_error(&working_set, err);
|
||||||
|
return Err(ShellError::GenericError {
|
||||||
return Err(ShellError::UnsupportedConfigValue {
|
error: format!("Failed to run {hook_name} hook"),
|
||||||
expected: "valid source code".into(),
|
msg: "source code has errors".into(),
|
||||||
value: "source code with syntax errors".into(),
|
span: Some(span),
|
||||||
span: source_span,
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +247,7 @@ pub fn eval_hook(
|
|||||||
output = pipeline_data;
|
output = pipeline_data;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
report_error_new(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,9 +259,9 @@ pub fn eval_hook(
|
|||||||
run_hook(engine_state, stack, val, input, arguments, source_span)?;
|
run_hook(engine_state, stack, val, input, arguments, source_span)?;
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
return Err(ShellError::UnsupportedConfigValue {
|
return Err(ShellError::RuntimeTypeMismatch {
|
||||||
expected: "block or string".to_string(),
|
expected: Type::custom("string or closure"),
|
||||||
value: format!("{}", other.get_type()),
|
actual: other.get_type(),
|
||||||
span: source_span,
|
span: source_span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -276,16 +272,15 @@ pub fn eval_hook(
|
|||||||
output = run_hook(engine_state, stack, val, input, arguments, span)?;
|
output = run_hook(engine_state, stack, val, input, arguments, span)?;
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
return Err(ShellError::UnsupportedConfigValue {
|
return Err(ShellError::RuntimeTypeMismatch {
|
||||||
expected: "string, block, record, or list of commands".into(),
|
expected: Type::custom("string, closure, record, or list"),
|
||||||
value: format!("{}", other.get_type()),
|
actual: other.get_type(),
|
||||||
span: other.span(),
|
span: other.span(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cwd = get_guaranteed_cwd(engine_state, stack);
|
engine_state.merge_env(stack)?;
|
||||||
engine_state.merge_env(stack, cwd)?;
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use nu_protocol::{ast::CellPath, PipelineData, ShellError, Span, Value};
|
use nu_protocol::{ast::CellPath, PipelineData, ShellError, Signals, Span, Value};
|
||||||
use std::sync::{atomic::AtomicBool, Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub trait CmdArgument {
|
pub trait CmdArgument {
|
||||||
fn take_cell_paths(&mut self) -> Option<Vec<CellPath>>;
|
fn take_cell_paths(&mut self) -> Option<Vec<CellPath>>;
|
||||||
@ -40,7 +40,7 @@ pub fn operate<C, A>(
|
|||||||
mut arg: A,
|
mut arg: A,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
span: Span,
|
span: Span,
|
||||||
ctrlc: Option<Arc<AtomicBool>>,
|
signals: &Signals,
|
||||||
) -> Result<PipelineData, ShellError>
|
) -> Result<PipelineData, ShellError>
|
||||||
where
|
where
|
||||||
A: CmdArgument + Send + Sync + 'static,
|
A: CmdArgument + Send + Sync + 'static,
|
||||||
@ -55,7 +55,7 @@ where
|
|||||||
_ => cmd(&v, &arg, span),
|
_ => cmd(&v, &arg, span),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ctrlc,
|
signals,
|
||||||
),
|
),
|
||||||
Some(column_paths) => {
|
Some(column_paths) => {
|
||||||
let arg = Arc::new(arg);
|
let arg = Arc::new(arg);
|
||||||
@ -79,7 +79,7 @@ where
|
|||||||
}
|
}
|
||||||
v
|
v
|
||||||
},
|
},
|
||||||
ctrlc,
|
signals,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![doc = include_str!("../README.md")]
|
||||||
pub mod formats;
|
pub mod formats;
|
||||||
pub mod hook;
|
pub mod hook;
|
||||||
pub mod input_handler;
|
pub mod input_handler;
|
||||||
|
@ -2,31 +2,18 @@ use nu_protocol::{
|
|||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
Range, ShellError, Span, Value,
|
Range, ShellError, Span, Value,
|
||||||
};
|
};
|
||||||
use std::{ops::Bound, path::PathBuf};
|
use std::ops::Bound;
|
||||||
|
|
||||||
pub fn get_init_cwd() -> PathBuf {
|
|
||||||
std::env::current_dir().unwrap_or_else(|_| {
|
|
||||||
std::env::var("PWD")
|
|
||||||
.map(Into::into)
|
|
||||||
.unwrap_or_else(|_| nu_path::home_dir().unwrap_or_default())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_guaranteed_cwd(engine_state: &EngineState, stack: &Stack) -> PathBuf {
|
|
||||||
engine_state
|
|
||||||
.cwd(Some(stack))
|
|
||||||
.unwrap_or(crate::util::get_init_cwd())
|
|
||||||
}
|
|
||||||
|
|
||||||
type MakeRangeError = fn(&str, Span) -> ShellError;
|
type MakeRangeError = fn(&str, Span) -> ShellError;
|
||||||
|
|
||||||
|
/// Returns a inclusive pair of boundary in given `range`.
|
||||||
pub fn process_range(range: &Range) -> Result<(isize, isize), MakeRangeError> {
|
pub fn process_range(range: &Range) -> Result<(isize, isize), MakeRangeError> {
|
||||||
match range {
|
match range {
|
||||||
Range::IntRange(range) => {
|
Range::IntRange(range) => {
|
||||||
let start = range.start().try_into().unwrap_or(0);
|
let start = range.start().try_into().unwrap_or(0);
|
||||||
let end = match range.end() {
|
let end = match range.end() {
|
||||||
Bound::Included(v) => (v + 1) as isize,
|
Bound::Included(v) => v as isize,
|
||||||
Bound::Excluded(v) => v as isize,
|
Bound::Excluded(v) => (v - 1) as isize,
|
||||||
Bound::Unbounded => isize::MAX,
|
Bound::Unbounded => isize::MAX,
|
||||||
};
|
};
|
||||||
Ok((start, end))
|
Ok((start, end))
|
||||||
|
@ -5,21 +5,24 @@ edition = "2021"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "nu-cmd-extra"
|
name = "nu-cmd-extra"
|
||||||
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-extra"
|
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-extra"
|
||||||
version = "0.94.2"
|
version = "0.99.1"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nu-cmd-base = { path = "../nu-cmd-base", version = "0.94.2" }
|
nu-cmd-base = { path = "../nu-cmd-base", version = "0.99.1" }
|
||||||
nu-engine = { path = "../nu-engine", version = "0.94.2" }
|
nu-engine = { path = "../nu-engine", version = "0.99.1" }
|
||||||
nu-json = { version = "0.94.2", path = "../nu-json" }
|
nu-json = { version = "0.99.1", path = "../nu-json" }
|
||||||
nu-parser = { path = "../nu-parser", version = "0.94.2" }
|
nu-parser = { path = "../nu-parser", version = "0.99.1" }
|
||||||
nu-pretty-hex = { version = "0.94.2", path = "../nu-pretty-hex" }
|
nu-pretty-hex = { version = "0.99.1", path = "../nu-pretty-hex" }
|
||||||
nu-protocol = { path = "../nu-protocol", version = "0.94.2" }
|
nu-protocol = { path = "../nu-protocol", version = "0.99.1" }
|
||||||
nu-utils = { path = "../nu-utils", version = "0.94.2" }
|
nu-utils = { path = "../nu-utils", version = "0.99.1" }
|
||||||
|
|
||||||
# Potential dependencies for extras
|
# Potential dependencies for extras
|
||||||
heck = { workspace = true }
|
heck = { workspace = true }
|
||||||
@ -32,11 +35,7 @@ serde_urlencoded = { workspace = true }
|
|||||||
v_htmlescape = { workspace = true }
|
v_htmlescape = { workspace = true }
|
||||||
itertools = { workspace = true }
|
itertools = { workspace = true }
|
||||||
|
|
||||||
[features]
|
|
||||||
extra = ["default"]
|
|
||||||
default = []
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.94.2" }
|
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.99.1" }
|
||||||
nu-command = { path = "../nu-command", version = "0.94.2" }
|
nu-command = { path = "../nu-command", version = "0.99.1" }
|
||||||
nu-test-support = { path = "../nu-test-support", version = "0.94.2" }
|
nu-test-support = { path = "../nu-test-support", version = "0.99.1" }
|
@ -37,7 +37,7 @@ impl Command for BitsAnd {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Performs bitwise and for ints or binary values."
|
"Performs bitwise and for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ impl Command for BitsAnd {
|
|||||||
|
|
||||||
input.map(
|
input.map(
|
||||||
move |value| binary_op(&value, &target, little_endian, |(l, r)| l & r, head),
|
move |value| binary_op(&value, &target, little_endian, |(l, r)| l & r, head),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ impl Command for Bits {
|
|||||||
.input_output_types(vec![(Type::Nothing, Type::String)])
|
.input_output_types(vec![(Type::Nothing, Type::String)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Various commands for working with bits."
|
"Various commands for working with bits."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_usage(&self) -> &str {
|
fn extra_description(&self) -> &str {
|
||||||
"You must use one of the following subcommands. Using this command as-is will only produce this help message."
|
"You must use one of the following subcommands. Using this command as-is will only produce this help message."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
use std::io::{self, Read, Write};
|
||||||
|
|
||||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
|
|
||||||
|
use nu_protocol::Signals;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
@ -42,7 +45,7 @@ impl Command for BitsInto {
|
|||||||
.category(Category::Conversions)
|
.category(Category::Conversions)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Convert value to a binary primitive."
|
"Convert value to a binary primitive."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,12 +121,43 @@ fn into_bits(
|
|||||||
let cell_paths = call.rest(engine_state, stack, 0)?;
|
let cell_paths = call.rest(engine_state, stack, 0)?;
|
||||||
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
|
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
|
||||||
|
|
||||||
if let PipelineData::ByteStream(stream, ..) = input {
|
if let PipelineData::ByteStream(stream, metadata) = input {
|
||||||
// TODO: in the future, we may want this to stream out, converting each to bytes
|
Ok(PipelineData::ByteStream(
|
||||||
Ok(Value::binary(stream.into_bytes()?, head).into_pipeline_data())
|
byte_stream_to_bits(stream, head),
|
||||||
|
metadata,
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
let args = Arguments { cell_paths };
|
let args = Arguments { cell_paths };
|
||||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
operate(action, args, input, call.head, engine_state.signals())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn byte_stream_to_bits(stream: ByteStream, head: Span) -> ByteStream {
|
||||||
|
if let Some(mut reader) = stream.reader() {
|
||||||
|
let mut is_first = true;
|
||||||
|
ByteStream::from_fn(
|
||||||
|
head,
|
||||||
|
Signals::empty(),
|
||||||
|
ByteStreamType::String,
|
||||||
|
move |buffer| {
|
||||||
|
let mut byte = [0];
|
||||||
|
if reader.read(&mut byte[..]).err_span(head)? > 0 {
|
||||||
|
// Format the byte as bits
|
||||||
|
if is_first {
|
||||||
|
is_first = false;
|
||||||
|
} else {
|
||||||
|
buffer.push(b' ');
|
||||||
|
}
|
||||||
|
write!(buffer, "{:08b}", byte[0]).expect("format failed");
|
||||||
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
// EOF
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ByteStream::read(io::empty(), head, Signals::empty(), ByteStreamType::String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,25 @@ enum InputNumType {
|
|||||||
SignedEight,
|
SignedEight,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InputNumType {
|
||||||
|
fn num_bits(self) -> u32 {
|
||||||
|
match self {
|
||||||
|
InputNumType::One => 8,
|
||||||
|
InputNumType::Two => 16,
|
||||||
|
InputNumType::Four => 32,
|
||||||
|
InputNumType::Eight => 64,
|
||||||
|
InputNumType::SignedOne => 8,
|
||||||
|
InputNumType::SignedTwo => 16,
|
||||||
|
InputNumType::SignedFour => 32,
|
||||||
|
InputNumType::SignedEight => 64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_permitted_bit_shift(self, bits: u32) -> bool {
|
||||||
|
bits < self.num_bits()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_number_bytes(
|
fn get_number_bytes(
|
||||||
number_bytes: Option<Spanned<usize>>,
|
number_bytes: Option<Spanned<usize>>,
|
||||||
head: Span,
|
head: Span,
|
||||||
|
@ -51,7 +51,7 @@ impl Command for BitsNot {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Performs logical negation on each bit."
|
"Performs logical negation on each bit."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ impl Command for BitsNot {
|
|||||||
number_size,
|
number_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
operate(action, args, input, head, engine_state.signals())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -38,7 +38,7 @@ impl Command for BitsOr {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Performs bitwise or for ints or binary values."
|
"Performs bitwise or for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ impl Command for BitsOr {
|
|||||||
|
|
||||||
input.map(
|
input.map(
|
||||||
move |value| binary_op(&value, &target, little_endian, |(l, r)| l | r, head),
|
move |value| binary_op(&value, &target, little_endian, |(l, r)| l | r, head),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
|
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
|
||||||
use itertools::Itertools;
|
|
||||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
|
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
signed: bool,
|
signed: bool,
|
||||||
bits: usize,
|
bits: Spanned<usize>,
|
||||||
number_size: NumberBytes,
|
number_size: NumberBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ impl Command for BitsRol {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Bitwise rotate left for ints or binary values."
|
"Bitwise rotate left for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ impl Command for BitsRol {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let bits: usize = call.req(engine_state, stack, 0)?;
|
let bits = call.req(engine_state, stack, 0)?;
|
||||||
let signed = call.has_flag(engine_state, stack, "signed")?;
|
let signed = call.has_flag(engine_state, stack, "signed")?;
|
||||||
let number_bytes: Option<Spanned<usize>> =
|
let number_bytes: Option<Spanned<usize>> =
|
||||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||||
@ -86,7 +85,7 @@ impl Command for BitsRol {
|
|||||||
bits,
|
bits,
|
||||||
};
|
};
|
||||||
|
|
||||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
operate(action, args, input, head, engine_state.signals())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
@ -119,6 +118,8 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
number_size,
|
number_size,
|
||||||
bits,
|
bits,
|
||||||
} = *args;
|
} = *args;
|
||||||
|
let bits_span = bits.span;
|
||||||
|
let bits = bits.item;
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
Value::Int { val, .. } => {
|
Value::Int { val, .. } => {
|
||||||
@ -127,6 +128,19 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
let bits = bits as u32;
|
let bits = bits as u32;
|
||||||
let input_num_type = get_input_num_type(val, signed, number_size);
|
let input_num_type = get_input_num_type(val, signed, number_size);
|
||||||
|
|
||||||
|
if bits > input_num_type.num_bits() {
|
||||||
|
return Value::error(
|
||||||
|
ShellError::IncorrectValue {
|
||||||
|
msg: format!(
|
||||||
|
"Trying to rotate by more than the available bits ({})",
|
||||||
|
input_num_type.num_bits()
|
||||||
|
),
|
||||||
|
val_span: bits_span,
|
||||||
|
call_span: span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
let int = match input_num_type {
|
let int = match input_num_type {
|
||||||
One => (val as u8).rotate_left(bits) as i64,
|
One => (val as u8).rotate_left(bits) as i64,
|
||||||
Two => (val as u16).rotate_left(bits) as i64,
|
Two => (val as u16).rotate_left(bits) as i64,
|
||||||
@ -157,16 +171,28 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
Value::int(int, span)
|
Value::int(int, span)
|
||||||
}
|
}
|
||||||
Value::Binary { val, .. } => {
|
Value::Binary { val, .. } => {
|
||||||
|
let len = val.len();
|
||||||
|
if bits > len * 8 {
|
||||||
|
return Value::error(
|
||||||
|
ShellError::IncorrectValue {
|
||||||
|
msg: format!(
|
||||||
|
"Trying to rotate by more than the available bits ({})",
|
||||||
|
len * 8
|
||||||
|
),
|
||||||
|
val_span: bits_span,
|
||||||
|
call_span: span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
let byte_shift = bits / 8;
|
let byte_shift = bits / 8;
|
||||||
let bit_rotate = bits % 8;
|
let bit_rotate = bits % 8;
|
||||||
|
|
||||||
let mut bytes = val
|
let bytes = if bit_rotate == 0 {
|
||||||
.iter()
|
rotate_bytes_left(val, byte_shift)
|
||||||
.copied()
|
} else {
|
||||||
.circular_tuple_windows::<(u8, u8)>()
|
rotate_bytes_and_bits_left(val, byte_shift, bit_rotate)
|
||||||
.map(|(lhs, rhs)| (lhs << bit_rotate) | (rhs >> (8 - bit_rotate)))
|
};
|
||||||
.collect::<Vec<u8>>();
|
|
||||||
bytes.rotate_left(byte_shift);
|
|
||||||
|
|
||||||
Value::binary(bytes, span)
|
Value::binary(bytes, span)
|
||||||
}
|
}
|
||||||
@ -184,6 +210,34 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rotate_bytes_left(data: &[u8], byte_shift: usize) -> Vec<u8> {
|
||||||
|
let len = data.len();
|
||||||
|
let mut output = vec![0; len];
|
||||||
|
output[..len - byte_shift].copy_from_slice(&data[byte_shift..]);
|
||||||
|
output[len - byte_shift..].copy_from_slice(&data[..byte_shift]);
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rotate_bytes_and_bits_left(data: &[u8], byte_shift: usize, bit_shift: usize) -> Vec<u8> {
|
||||||
|
debug_assert!(byte_shift < data.len());
|
||||||
|
debug_assert!(
|
||||||
|
(1..8).contains(&bit_shift),
|
||||||
|
"Bit shifts of 0 can't be handled by this impl and everything else should be part of the byteshift");
|
||||||
|
let mut bytes = Vec::with_capacity(data.len());
|
||||||
|
let mut next_index = byte_shift;
|
||||||
|
for _ in 0..data.len() {
|
||||||
|
let curr_byte = data[next_index];
|
||||||
|
next_index += 1;
|
||||||
|
if next_index == data.len() {
|
||||||
|
next_index = 0;
|
||||||
|
}
|
||||||
|
let next_byte = data[next_index];
|
||||||
|
let new_byte = (curr_byte << bit_shift) | (next_byte >> (8 - bit_shift));
|
||||||
|
bytes.push(new_byte);
|
||||||
|
}
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
|
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
|
||||||
use itertools::Itertools;
|
|
||||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
|
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
signed: bool,
|
signed: bool,
|
||||||
bits: usize,
|
bits: Spanned<usize>,
|
||||||
number_size: NumberBytes,
|
number_size: NumberBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ impl Command for BitsRor {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Bitwise rotate right for ints or binary values."
|
"Bitwise rotate right for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ impl Command for BitsRor {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let bits: usize = call.req(engine_state, stack, 0)?;
|
let bits = call.req(engine_state, stack, 0)?;
|
||||||
let signed = call.has_flag(engine_state, stack, "signed")?;
|
let signed = call.has_flag(engine_state, stack, "signed")?;
|
||||||
let number_bytes: Option<Spanned<usize>> =
|
let number_bytes: Option<Spanned<usize>> =
|
||||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||||
@ -86,7 +85,7 @@ impl Command for BitsRor {
|
|||||||
bits,
|
bits,
|
||||||
};
|
};
|
||||||
|
|
||||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
operate(action, args, input, head, engine_state.signals())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
@ -123,6 +122,8 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
number_size,
|
number_size,
|
||||||
bits,
|
bits,
|
||||||
} = *args;
|
} = *args;
|
||||||
|
let bits_span = bits.span;
|
||||||
|
let bits = bits.item;
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
Value::Int { val, .. } => {
|
Value::Int { val, .. } => {
|
||||||
@ -131,6 +132,19 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
let bits = bits as u32;
|
let bits = bits as u32;
|
||||||
let input_num_type = get_input_num_type(val, signed, number_size);
|
let input_num_type = get_input_num_type(val, signed, number_size);
|
||||||
|
|
||||||
|
if bits > input_num_type.num_bits() {
|
||||||
|
return Value::error(
|
||||||
|
ShellError::IncorrectValue {
|
||||||
|
msg: format!(
|
||||||
|
"Trying to rotate by more than the available bits ({})",
|
||||||
|
input_num_type.num_bits()
|
||||||
|
),
|
||||||
|
val_span: bits_span,
|
||||||
|
call_span: span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
let int = match input_num_type {
|
let int = match input_num_type {
|
||||||
One => (val as u8).rotate_right(bits) as i64,
|
One => (val as u8).rotate_right(bits) as i64,
|
||||||
Two => (val as u16).rotate_right(bits) as i64,
|
Two => (val as u16).rotate_right(bits) as i64,
|
||||||
@ -161,16 +175,28 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
Value::int(int, span)
|
Value::int(int, span)
|
||||||
}
|
}
|
||||||
Value::Binary { val, .. } => {
|
Value::Binary { val, .. } => {
|
||||||
|
let len = val.len();
|
||||||
|
if bits > len * 8 {
|
||||||
|
return Value::error(
|
||||||
|
ShellError::IncorrectValue {
|
||||||
|
msg: format!(
|
||||||
|
"Trying to rotate by more than the available bits ({})",
|
||||||
|
len * 8
|
||||||
|
),
|
||||||
|
val_span: bits_span,
|
||||||
|
call_span: span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
let byte_shift = bits / 8;
|
let byte_shift = bits / 8;
|
||||||
let bit_rotate = bits % 8;
|
let bit_rotate = bits % 8;
|
||||||
|
|
||||||
let mut bytes = val
|
let bytes = if bit_rotate == 0 {
|
||||||
.iter()
|
rotate_bytes_right(val, byte_shift)
|
||||||
.copied()
|
} else {
|
||||||
.circular_tuple_windows::<(u8, u8)>()
|
rotate_bytes_and_bits_right(val, byte_shift, bit_rotate)
|
||||||
.map(|(lhs, rhs)| (lhs >> bit_rotate) | (rhs << (8 - bit_rotate)))
|
};
|
||||||
.collect::<Vec<u8>>();
|
|
||||||
bytes.rotate_right(byte_shift);
|
|
||||||
|
|
||||||
Value::binary(bytes, span)
|
Value::binary(bytes, span)
|
||||||
}
|
}
|
||||||
@ -188,6 +214,35 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rotate_bytes_right(data: &[u8], byte_shift: usize) -> Vec<u8> {
|
||||||
|
let len = data.len();
|
||||||
|
let mut output = vec![0; len];
|
||||||
|
output[byte_shift..].copy_from_slice(&data[..len - byte_shift]);
|
||||||
|
output[..byte_shift].copy_from_slice(&data[len - byte_shift..]);
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rotate_bytes_and_bits_right(data: &[u8], byte_shift: usize, bit_shift: usize) -> Vec<u8> {
|
||||||
|
debug_assert!(byte_shift < data.len());
|
||||||
|
debug_assert!(
|
||||||
|
(1..8).contains(&bit_shift),
|
||||||
|
"Bit shifts of 0 can't be handled by this impl and everything else should be part of the byteshift"
|
||||||
|
);
|
||||||
|
let mut bytes = Vec::with_capacity(data.len());
|
||||||
|
let mut previous_index = data.len() - byte_shift - 1;
|
||||||
|
for _ in 0..data.len() {
|
||||||
|
let previous_byte = data[previous_index];
|
||||||
|
previous_index += 1;
|
||||||
|
if previous_index == data.len() {
|
||||||
|
previous_index = 0;
|
||||||
|
}
|
||||||
|
let curr_byte = data[previous_index];
|
||||||
|
let rotated_byte = (curr_byte >> bit_shift) | (previous_byte << (8 - bit_shift));
|
||||||
|
bytes.push(rotated_byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes
|
||||||
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -7,7 +7,7 @@ use std::iter;
|
|||||||
|
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
signed: bool,
|
signed: bool,
|
||||||
bits: usize,
|
bits: Spanned<usize>,
|
||||||
number_size: NumberBytes,
|
number_size: NumberBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ impl Command for BitsShl {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Bitwise shift left for ints or binary values."
|
"Bitwise shift left for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,9 @@ impl Command for BitsShl {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let bits: usize = call.req(engine_state, stack, 0)?;
|
// This restricts to a positive shift value (our underlying operations do not
|
||||||
|
// permit them)
|
||||||
|
let bits: Spanned<usize> = call.req(engine_state, stack, 0)?;
|
||||||
let signed = call.has_flag(engine_state, stack, "signed")?;
|
let signed = call.has_flag(engine_state, stack, "signed")?;
|
||||||
let number_bytes: Option<Spanned<usize>> =
|
let number_bytes: Option<Spanned<usize>> =
|
||||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||||
@ -88,7 +90,7 @@ impl Command for BitsShl {
|
|||||||
bits,
|
bits,
|
||||||
};
|
};
|
||||||
|
|
||||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
operate(action, args, input, head, engine_state.signals())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
@ -131,14 +133,29 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
number_size,
|
number_size,
|
||||||
bits,
|
bits,
|
||||||
} = *args;
|
} = *args;
|
||||||
|
let bits_span = bits.span;
|
||||||
|
let bits = bits.item;
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
Value::Int { val, .. } => {
|
Value::Int { val, .. } => {
|
||||||
use InputNumType::*;
|
use InputNumType::*;
|
||||||
let val = *val;
|
let val = *val;
|
||||||
let bits = bits as u64;
|
let bits = bits as u32;
|
||||||
|
|
||||||
let input_num_type = get_input_num_type(val, signed, number_size);
|
let input_num_type = get_input_num_type(val, signed, number_size);
|
||||||
|
if !input_num_type.is_permitted_bit_shift(bits) {
|
||||||
|
return Value::error(
|
||||||
|
ShellError::IncorrectValue {
|
||||||
|
msg: format!(
|
||||||
|
"Trying to shift by more than the available bits (permitted < {})",
|
||||||
|
input_num_type.num_bits()
|
||||||
|
),
|
||||||
|
val_span: bits_span,
|
||||||
|
call_span: span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
let int = match input_num_type {
|
let int = match input_num_type {
|
||||||
One => ((val as u8) << bits) as i64,
|
One => ((val as u8) << bits) as i64,
|
||||||
Two => ((val as u16) << bits) as i64,
|
Two => ((val as u16) << bits) as i64,
|
||||||
@ -147,12 +164,14 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
let Ok(i) = i64::try_from((val as u64) << bits) else {
|
let Ok(i) = i64::try_from((val as u64) << bits) else {
|
||||||
return Value::error(
|
return Value::error(
|
||||||
ShellError::GenericError {
|
ShellError::GenericError {
|
||||||
error: "result out of range for specified number".into(),
|
error: "result out of range for int".into(),
|
||||||
msg: format!(
|
msg: format!(
|
||||||
"shifting left by {bits} is out of range for the value {val}"
|
"shifting left by {bits} is out of range for the value {val}"
|
||||||
),
|
),
|
||||||
span: Some(span),
|
span: Some(span),
|
||||||
help: None,
|
help: Some(
|
||||||
|
"Ensure the result fits in a 64-bit signed integer.".into(),
|
||||||
|
),
|
||||||
inner: vec![],
|
inner: vec![],
|
||||||
},
|
},
|
||||||
span,
|
span,
|
||||||
@ -172,19 +191,26 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
let byte_shift = bits / 8;
|
let byte_shift = bits / 8;
|
||||||
let bit_shift = bits % 8;
|
let bit_shift = bits % 8;
|
||||||
|
|
||||||
use itertools::Position::*;
|
// This is purely for symmetry with the int case and the fact that the
|
||||||
let bytes = val
|
// shift right implementation in its current form panicked with an overflow
|
||||||
.iter()
|
if bits > val.len() * 8 {
|
||||||
.copied()
|
return Value::error(
|
||||||
.skip(byte_shift)
|
ShellError::IncorrectValue {
|
||||||
.circular_tuple_windows::<(u8, u8)>()
|
msg: format!(
|
||||||
.with_position()
|
"Trying to shift by more than the available bits ({})",
|
||||||
.map(|(pos, (lhs, rhs))| match pos {
|
val.len() * 8
|
||||||
Last | Only => lhs << bit_shift,
|
),
|
||||||
_ => (lhs << bit_shift) | (rhs >> bit_shift),
|
val_span: bits_span,
|
||||||
})
|
call_span: span,
|
||||||
.chain(iter::repeat(0).take(byte_shift))
|
},
|
||||||
.collect::<Vec<u8>>();
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let bytes = if bit_shift == 0 {
|
||||||
|
shift_bytes_left(val, byte_shift)
|
||||||
|
} else {
|
||||||
|
shift_bytes_and_bits_left(val, byte_shift, bit_shift)
|
||||||
|
};
|
||||||
|
|
||||||
Value::binary(bytes, span)
|
Value::binary(bytes, span)
|
||||||
}
|
}
|
||||||
@ -202,6 +228,31 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn shift_bytes_left(data: &[u8], byte_shift: usize) -> Vec<u8> {
|
||||||
|
let len = data.len();
|
||||||
|
let mut output = vec![0; len];
|
||||||
|
output[..len - byte_shift].copy_from_slice(&data[byte_shift..]);
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shift_bytes_and_bits_left(data: &[u8], byte_shift: usize, bit_shift: usize) -> Vec<u8> {
|
||||||
|
use itertools::Position::*;
|
||||||
|
debug_assert!((1..8).contains(&bit_shift),
|
||||||
|
"Bit shifts of 0 can't be handled by this impl and everything else should be part of the byteshift"
|
||||||
|
);
|
||||||
|
data.iter()
|
||||||
|
.copied()
|
||||||
|
.skip(byte_shift)
|
||||||
|
.circular_tuple_windows::<(u8, u8)>()
|
||||||
|
.with_position()
|
||||||
|
.map(|(pos, (lhs, rhs))| match pos {
|
||||||
|
Last | Only => lhs << bit_shift,
|
||||||
|
_ => (lhs << bit_shift) | (rhs >> (8 - bit_shift)),
|
||||||
|
})
|
||||||
|
.chain(iter::repeat(0).take(byte_shift))
|
||||||
|
.collect::<Vec<u8>>()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
|
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
|
||||||
use itertools::Itertools;
|
|
||||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
|
|
||||||
use std::iter;
|
|
||||||
|
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
signed: bool,
|
signed: bool,
|
||||||
bits: usize,
|
bits: Spanned<usize>,
|
||||||
number_size: NumberBytes,
|
number_size: NumberBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +52,7 @@ impl Command for BitsShr {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Bitwise shift right for ints or binary values."
|
"Bitwise shift right for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +68,9 @@ impl Command for BitsShr {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let bits: usize = call.req(engine_state, stack, 0)?;
|
// This restricts to a positive shift value (our underlying operations do not
|
||||||
|
// permit them)
|
||||||
|
let bits: Spanned<usize> = call.req(engine_state, stack, 0)?;
|
||||||
let signed = call.has_flag(engine_state, stack, "signed")?;
|
let signed = call.has_flag(engine_state, stack, "signed")?;
|
||||||
let number_bytes: Option<Spanned<usize>> =
|
let number_bytes: Option<Spanned<usize>> =
|
||||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||||
@ -88,7 +87,7 @@ impl Command for BitsShr {
|
|||||||
bits,
|
bits,
|
||||||
};
|
};
|
||||||
|
|
||||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
operate(action, args, input, head, engine_state.signals())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
@ -121,6 +120,8 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
number_size,
|
number_size,
|
||||||
bits,
|
bits,
|
||||||
} = *args;
|
} = *args;
|
||||||
|
let bits_span = bits.span;
|
||||||
|
let bits = bits.item;
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
Value::Int { val, .. } => {
|
Value::Int { val, .. } => {
|
||||||
@ -129,6 +130,19 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
let bits = bits as u32;
|
let bits = bits as u32;
|
||||||
let input_num_type = get_input_num_type(val, signed, number_size);
|
let input_num_type = get_input_num_type(val, signed, number_size);
|
||||||
|
|
||||||
|
if !input_num_type.is_permitted_bit_shift(bits) {
|
||||||
|
return Value::error(
|
||||||
|
ShellError::IncorrectValue {
|
||||||
|
msg: format!(
|
||||||
|
"Trying to shift by more than the available bits (permitted < {})",
|
||||||
|
input_num_type.num_bits()
|
||||||
|
),
|
||||||
|
val_span: bits_span,
|
||||||
|
call_span: span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
);
|
||||||
|
}
|
||||||
let int = match input_num_type {
|
let int = match input_num_type {
|
||||||
One => ((val as u8) >> bits) as i64,
|
One => ((val as u8) >> bits) as i64,
|
||||||
Two => ((val as u16) >> bits) as i64,
|
Two => ((val as u16) >> bits) as i64,
|
||||||
@ -147,21 +161,27 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
let bit_shift = bits % 8;
|
let bit_shift = bits % 8;
|
||||||
|
|
||||||
let len = val.len();
|
let len = val.len();
|
||||||
use itertools::Position::*;
|
// This check is done for symmetry with the int case and the previous
|
||||||
let bytes = iter::repeat(0)
|
// implementation would overflow byte indices leading to unexpected output
|
||||||
.take(byte_shift)
|
// lengths
|
||||||
.chain(
|
if bits > len * 8 {
|
||||||
val.iter()
|
return Value::error(
|
||||||
.copied()
|
ShellError::IncorrectValue {
|
||||||
.circular_tuple_windows::<(u8, u8)>()
|
msg: format!(
|
||||||
.with_position()
|
"Trying to shift by more than the available bits ({})",
|
||||||
.map(|(pos, (lhs, rhs))| match pos {
|
len * 8
|
||||||
First | Only => lhs >> bit_shift,
|
),
|
||||||
_ => (lhs >> bit_shift) | (rhs << bit_shift),
|
val_span: bits_span,
|
||||||
})
|
call_span: span,
|
||||||
.take(len - byte_shift),
|
},
|
||||||
)
|
span,
|
||||||
.collect::<Vec<u8>>();
|
);
|
||||||
|
}
|
||||||
|
let bytes = if bit_shift == 0 {
|
||||||
|
shift_bytes_right(val, byte_shift)
|
||||||
|
} else {
|
||||||
|
shift_bytes_and_bits_right(val, byte_shift, bit_shift)
|
||||||
|
};
|
||||||
|
|
||||||
Value::binary(bytes, span)
|
Value::binary(bytes, span)
|
||||||
}
|
}
|
||||||
@ -178,6 +198,35 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn shift_bytes_right(data: &[u8], byte_shift: usize) -> Vec<u8> {
|
||||||
|
let len = data.len();
|
||||||
|
let mut output = vec![0; len];
|
||||||
|
output[byte_shift..].copy_from_slice(&data[..len - byte_shift]);
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shift_bytes_and_bits_right(data: &[u8], byte_shift: usize, bit_shift: usize) -> Vec<u8> {
|
||||||
|
debug_assert!(
|
||||||
|
bit_shift > 0 && bit_shift < 8,
|
||||||
|
"bit_shift should be in the range (0, 8)"
|
||||||
|
);
|
||||||
|
let len = data.len();
|
||||||
|
let mut output = vec![0; len];
|
||||||
|
|
||||||
|
for i in byte_shift..len {
|
||||||
|
let shifted_bits = data[i - byte_shift] >> bit_shift;
|
||||||
|
let carried_bits = if i > byte_shift {
|
||||||
|
data[i - byte_shift - 1] << (8 - bit_shift)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
let shifted_byte = shifted_bits | carried_bits;
|
||||||
|
|
||||||
|
output[i] = shifted_byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
@ -38,7 +38,7 @@ impl Command for BitsXor {
|
|||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Performs bitwise xor for ints or binary values."
|
"Performs bitwise xor for ints or binary values."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ impl Command for BitsXor {
|
|||||||
|
|
||||||
input.map(
|
input.map(
|
||||||
move |value| binary_op(&value, &target, little_endian, |(l, r)| l ^ r, head),
|
move |value| binary_op(&value, &target, little_endian, |(l, r)| l ^ r, head),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ impl Command for Fmt {
|
|||||||
"fmt"
|
"fmt"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Format a number."
|
"Format a number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ fn fmt(
|
|||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
||||||
let args = CellPathOnlyArgs::from(cell_paths);
|
let args = CellPathOnlyArgs::from(cell_paths);
|
||||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
operate(action, args, input, call.head, engine_state.signals())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||||
|
@ -9,7 +9,7 @@ impl Command for EachWhile {
|
|||||||
"each while"
|
"each while"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Run a closure on each row of the input list until a null is found, then create a new list with the results."
|
"Run a closure on each row of the input list until a null is found, then create a new list with the results."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ impl Command for EachWhile {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fuse()
|
.fuse()
|
||||||
.into_pipeline_data(head, engine_state.ctrlc.clone()))
|
.into_pipeline_data(head, engine_state.signals().clone()))
|
||||||
}
|
}
|
||||||
PipelineData::ByteStream(stream, ..) => {
|
PipelineData::ByteStream(stream, ..) => {
|
||||||
let span = stream.span();
|
let span = stream.span();
|
||||||
@ -107,7 +107,7 @@ impl Command for EachWhile {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fuse()
|
.fuse()
|
||||||
.into_pipeline_data(head, engine_state.ctrlc.clone()))
|
.into_pipeline_data(head, engine_state.signals().clone()))
|
||||||
} else {
|
} else {
|
||||||
Ok(PipelineData::Empty)
|
Ok(PipelineData::Empty)
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ impl Command for Roll {
|
|||||||
.input_output_types(vec![(Type::Nothing, Type::String)])
|
.input_output_types(vec![(Type::Nothing, Type::String)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Rolling commands for tables."
|
"Rolling commands for tables."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_usage(&self) -> &str {
|
fn extra_description(&self) -> &str {
|
||||||
"You must use one of the following subcommands. Using this command as-is will only produce this help message."
|
"You must use one of the following subcommands. Using this command as-is will only produce this help message."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for RollDown {
|
|||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Roll table rows down."
|
"Roll table rows down."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ impl Command for RollLeft {
|
|||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Roll record or table columns left."
|
"Roll record or table columns left."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ impl Command for RollRight {
|
|||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Roll table columns right."
|
"Roll table columns right."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for RollUp {
|
|||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Roll table rows up."
|
"Roll table rows up."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ impl Command for Rotate {
|
|||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Rotates a table or record clockwise (default) or counter-clockwise (use --ccw flag)."
|
"Rotates a table or record clockwise (default) or counter-clockwise (use --ccw flag)."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ impl Command for UpdateCells {
|
|||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Update the table cells."
|
"Update the table cells."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ impl Command for UpdateCells {
|
|||||||
columns,
|
columns,
|
||||||
span: head,
|
span: head,
|
||||||
}
|
}
|
||||||
.into_pipeline_data(head, engine_state.ctrlc.clone())
|
.into_pipeline_data(head, engine_state.signals().clone())
|
||||||
.set_metadata(metadata))
|
.set_metadata(metadata))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ impl Command for FromUrl {
|
|||||||
.category(Category::Formats)
|
.category(Category::Formats)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Parse url-encoded string as a record."
|
"Parse url-encoded string as a record."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,11 +138,11 @@ impl Command for ToHtml {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Convert table into simple HTML."
|
"Convert table into simple HTML."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_usage(&self) -> &str {
|
fn extra_description(&self) -> &str {
|
||||||
"Screenshots of the themes can be browsed here: https://github.com/mbadolato/iTerm2-Color-Schemes."
|
"Screenshots of the themes can be browsed here: https://github.com/mbadolato/iTerm2-Color-Schemes."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ fn to_html(
|
|||||||
let partial = call.has_flag(engine_state, stack, "partial")?;
|
let partial = call.has_flag(engine_state, stack, "partial")?;
|
||||||
let list = call.has_flag(engine_state, stack, "list")?;
|
let list = call.has_flag(engine_state, stack, "list")?;
|
||||||
let theme: Option<Spanned<String>> = call.get_flag(engine_state, stack, "theme")?;
|
let theme: Option<Spanned<String>> = call.get_flag(engine_state, stack, "theme")?;
|
||||||
let config = engine_state.get_config();
|
let config = &stack.get_config(engine_state);
|
||||||
|
|
||||||
let vec_of_values = input.into_iter().collect::<Vec<Value>>();
|
let vec_of_values = input.into_iter().collect::<Vec<Value>>();
|
||||||
let headers = merge_descriptors(&vec_of_values);
|
let headers = merge_descriptors(&vec_of_values);
|
||||||
@ -368,6 +368,7 @@ fn theme_demo(span: Span) -> PipelineData {
|
|||||||
.collect();
|
.collect();
|
||||||
Value::list(result, span).into_pipeline_data_with_metadata(PipelineMetadata {
|
Value::list(result, span).into_pipeline_data_with_metadata(PipelineMetadata {
|
||||||
data_source: DataSource::HtmlThemes,
|
data_source: DataSource::HtmlThemes,
|
||||||
|
content_type: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the arccosine of the number."
|
"Returns the arccosine of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ impl Command for SubCommand {
|
|||||||
}
|
}
|
||||||
input.map(
|
input.map(
|
||||||
move |value| operate(value, head, use_degrees),
|
move |value| operate(value, head, use_degrees),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the inverse of the hyperbolic cosine function."
|
"Returns the inverse of the hyperbolic cosine function."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -22,7 +22,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the arcsine of the number."
|
"Returns the arcsine of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ impl Command for SubCommand {
|
|||||||
}
|
}
|
||||||
input.map(
|
input.map(
|
||||||
move |value| operate(value, head, use_degrees),
|
move |value| operate(value, head, use_degrees),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the inverse of the hyperbolic sine function."
|
"Returns the inverse of the hyperbolic sine function."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -22,7 +22,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the arctangent of the number."
|
"Returns the arctangent of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ impl Command for SubCommand {
|
|||||||
}
|
}
|
||||||
input.map(
|
input.map(
|
||||||
move |value| operate(value, head, use_degrees),
|
move |value| operate(value, head, use_degrees),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the inverse of the hyperbolic tangent function."
|
"Returns the inverse of the hyperbolic tangent function."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the cosine of the number."
|
"Returns the cosine of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl Command for SubCommand {
|
|||||||
}
|
}
|
||||||
input.map(
|
input.map(
|
||||||
move |value| operate(value, head, use_degrees),
|
move |value| operate(value, head, use_degrees),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the hyperbolic cosine of the number."
|
"Returns the hyperbolic cosine of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns e raised to the power of x."
|
"Returns e raised to the power of x."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the natural logarithm. Base: (math e)."
|
"Returns the natural logarithm. Base: (math e)."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the sine of the number."
|
"Returns the sine of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl Command for SubCommand {
|
|||||||
}
|
}
|
||||||
input.map(
|
input.map(
|
||||||
move |value| operate(value, head, use_degrees),
|
move |value| operate(value, head, use_degrees),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the hyperbolic sine of the number."
|
"Returns the hyperbolic sine of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,7 @@ impl Command for SubCommand {
|
|||||||
if matches!(input, PipelineData::Empty) {
|
if matches!(input, PipelineData::Empty) {
|
||||||
return Err(ShellError::PipelineEmpty { dst_span: head });
|
return Err(ShellError::PipelineEmpty { dst_span: head });
|
||||||
}
|
}
|
||||||
input.map(
|
input.map(move |value| operate(value, head), engine_state.signals())
|
||||||
move |value| operate(value, head),
|
|
||||||
engine_state.ctrlc.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -21,7 +21,7 @@ impl Command for SubCommand {
|
|||||||
.category(Category::Math)
|
.category(Category::Math)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Returns the tangent of the number."
|
"Returns the tangent of the number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl Command for SubCommand {
|
|||||||
}
|
}
|
||||||
input.map(
|
input.map(
|
||||||
move |value| operate(value, head, use_degrees),
|
move |value| operate(value, head, use_degrees),
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.signals(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user