A problem nu finds reads without color: a monochrome case for its underline and its words on the context line.
- commit
- c4827b3b4313d5581711e64890c735d3f1d6d8d3
- parent
- 9dc9f69f43c893baf5a97004207b0430a20ab947
- author
- Dami <dami.etoile@gmail.com>
- kind
- docs risk score 0.5 of 3, Jev's estimate
| M | ROADMAP.md | 7 | +++-- |
| M | docs/ | 2 | +- |
| M | docs/ | 43 | +++++++++++++++++++++++++++++- |
| M | docs/ | 2 | +- |
| M | docs/ | 4 | ++- |
| M | internal/ | 23 | ++++++++++++++++ |
| M | internal/ | 10 | ++++++- |
| M | internal/ | 2 | +- |
@@ -29,12 +29,12 @@ rises in measured steps; see [Bounds of support](docs/contributing/limits.md#wha
2929 3030 Notebook tabs are a TUI Jupyter for nushell3131 ([Notebooks](docs/nushell/notebooks.md)): code and note cells, outputs in32-place, sent to sheets as live regions. What's ahead makes writing a cell33-feel like nushell's own prompt.32+place, sent to sheets as live regions, and cells highlighted, checked and33+completed by nu as they're written.3434 3535 | Item | Result | Size |3636 |---|---|---|37-| Code cells highlighted, completed and checked as you type by nushell itself: `nu --ide-ast` token shapes mapped to theme roles, `nu --ide-complete` plus 012's cell, region and sheet names on Tab, `nu --ide-check` errors underlined; debounced in the background, plain text when nu is missing or slow; hover docs through `nu --lsp` later | Writing pipelines in 012 feels like nushell's own prompt | S to M |37+| A command's signature and description for the word at the caret, on the context line, through `nu --ide-hover` or `nu --lsp` | Writing a cell without leaving for `help` | S |3838 3939 ### 3. Toward multiplayer4040 @@ -140,6 +140,7 @@ stream above rather than a design of their own.
140140 - 012 as a stage in a pipeline: `012 -` reads a table from standard input, `012 --pipe` sends the sheet or selection on, with nushell's types kept through NUON: [Pipelines](docs/nushell/pipelines.md)141141 - The `sheet` command: a nushell module shipped in the binary (`012 nu --install-module`), so nu calls 012 without `^012` or NUON on either side: [Pipelines](docs/nushell/pipelines.md#the-sheet-command)142142 - Notebook tabs, a TUI Jupyter for nushell: code and note cells with Jupyter's keys, outputs drawn in place and opened full-screen, `$name` between cells, stale marks and a reactive mode, outputs sent to sheets as live regions (`nu.name`), saved up to a cap, and earlier notebook sheets converted on open: [Notebooks](docs/nushell/notebooks.md)143+- Code cells highlighted, checked and completed as they're written by nu itself (`--ide-ast`, `--ide-check`, `--ide-complete`), in the background, falling back to 012's own when nu is missing, old, slow or not trusted: [Notebooks](docs/nushell/notebooks.md#writing-a-cell)143144 144145 **Files**145146 @@ -99,7 +99,7 @@ there.
9999 | Entries failing validation | A dotted underline, and `Invalid:` with the rule on the context line |100100 | Values an array spilled | Italic, and `Spilled from B2` on the context line |101101 | Linked files' rows, following, paused or failing | Italic; `●`, `‖` or `!` beside the tab's name and on the context line, with the state in words (`Following`, `Paused`, the error) |102-| A notebook's cells and outputs | `❯` before the tab's name; the selected cell's head in reverse video; the head's words for its state (`[*]` and `running`, `waiting`, `failed`, `stale`); `×` before an error; an output table's header bold and underlined; an output sent to a sheet in italic, with `Output of files` on the context line |102+| A notebook's cells and outputs | `❯` before the tab's name; the selected cell's head in reverse video; the head's words for its state (`[*]` and `running`, `waiting`, `failed`, `stale`); `×` before an error; an output table's header bold and underlined; an output sent to a sheet in italic, with `Output of files` on the context line; a problem nu finds in the cell being written curly-underlined, in words on the context line with the caret on it |103103 | Pivot table results | Their headings (`SUM of Units`, `Grand Total`), and a note in words when an edit is refused |104104 | Protected ranges | A question in words before an edit (`A1:B2 is protected.`) |105105 | Notes | A `▝` in the cell's top-right corner |@@ -138,7 +138,7 @@ stateDiagram-v2
138138 | Enter | A new line, as indented as the one before |139139 | Up, Down, Home, End | Move by the lines on screen, wrapped lines too |140140 | Ctrl+A, Ctrl+E | The start, the end of the line |141-| Tab | Complete the word at the caret: a cell's `$name`, `$selection`, a linked file, or one of nu's commands |141+| Tab | Complete the word at the caret: a cell's `$name`, `$selection`, a linked file, then what nu completes there (commands, flags, paths); one completion goes in at once ([Writing a cell](#writing-a-cell)) |142142 143143 A terminal without the kitty keyboard protocol sends Shift+Enter and144144 Ctrl+Enter as Enter ([Keys the terminal has to tell@@ -150,6 +150,47 @@ shortcuts (Ctrl+/), and File, Edit and the sheet tabs work as anywhere;
150150 commands for a sheet's cells are off on a notebook's tab. Changes to151151 cells are undo steps, as any edit is.152152 153+## Writing a cell154+155+The cell being written is read by nu itself, as nushell's own prompt156+reads what you type: once typing pauses, 012 asks `nu --ide-ast` what157+each word is and colors it (commands, strings, variables, numbers,158+keywords, operators; flags stay plain), and `nu --ide-check` what's159+wrong. A problem is underlined with a curly line, and with the caret on160+it the context line says what nu said:161+162+```163+ [ ] not run164+│ $files | sort-by size --revrse165+ ~~~~~~~~166+The `sort-by` command doesn't have flag `revrse`.167+```168+169+Tab asks `nu --ide-complete` too, after the notebook's own names, so it170+completes flags, subcommands and paths as well as cells and commands.171+nu doesn't know the variables a notebook binds, so it's asked about the172+cell with `$name` for each named cell and linked file, `$selection` and173+`$sheet` declared before it; a `$sheet.A1:C9` range reads as one174+variable, and `name =` isn't part of what nu reads.175+176+Questions to nu run in the background and never on each key: one177+process for each question after a pause, at most two at a time, each178+stopped once the text changes and after a second and a half. Until nu179+answers, the cell shows 012's own highlighting, and what's unchanged180+keeps nu's colors, so nothing flickers or moves. 012 falls back to its181+own highlighting and names, without saying so, when:182+183+- nu isn't installed, or is older than 0.100;184+- nu timed out three times in a row (asked again in the next session);185+- the cells couldn't run without asking: a file from another computer186+ not yet trusted ([Saving and trust](#saving-and-trust)), `shell =187+ off`, or [012 serve](../terminal/ssh.md#notebooks) without188+ `serve-shell`.189+190+nu reads the cell without your `config.nu` or its standard library, so191+your own commands aren't known to it; they still run when the cell does192+with `nu-config`.193+153194 ## Running154195 155196 Cells run in the background, one at a time, so the screen stays live:@@ -150,7 +150,7 @@ on a sheet, `!` starts an entry as any character does.
150150 |---|---|151151 | Esc | Back to command mode, keeping what was typed |152152 | Shift+Enter, Ctrl+Enter, Alt+Enter | Run, as in command mode |153-| Enter, Tab | A new line; complete the word at the caret |153+| Enter, Tab | A new line; complete the word at the caret, with what nu completes there ([Writing a cell](../nushell/notebooks.md#writing-a-cell)) |154154 | Up, Down, Home, End, Ctrl+A, Ctrl+E | Move by the lines on screen; the start, the end of the line |155155 156156 | Key | On an output full-screen |@@ -158,7 +158,9 @@ reach, well beyond the served directory. `serve-shell = on` in the
158158 server's config lets sessions run them, as the user 012 serve runs as,159159 following the `shell` option as the local app does; a file's cells still160160 ask once per session before they run. Only turn it on when everyone holding an161-authorized key may run programs on the server.161+authorized key may run programs on the server. The same setting decides162+whether nu is started to [highlight and check](../nushell/notebooks.md#writing-a-cell)163+the cell being written; without it, 012's own highlighting answers.162164 163165 ## Unsaved work164166 @@ -457,3 +457,26 @@ func TestMonochromeBarsIconsChips(t *testing.T) {
457457 t.Errorf("chip %q %+v", got, c1[2])458458 }459459 }460+461+// A problem nu finds in the cell being written is underlined, curly as462+// an error cell is, and in words on the context line with the caret on463+// it.464+func TestMonochromeNuProblem(t *testing.T) {465+ nu := &ideNu{fakeNu: &fakeNu{}, problem: "--revrse"}466+ m := newModel()467+ m.SetShellRunner(nu)468+ m.SetMachine("here")469+ run(m, m.runCommand("nb.open"))470+ press(t, m, "b", "<enter>")471+ send(m, pasteMsg("ls | sort-by name --revrse"))472+ l := findLine(t, m, "sort-by")473+ if c := cellsOf(l, "--revrse"); !every(c, true, func(c monoCell) bool { return c.underline == "3" }) {474+ t.Errorf("the problem isn't underlined: %+v", c)475+ }476+ if c := cellsOf(l, "name"); every(c, true, func(c monoCell) bool { return c.underline == "3" }) {477+ t.Error("what's fine is underlined")478+ }479+ if !strings.Contains(cellText(monoLine(m, contextLine)), "Not a flag.") {480+ t.Errorf("the context line: %q", cellText(monoLine(m, contextLine)))481+ }482+}@@ -3,6 +3,7 @@ package ui
33 import (44 "bytes"55 "context"6+ "fmt"67 "io"78 "slices"89 "strings"@@ -15,10 +16,12 @@ import (
1516 )1617 1718 // ideNu is fakeNu answering the code editor's questions too, as nu18-// 0.116 would about any pipeline, and noting them.19+// 0.116 would about any pipeline, and noting them. Its check finds20+// problem wherever the pipeline has it.1921 type ideNu struct {2022 *fakeNu21- ide []string23+ ide []string24+ problem string2225 }2326 2427 func (f *ideNu) Run(ctx context.Context, job nushell.Job, script string, stdout io.Writer) error {@@ -27,6 +30,9 @@ func (f *ideNu) Run(ctx context.Context, job nushell.Job, script string, stdout
2730 }2831 f.ide = append(f.ide, job.IDE[0])2932 answer := map[string]string{"--version": "0.116.0", "--ide-ast": "[]", "--ide-complete": `{"completions": []}`}[job.IDE[0]]33+ if i := strings.Index(script, f.problem); job.IDE[0] == "--ide-check" && f.problem != "" && i >= 0 {34+ answer = fmt.Sprintf(`{"type":"diagnostic","severity":"Error","message":"Not a flag.","span":{"start":%d,"end":%d}}`, i, i+len(f.problem))35+ }3036 _, err := io.WriteString(stdout, answer)3137 return err3238 }@@ -41,7 +41,7 @@ func NewNuSession(r nushell.Runner) *NuSession {
4141 4242 // SetOn says whether nu may be asked: in 012 serve only as serve-shell4343 // allows, and only about a notebook whose cells may run here without44-// asking (docs/nushell/notebooks.md#trust).44+// asking (docs/nushell/notebooks.md#saving-and-trust).4545 func (s *NuSession) SetOn(on bool) { s.on.Store(on) }4646 4747 // Asking reports whether nu is asked: allowed, and not found missing,