diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 7388347674..c86bd34bd4 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -748,6 +748,11 @@ type App struct { // of scrolling sideways. The switch at the end of each group's strip of tabs turns it on // and off for every file at once; it lasts until the client quits. softWrap bool + // runWrap says the Run window's consoles break their long lines onto more rows instead of + // ending them in an ellipsis. The switch in the console's toolbar turns it on and off for + // every execution at once, as the Git console's does for that console; it lasts until the + // client quits. + runWrap bool // application is the running application the log window opens in; it is nil until // Run has started it. diff --git a/desktop/internal/workbench/output_style.go b/desktop/internal/workbench/output_style.go index b2ddb13c66..b53f3ec422 100644 --- a/desktop/internal/workbench/output_style.go +++ b/desktop/internal/workbench/output_style.go @@ -132,13 +132,16 @@ func completeUTF8(text string) int { // outputBuffer is one console's bounded output: finished lines, oldest first, and the line still // being written. The oldest lines go first when it holds more than maxLines lines or maxBytes // bytes. start is the sequence number of lines[0] and sequence counts the lines ever finished, so -// a reader that remembers a sequence notices lines that were dropped. Window thread only. +// a reader that remembers a sequence notices lines that were dropped. revision counts the changes +// to what it shows, so a view that wraps the lines breaks them again only when they changed; it +// is zero only before the first. Window thread only. type outputBuffer struct { lines []styledLine open styledLine bytes int start, sequence int maxLines, maxBytes int + revision uint64 } func newOutputBuffer(maxLines, maxBytes int) outputBuffer { @@ -147,6 +150,7 @@ func newOutputBuffer(maxLines, maxBytes int) outputBuffer { // apply adds a decoded chunk. func (b *outputBuffer) apply(chunk outputChunk) { + b.revision++ for _, line := range chunk.lines { b.lines = append(b.lines, line) b.bytes += len(line.text) + 1 @@ -173,6 +177,7 @@ func (b *outputBuffer) seal() { // it; the sequence keeps counting. func (b *outputBuffer) clear() { b.lines, b.bytes, b.start = nil, 0, b.sequence + b.revision++ } // count is the number of rows the console shows: the finished lines and an open line with text. diff --git a/desktop/internal/workbench/outputlinks_test.go b/desktop/internal/workbench/outputlinks_test.go index ca7afa8540..90e43492ed 100644 --- a/desktop/internal/workbench/outputlinks_test.go +++ b/desktop/internal/workbench/outputlinks_test.go @@ -37,6 +37,37 @@ func (h *harness) startRunConsole(root, text string) { h.app.applyRunOutput("run-test", chunk) } +// A wrapping console breaks its lines again only when the revision changed, so every change to +// what the buffer shows must change it: an open line that grows keeps the row count, and a +// trim keeps it too once the buffer is full. +func TestOutputBufferRevisionChangesWithEveryChangeItShows(t *testing.T) { + b := newOutputBuffer(2, 1<<20) + seen := map[uint64]bool{b.revision: true} + step := func(what string, change func()) { + t.Helper() + change() + if seen[b.revision] { + t.Fatalf("%s left the revision at %d, which it had before", what, b.revision) + } + seen[b.revision] = true + } + step("an open line", func() { b.apply(outputChunk{open: styledLine{text: "par"}}) }) + step("the open line growing", func() { b.apply(outputChunk{open: styledLine{text: "partial"}}) }) + step("two finished lines", func() { + b.apply(outputChunk{lines: []styledLine{{text: "one"}, {text: "two"}}}) + }) + count := b.count() + step("a line that pushes the oldest out", func() { b.apply(outputChunk{lines: []styledLine{{text: "three"}}}) }) + if b.count() != count || b.row(0).text != "two" { + t.Fatalf("rows = %d from %q, want %d from \"two\"", b.count(), b.row(0).text, count) + } + step("sealing the open line", func() { + b.apply(outputChunk{open: styledLine{text: "tail"}}) + b.seal() + }) + step("clearing", b.clear) +} + func TestOutputSegmentsCutAtStyleAndLinkBoundaries(t *testing.T) { bold := core.OutputStyle{Bold: true} // 😀 is two UTF-16 units, so "at" starts at unit 3. diff --git a/desktop/internal/workbench/outputlinks_view.go b/desktop/internal/workbench/outputlinks_view.go index 8034fc4da6..8d16454cd5 100644 --- a/desktop/internal/workbench/outputlinks_view.go +++ b/desktop/internal/workbench/outputlinks_view.go @@ -123,8 +123,10 @@ func (s outputSource) Line(n int) string { return s.output.row(n - s.output.star // The lines are drawn in the run output's font (fonts.go), each line as tall as that font's // line spacing makes it. A secondary press opens menu, when there is one. The console keeps // to the newest line as output arrives, until the user scrolls up, and keeps to it again once -// they scroll back down. -func (a *App) outputList(c ui.C, p *project, view *textview.View, scope, label string, output *outputBuffer, from int, menu *outputMenu) ui.Box { +// they scroll back down. A line wider than the console breaks onto more rows when wrap is set +// and otherwise ends in an ellipsis, as the Git console's do (gitconsole_view.go); the lines are +// broken again only when the output or the width changed. +func (a *App) outputList(c ui.C, p *project, view *textview.View, scope, label string, output *outputBuffer, from int, wrap bool, menu *outputMenu) ui.Box { if menu != nil && menu.key != "" { c = c.Key(menu.key) } @@ -140,6 +142,9 @@ func (a *App) outputList(c ui.C, p *project, view *textview.View, scope, label s Selection: a.terminalLook().Selection, Scroll: true, Follow: true, + Wrap: wrap, + Ellipsis: true, + Revision: output.revision, Spans: func(n int, text string, dst []textview.Span) []textview.Span { return a.outputSpans(p, scope, output.row(n-output.start), &ink, dst) }, diff --git a/desktop/internal/workbench/run_console_wrap_visual_test.go b/desktop/internal/workbench/run_console_wrap_visual_test.go new file mode 100644 index 0000000000..b2f29bd10e --- /dev/null +++ b/desktop/internal/workbench/run_console_wrap_visual_test.go @@ -0,0 +1,79 @@ +//go:build vivahead && lithevisual + +package workbench + +import ( + "os" + "path/filepath" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/headless" +) + +// wrapOutput is a build's output with lines far wider than the console, some of them in the +// colors the build printed them in. +const wrapOutput = "make -C build all\n" + + "cc -O2 -Wall -Wextra -Werror -std=c17 -I./include -I./third_party/zlib -I./third_party/yaml/include -DNDEBUG -DAPP_VERSION=\\\"1.4.2\\\" -c src/compress/deflate_stream_encoder.c -o build/obj/compress/deflate_stream_encoder.o\n" + + "\x1b[1;33mwarning:\x1b[0m src/compress/deflate_stream_encoder.c:218:17: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' when the window is resized while a block is still being written [-Wshorten-64-to-32]\n" + + "cc -O2 -Wall -Wextra -Werror -std=c17 -I./include -I./third_party/zlib -I./third_party/yaml/include -DNDEBUG -c src/config/loader.c -o build/obj/config/loader.o\n" + + "\x1b[32mok\x1b[0m build/bin/app linked from 42 objects in 1.8s; see https://example.test/builds/2026-11-18/app/linking-report.html for the full report\n" + +// TestVisualRunConsoleWrap captures the Run console holding a build's long lines, with the wrap +// switch in its toolbar off, where a line ends in an ellipsis at the console's edge, and on, +// where it breaks onto more rows in the colors it was printed in. +func TestVisualRunConsoleWrap(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, look := range []struct{ theme, language string }{{"dark", "zh-Hans"}, {"light", "en"}} { + t.Run(look.theme, func(t *testing.T) { + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, settings{Theme: themeChoice(look.theme), Language: look.language, DisableAutoSave: true}); err != nil { + t.Fatal(err) + } + var session *headless.Session + h := newHarnessWithDriver(t, Options{Kernel: &testKernel{Client: core.NewClient()}, Store: prefs, Languages: []string{look.language}}, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1200, 760 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + h.open(t.TempDir()) + p := h.app.project + run := &runEntry{id: "run-1", label: "Makefile", output: newOutputBuffer(runOutputMaxLines, runOutputBytes)} + chunk, err := newOutputDecoder(h.app.kernel).decode(wrapOutput) + if err != nil { + t.Fatal(err) + } + run.output.apply(chunk) + p.build.runs = append(p.build.runs, run) + p.build.view = run.id + if !h.app.chrome.isOpen(catalogIndex[itemRun]) { + h.app.reduceChrome(core.SetChromeOpen(itemRun, true)) + } + capture := func(id string) { + h.settleChain() + if err := session.Screenshot(filepath.Join(out, id+"-"+look.theme+".png")); err != nil { + t.Fatal(err) + } + } + capture("run-console-cut") + h.clickNamed(i18n.Shared(h.app.language(), "git.console.wrap")) + if !h.app.runWrap { + t.Fatal("a click on the wrap switch did not turn it on") + } + capture("run-console-wrapped") + }) + } +} diff --git a/desktop/internal/workbench/run_panels_test.go b/desktop/internal/workbench/run_panels_test.go index efa838ef9e..3b60e3c3d3 100644 --- a/desktop/internal/workbench/run_panels_test.go +++ b/desktop/internal/workbench/run_panels_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/gfx" ) @@ -95,3 +96,52 @@ func TestRunConsoleDeclaresOnlyTheRowsOnScreen(t *testing.T) { t.Fatal("the console does not keep to the end of its output") } } + +func TestRunConsoleWrapSwitchBreaksLongLinesInsteadOfCuttingThem(t *testing.T) { + h := debugPluginHarness(t, "dev.lithe.test.output-links", outputLinkManifest, false) + root := t.TempDir() + h.open(root) + h.app.reduceChrome(core.ToggleChrome(itemRun)) + h.startRunConsole(root, "start "+strings.Repeat("word ", 200)+"finish\nshort line\n") + for range 6 { + h.settle() + } + wrap := i18n.Shared(h.app.language(), "git.console.wrap") + if hit := h.pageHit(wrap); hit.Role != gfx.RoleSwitch || hit.Checked { + t.Fatalf("the wrap switch is %+v, want an unchecked switch", hit) + } + // Unwrapped, the long line ends in an ellipsis at the console's edge. + if h.shows("finish") || !h.shows("…") || !h.shows("short line") { + t.Fatal("an unwrapped long line is not cut with an ellipsis at the console's edge") + } + unwrapped := labelsHolding(h, "word") + + h.clickNamed(wrap) + h.settle() + if !h.app.runWrap || !h.pageHit(wrap).Checked { + t.Fatal("a click on the wrap switch did not turn it on") + } + if !h.shows("finish") || h.shows("…") || !h.shows("short line") { + t.Fatal("a wrapped long line does not show its end") + } + if wrapped := labelsHolding(h, "word"); wrapped <= unwrapped { + t.Fatalf("the long line takes %d rows wrapped and %d unwrapped, want more wrapped", wrapped, unwrapped) + } + + h.clickNamed(wrap) + h.settle() + if h.app.runWrap || h.shows("finish") || !h.shows("…") { + t.Fatal("a second click did not cut the long line again") + } +} + +// labelsHolding is the number of labels on screen that hold value. +func labelsHolding(h *harness, value string) int { + labels := 0 + for _, label := range h.driver.Snapshot().Labels { + if strings.Contains(label.Value, value) { + labels++ + } + } + return labels +} diff --git a/desktop/internal/workbench/run_view.go b/desktop/internal/workbench/run_view.go index 79c02f2a12..092177c401 100644 --- a/desktop/internal/workbench/run_view.go +++ b/desktop/internal/workbench/run_view.go @@ -130,12 +130,25 @@ func (a *App) runToolbar(c ui.C, p *project, run *runEntry) { // on it. It reports a click. Viva's icon buttons draw their icon in the text color, so the // toolbars draw their own. func (a *App) runToolButton(c ui.C, label string, icon gfx.Icon, tint gfx.Color, disabled bool) bool { - options := gfx.HitOptions{Role: gfx.RoleButton, Disabled: disabled} + return a.runToolIcon(c, label, icon, tint, false, disabled, gfx.HitOptions{Role: gfx.RoleButton, Disabled: disabled}) +} + +// runToolToggle declares a switch of the Run window's toolbars, which keeps the background the +// Git console's switches take while it is on. It reports a click. +func (a *App) runToolToggle(c ui.C, label string, icon gfx.Icon, on bool) bool { + return a.runToolIcon(c, label, icon, a.colors.Text, on, false, gfx.HitOptions{Role: gfx.RoleSwitch, Checked: on}) +} + +// runToolIcon declares the button runToolButton and runToolToggle share. +func (a *App) runToolIcon(c ui.C, label string, icon gfx.Icon, tint gfx.Color, on, disabled bool, options gfx.HitOptions) bool { if !disabled { options.Cursor = gfx.PointerCursorHand } button := ui.Row(c).Size(shellHideSize, shellHideSize).Shrink(0).Center().Radius(a.theme.Metrics.RadiusItem()). HitWith(ui.ID(c), label, options).Tooltip(label) + if on { + button = button.Background(a.colors.Active) + } if !disabled { button = button.Hover(ui.Look{}.Background(a.colors.Hover)).Pressed(ui.Look{}.Background(a.colors.Active)) } @@ -285,12 +298,15 @@ func (a *App) runConsole(c ui.C, p *project, run *runEntry) { } }, } - a.outputList(c, p, &run.console, outputScopeRun, a.text.Build.Output, &run.output, 0, menu).Grow(1) + a.outputList(c, p, &run.console, outputScopeRun, a.text.Build.Output, &run.output, 0, a.runWrap, menu).Grow(1) }) ui.Divider(c) lang := a.language() ui.Column(c).FillHeight().Shrink(0).Gap(2).Pad(4).Children(func() { empty := run.output.empty() + if a.runToolToggle(c.Part("wrap"), i18n.Shared(lang, "git.console.wrap"), icons.WrapText, a.runWrap) { + c.After(a.toggleRunWrap) + } if a.runToolButton(c.Part("end"), i18n.Shared(lang, "git.console.scrollToEnd"), icons.ArrowDownToLine, a.colors.Text, empty) { c.After(func() { run.console.ScrollToEnd() }) } @@ -300,6 +316,13 @@ func (a *App) runConsole(c ui.C, p *project, run *runEntry) { }) } +// toggleRunWrap switches the Run window's consoles between breaking long lines and ending them in +// an ellipsis. +func (a *App) toggleRunWrap() { + a.performed("run.console.wrap", surfaceButton) + a.runWrap = !a.runWrap +} + // showBuildConsole brings the Run window forward, for an action of the Build window that prints // there, on the host's execution that runs; a run a plugin starts selects its own tab when it // starts. diff --git a/desktop/internal/workbench/tests_view.go b/desktop/internal/workbench/tests_view.go index ac800201d7..441484c06f 100644 --- a/desktop/internal/workbench/tests_view.go +++ b/desktop/internal/workbench/tests_view.go @@ -196,5 +196,5 @@ func (a *App) testOutput(c ui.C, p *project) { } ui.Divider(c) menu := &outputMenu{key: "testoutput", all: output.all} - a.outputList(c, p, &p.panels.testOutput, outputScopeTest, a.text.Build.Output, output, output.count()-12, menu).Height(140).Shrink(0) + a.outputList(c, p, &p.panels.testOutput, outputScopeTest, a.text.Build.Output, output, output.count()-12, false, menu).Height(140).Shrink(0) } diff --git a/docs/assets/run-console-wrap/README.md b/docs/assets/run-console-wrap/README.md new file mode 100644 index 0000000000..acab1a6e74 --- /dev/null +++ b/docs/assets/run-console-wrap/README.md @@ -0,0 +1,14 @@ +# 运行控制台自动换行测试截图 + +来自生产 Viva Page 的无头渲染,使用隔离的临时项目和配置。控制台内容是测试注入的合成构建输出(make 与 cc 命令、 +带颜色的警告和带链接的结尾行),不代表任何真实插件或构建系统的输出。深色使用中文、浅色使用英文。 +截图不代表 macOS/Windows 原生窗口验收。 + +| 场景 | 深色中文 | 浅色英文 | +| --- | --- | --- | +| 自动换行关闭(默认):超出控制台宽度的行在右边缘以“…”结尾,被截掉的部分仍可选中和复制;右侧工具栏第一个按钮是“自动换行”开关 | [截图](run-console-cut-dark.png) | [截图](run-console-cut-light.png) | +| 点击“自动换行”后:开关保持按下的背景,长行在空格处折成多行,警告的颜色和链接颜色跨行保留 | [截图](run-console-wrapped-dark.png) | [截图](run-console-wrapped-light.png) | + +复验:设置 `LITHE_VISUAL_OUTPUT_DIR`,通过 `scripts/desktop/desktop-go.sh test +-tags vivahead,lithevisual ./internal/workbench -run '^TestVisualRunConsoleWrap$' +-count=1 -timeout 180s` 生成。 diff --git a/docs/assets/run-console-wrap/run-console-cut-dark.png b/docs/assets/run-console-wrap/run-console-cut-dark.png new file mode 100644 index 0000000000..5f8d4ae19d Binary files /dev/null and b/docs/assets/run-console-wrap/run-console-cut-dark.png differ diff --git a/docs/assets/run-console-wrap/run-console-cut-light.png b/docs/assets/run-console-wrap/run-console-cut-light.png new file mode 100644 index 0000000000..5d9c4f3040 Binary files /dev/null and b/docs/assets/run-console-wrap/run-console-cut-light.png differ diff --git a/docs/assets/run-console-wrap/run-console-wrapped-dark.png b/docs/assets/run-console-wrap/run-console-wrapped-dark.png new file mode 100644 index 0000000000..884126f963 Binary files /dev/null and b/docs/assets/run-console-wrap/run-console-wrapped-dark.png differ diff --git a/docs/assets/run-console-wrap/run-console-wrapped-light.png b/docs/assets/run-console-wrap/run-console-wrapped-light.png new file mode 100644 index 0000000000..bec78deb01 Binary files /dev/null and b/docs/assets/run-console-wrap/run-console-wrapped-light.png differ diff --git a/shared/platform-feature-matrix/features/run-console-soft-wrap.json b/shared/platform-feature-matrix/features/run-console-soft-wrap.json new file mode 100644 index 0000000000..758be59428 --- /dev/null +++ b/shared/platform-feature-matrix/features/run-console-soft-wrap.json @@ -0,0 +1,33 @@ +{ + "id": "run-console-soft-wrap", + "area": "运行与调试", + "group": "运行输出", + "capability": "运行控制台自动换行:右侧工具栏的“自动换行”开关让超出控制台宽度的行折成多行,关闭时长行在右边缘以省略号结尾", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/run_view.go", + "desktop/internal/workbench/outputlinks_view.go", + "desktop/internal/workbench/output_style.go", + "desktop/internal/workbench/run_panels_test.go", + "desktop/internal/workbench/outputlinks_test.go", + "desktop/internal/workbench/run_console_wrap_visual_test.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/run_view.go", + "desktop/internal/workbench/outputlinks_view.go", + "desktop/internal/workbench/output_style.go", + "desktop/internal/workbench/run_panels_test.go", + "desktop/internal/workbench/outputlinks_test.go", + "desktop/internal/workbench/run_console_wrap_visual_test.go" + ] + }, + "owner": "Run", + "verification": "运行一个会打印超长行的程序(例如带长编译参数的 make),确认默认状态下长行在控制台右边缘以“…”结尾,选中整行复制后得到完整内容;点击控制台右侧工具栏的“自动换行”开关,开关保持按下的背景,长行在空格处折成多行,ANSI 颜色和链接颜色跨行保留,点击折到下一行的链接仍能打开;拖动运行窗口的分隔条改变控制台宽度,折行随宽度重新排列;切换到另一个执行标签,开关状态相同;再次点击开关恢复省略号。读屏软件把开关读作开关并报告开/关状态。自动化:run_panels_test.go 的 TestRunConsoleWrapSwitchBreaksLongLinesInsteadOfCuttingThem,outputlinks_test.go 的 TestOutputBufferRevisionChangesWithEveryChangeItShows;Viva 无头截图由 run_console_wrap_visual_test.go 的 TestVisualRunConsoleWrap 生成(明暗主题 × 中英文 × 开关关/开)。", + "notes": "沿用 Git 控制台的做法:同一个 Viva textview,Wrap 由开关决定,未换行时 Ellipsis,Revision 取输出缓冲的修改计数,只在输出或宽度变化时重新折行;着色仍只走 textview 的 Spans。开关状态在整个应用内共用,退出前一直有效,不写入设置。测试窗口的失败输出不显示开关,保持省略号。和 Git 控制台一样不提供左右滚动,要看完整长行时打开自动换行。" +}