Skip to content

Commit 125ff12

Browse files
authored
FIX: add | table to folded tables (#918)
* add `| table` to folded tables * refactor the "loading data" chapter in snippets * refactor the "cell paths" section in a snippet
1 parent b602715 commit 125ff12

File tree

12 files changed

+68
-160
lines changed

12 files changed

+68
-160
lines changed

book/loading_data.md

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@ Earlier, we saw how you can use commands like [`ls`](/commands/docs/ls.md), [`ps
66

77
One of Nu's most powerful assets in working with data is the [`open`](/commands/docs/open.md) command. It is a multi-tool that can work with a number of different data formats. To see what this means, let's try opening a json file:
88

9-
```
10-
> open editors/vscode/package.json
11-
──────────────────┬───────────────────────────────────────────────────────────────────────────────
12-
name │ lark
13-
description │ Lark support for VS Code
14-
author │ Lark developers
15-
license │ MIT
16-
version │ 1.0.0
17-
repository │ [row type url]
18-
publisher │ vscode
19-
categories │ [table 0 rows]
20-
keywords │ [table 1 rows]
21-
engines │ [row vscode]
22-
activationEvents │ [table 1 rows]
23-
main │ ./out/extension
24-
contributes │ [row configuration grammars languages]
25-
scripts │ [row compile postinstall test vscode:prepublish watch]
26-
devDependencies │ [row @types/mocha @types/node tslint typescript vscode vscode-languageclient]
27-
──────────────────┴───────────────────────────────────────────────────────────────────────────────
28-
```
9+
@[code](@snippets/loading_data/vscode.sh)
2910

3011
In a similar way to [`ls`](/commands/docs/ls.md), opening a file type that Nu understands will give us back something that is more than just text (or a stream of bytes). Here we open a "package.json" file from a JavaScript project. Nu can recognize the JSON text and parse it to a table of data.
3112

@@ -213,13 +194,7 @@ version = "0.1.2"
213194

214195
The "Cargo.lock" file is actually a .toml file, but the file extension isn't .toml. That's okay, we can use the [`from`](/commands/docs/from.md) command using the `toml` subcommand:
215196

216-
```
217-
> open Cargo.lock | from toml
218-
──────────┬───────────────────
219-
metadata │ [row 107 columns]
220-
package │ [table 130 rows]
221-
──────────┴───────────────────
222-
```
197+
@[code](@snippets/loading_data/cargo-toml.sh)
223198

224199
The [`from`](/commands/docs/from.md) command can be used for each of the structured data text formats that Nu can open and understand by passing it the supported format as a subcommand.
225200

@@ -262,9 +237,4 @@ Or run any SQL query you like:
262237

263238
In addition to loading files from your filesystem, you can also load URLs by using the [`http get`](/commands/docs/fetch.md) command. This will fetch the contents of the URL from the internet and return it:
264239

265-
```
266-
> http get https://blog.rust-lang.org/feed.xml
267-
──────┬───────────────────
268-
feed │ {record 2 fields}
269-
──────┴───────────────────
270-
```
240+
@[code](@snippets/loading_data/rust-lang-feed.sh)

book/metadata.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ Values that flow through a pipeline in Nu often have a set of additional informa
2020
Let's run the [`open`](/commands/docs/open.md) command again, but this time, we'll look at the tags it gives back:
2121

2222
```
23-
> open Cargo.toml | metadata
24-
────────┬───────────────────────────────────────────
25-
span │ {record 2 fields}
26-
────────┴───────────────────────────────────────────
23+
> metadata (open Cargo.toml) | table
24+
──────┬───────────────────
25+
span │ {record 2 fields}
26+
──────┴───────────────────
2727
```
2828

2929
Currently, we track only the span of where values come from. Let's take a closer look at that:
3030

3131
```
32-
> open Cargo.toml | metadata | get span
33-
───────┬────
34-
start │ 5
35-
end │ 15
36-
───────┴────
32+
> metadata (open Cargo.toml) | get span
33+
───────┬────────╮
34+
start │ 212970 │
35+
end │ 212987 │
36+
───────┴────────╯
3737
```
3838

3939
The span "start" and "end" here refer to where the underline will be in the line. If you count over 5, and then count up to 15, you'll see it lines up with the "Cargo.toml" filename. This is how the error we saw earlier knew what to underline.

book/types_of_data.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,7 @@ You can combine list and record data access syntax to navigate tables. When used
348348

349349
You can access individual rows by number to obtain records:
350350

351-
```sh
352-
> [{langs:[Rust JS Python], releases:60}].0
353-
╭──────────┬────────────────╮
354-
│ langs │ [list 3 items] │
355-
│ releases │ 60 │
356-
╰──────────┴────────────────╯
357-
> [{langs:[Rust JS Python], releases:60}].0.langs.2
358-
Python
359-
```
351+
@[code](@snippets/types_of_data/cell-paths.sh)
360352

361353
Moreover, you can also access entire columns of a table by name, to obtain lists:
362354

de/book/loading_data.md

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,7 @@ Einer der mächtigsten Befehle in Nu um mir Daten zu arbeite ist der [`open`](/c
1212
Er ist ein Multi-Werkzeug, welcher mit verschiedensten Datenformaten umgehen kann.
1313
Hier zum Beispiel was passiert, wenn eine json Datei geöffnet wird:
1414

15-
```
16-
> open editors/vscode/package.json
17-
──────────────────┬───────────────────────────────────────────────────────────────────────────────
18-
name │ lark
19-
description │ Lark support for VS Code
20-
author │ Lark developers
21-
license │ MIT
22-
version │ 1.0.0
23-
repository │ [row type url]
24-
publisher │ vscode
25-
categories │ [table 0 rows]
26-
keywords │ [table 1 rows]
27-
engines │ [row vscode]
28-
activationEvents │ [table 1 rows]
29-
main │ ./out/extension
30-
contributes │ [row configuration grammars languages]
31-
scripts │ [row compile postinstall test vscode:prepublish watch]
32-
devDependencies │ [row @types/mocha @types/node tslint typescript vscode vscode-languageclient]
33-
──────────────────┴───────────────────────────────────────────────────────────────────────────────
34-
```
15+
@[code](@snippets/loading_data/vscode.sh)
3516

3617
Ähnlich wie beim [`ls`](/commands/docs/ls.md) Befehl, bekommen wir mehr als nur Text
3718
(oder einen Stream von bytes) zurück, wenn wir einen Dateityp öffnen, den Nu versteht.
@@ -196,13 +177,7 @@ version = "0.1.2"
196177
Eine "Cargo.lock" Datei ist eigentlich eine .toml Datei, aber die Dateiendung ist nicht .toml.
197178
Das ist ok, denn mit dem `from` und seinem Unterbefehl `toml` können wir dies explizit angeben:
198179

199-
```
200-
> open Cargo.lock | from toml
201-
──────────┬───────────────────
202-
metadata │ [row 107 columns]
203-
package │ [table 130 rows]
204-
──────────┴───────────────────
205-
```
180+
@[code](@snippets/loading_data/cargo-toml.sh)
206181

207182
Der `from` Befehl kann für jedes strukturierte Datenformat, welches Nu versteht, verwendet werden,
208183
indem das Format als entsprechender Unterbefehl verwendet wird.
@@ -227,9 +202,4 @@ license = "MIT"
227202
Zusätzlich zum Laden von Dateien vom Dateisystem, können auch URLs mit dem [`http get`](/commands/docs/fetch.md)
228203
Befehl geladen werden. Dies wird den Inhalt der URL aus dem Netz abrufen und zurückgeben:
229204

230-
```
231-
> http get https://blog.rust-lang.org/feed.xml
232-
──────┬───────────────────
233-
feed │ {record 2 fields}
234-
──────┴───────────────────
235-
```
205+
@[code](@snippets/loading_data/rust-lang-feed.sh)

ja/book/loading_data.md

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@
66

77
データを操作するための Nu の最も強力なコマンドのひとつが`open`コマンドです。これは様々なデータ形式に対応したマルチツールです。これがなにを意味するかをみるために、json ファイルを開いてみましょう。
88

9-
```
10-
> open editors/vscode/package.json
11-
──────────────────┬───────────────────────────────────────────────────────────────────────────────
12-
name │ lark
13-
description │ Lark support for VS Code
14-
author │ Lark developers
15-
license │ MIT
16-
version │ 1.0.0
17-
repository │ [row type url]
18-
publisher │ vscode
19-
categories │ [table 0 rows]
20-
keywords │ [table 1 rows]
21-
engines │ [row vscode]
22-
activationEvents │ [table 1 rows]
23-
main │ ./out/extension
24-
contributes │ [row configuration grammars languages]
25-
scripts │ [row compile postinstall test vscode:prepublish watch]
26-
devDependencies │ [row @types/mocha @types/node tslint typescript vscode vscode-languageclient]
27-
──────────────────┴───────────────────────────────────────────────────────────────────────────────
28-
```
9+
@[code](@snippets/loading_data/vscode.sh)
2910

3011
`ls`と同様、Nu が理解できるタイプのファイルを開くと、単なるテキスト(またはバイトストリーム)以上のものが返ってきます。ここでは、JavaScript プロジェクト内の"package.json"ファイルを開いています。Nu は JSON テキストを認識し、テーブルデータを返すことができます。
3112

@@ -163,13 +144,7 @@ version = "0.1.2"
163144

164145
"Cargo.lock"ファイルは実際には.toml ファイルですが、ファイル拡張子が.toml ではありません。でも大丈夫です、`from toml`コマンドが使えます。
165146

166-
```
167-
> open Cargo.lock | from toml
168-
──────────┬───────────────────
169-
metadata │ [row 107 columns]
170-
package │ [table 130 rows]
171-
──────────┴───────────────────
172-
```
147+
@[code](@snippets/loading_data/cargo-toml.sh)
173148

174149
`from`コマンドはサポートされているテキストフォーマットをサブコマンドとして渡すことで Nu が扱える構造化データごとに利用できます。
175150

@@ -191,9 +166,4 @@ license = "MIT"
191166
ファイルシステムからファイルを読み込むことに加えて、`http get`コマンドを利用して URL からリソースを取得できます。
192167
これはインターネットから URL の内容をフェッチして返してくれます。
193168

194-
```
195-
> http get https://www.jonathanturner.org/feed.xml
196-
─────┬───────────────────────────
197-
rss │ [row attributes children]
198-
─────┴───────────────────────────
199-
```
169+
@[code](@snippets/loading_data/rust-lang-feed.sh)

snippets/introduction/sys_example.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> sys
1+
> sys | table
22
╭───────┬───────────────────╮
33
│ host │ {record 6 fields} │
44
│ cpu │ [table 4 rows] │

snippets/loading_data/cargo-toml.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
> open Cargo.lock | from toml | table
2+
──────────┬───────────────────
3+
metadata │ [row 107 columns]
4+
package │ [table 130 rows]
5+
──────────┴───────────────────
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
> http get https://blog.rust-lang.org/feed.xml | table
2+
╭────────────┬──────────────────╮
3+
│ tag │ feed │
4+
│ attributes │ {record 1 field} │
5+
│ content │ [table 18 rows] │
6+
╰────────────┴──────────────────╯

snippets/loading_data/vscode.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
> open editors/vscode/package.json | table
2+
──────────────────┬───────────────────────────────────────────────────────────────────────────────
3+
name │ lark
4+
description │ Lark support for VS Code
5+
author │ Lark developers
6+
license │ MIT
7+
version │ 1.0.0
8+
repository │ [row type url]
9+
publisher │ vscode
10+
categories │ [table 0 rows]
11+
keywords │ [table 1 rows]
12+
engines │ [row vscode]
13+
activationEvents │ [table 1 rows]
14+
main │ ./out/extension
15+
contributes │ [row configuration grammars languages]
16+
scripts │ [row compile postinstall test vscode:prepublish watch]
17+
devDependencies │ [row @types/mocha @types/node tslint typescript vscode vscode-languageclient]
18+
──────────────────┴───────────────────────────────────────────────────────────────────────────────

snippets/types_of_data/cell-paths.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
> [{langs:[Rust JS Python], releases:60}].0 | table
2+
╭──────────┬────────────────╮
3+
│ langs │ [list 3 items] │
4+
│ releases │ 60 │
5+
╰──────────┴────────────────╯
6+
> [{langs:[Rust JS Python], releases:60}].0.langs.2
7+
Python

0 commit comments

Comments
 (0)