diff --git a/desktop/internal/i18n/en.go b/desktop/internal/i18n/en.go index e4dc99f842..96ea4a19d1 100644 --- a/desktop/internal/i18n/en.go +++ b/desktop/internal/i18n/en.go @@ -304,12 +304,16 @@ var english = Messages{ FindPrevious: Shared(English, "desktop.terminal.findPrevious"), FindNext: Shared(English, "desktop.terminal.findNext"), FindClose: Shared(English, "desktop.terminal.findClose"), + PasteImageTooLarge: Shared(English, "desktop.terminal.pasteImageTooLarge"), FindCount: func(current, total string) string { return SharedFormat(English, "desktop.terminal.findCount", map[string]string{"current": current, "total": total}) }, OpenLinkFailed: func(reason string) string { return SharedFormat(English, "desktop.terminal.openLinkFailed", map[string]string{"reason": reason}) }, + PasteImageFailed: func(reason string) string { + return SharedFormat(English, "desktop.terminal.pasteImageFailed", map[string]string{"reason": reason}) + }, ShellMenu: Shared(English, "native.newTerminalWithShell"), DetectingShells: Shared(English, "terminal.detectingShells"), NoShells: Shared(English, "native.shellNotFound"), diff --git a/desktop/internal/i18n/messages.go b/desktop/internal/i18n/messages.go index ae7c489b0f..442911e7f1 100644 --- a/desktop/internal/i18n/messages.go +++ b/desktop/internal/i18n/messages.go @@ -498,6 +498,10 @@ type TerminalMessages struct { FindCount func(current, total string) string // OpenLinkFailed tells that a clicked link could not be opened. OpenLinkFailed func(reason string) string + // PasteImageFailed tells that the picture on the clipboard could not be saved for a + // paste, and PasteImageTooLarge that it was too large to read. + PasteImageFailed func(reason string) string + PasteImageTooLarge string // ShellMenu is the accessible name of the button beside NewTab that lists the // installed shells. DetectingShells and NoShells stand in that list while it is being // made and when it found none. ShellWithPath names an installation whose name another diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 6e4050cdf4..2fe24fe853 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1436,6 +1436,16 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.tabsScroll": "Scroll tab panel", "desktop.settings.tabsShowIn": "Show tabs in:", "desktop.settings.tabsSqueeze": "Squeeze tabs", + "desktop.settings.terminal.cursor": "Cursor", + "desktop.settings.terminal.cursorHelp": "The shape the cursor takes until a program asks for its own, and how thick the bar and underline draw. Open terminals change at once.", + "desktop.settings.terminal.cursorNormal": "Normal", + "desktop.settings.terminal.cursorShape": "Shape", + "desktop.settings.terminal.cursorShapeBar": "Bar", + "desktop.settings.terminal.cursorShapeBlock": "Block", + "desktop.settings.terminal.cursorShapeUnderline": "Underline", + "desktop.settings.terminal.cursorThick": "Thick", + "desktop.settings.terminal.cursorThickness": "Thickness", + "desktop.settings.terminal.cursorThin": "Thin", "desktop.settings.terminal.scrollback": "Scrollback", "desktop.settings.terminal.scrollbackDefault": "Default", "desktop.settings.terminal.scrollbackHelp": "How many lines of history a new terminal keeps above its screen (100–50,000). Open terminals keep their current limit.", @@ -1622,6 +1632,8 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.terminal.localNumber": "Local ({number})", "desktop.terminal.noTerminals": "All terminals are in the editor. Click + to open a new one here.", "desktop.terminal.openLinkFailed": "Could not open the link: {reason}", + "desktop.terminal.pasteImageFailed": "Could not save the clipboard image: {reason}", + "desktop.terminal.pasteImageTooLarge": "The clipboard image is too large to paste.", "desktop.terminal.restartHint": "Press Enter to start a new session.", "desktop.terminal.runSelection": "Run Selection in Terminal", "desktop.terminal.scrollbarLabel": "Terminal scrollback", @@ -4115,6 +4127,16 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.tabsScroll": "滚动标签页面板", "desktop.settings.tabsShowIn": "在以下位置显示标签页:", "desktop.settings.tabsSqueeze": "挤压标签页", + "desktop.settings.terminal.cursor": "光标", + "desktop.settings.terminal.cursorHelp": "程序没有指定光标形状时终端使用的形状,以及竖线和下划线光标的粗细。已打开的终端立即生效。", + "desktop.settings.terminal.cursorNormal": "标准", + "desktop.settings.terminal.cursorShape": "形状", + "desktop.settings.terminal.cursorShapeBar": "竖线", + "desktop.settings.terminal.cursorShapeBlock": "方块", + "desktop.settings.terminal.cursorShapeUnderline": "下划线", + "desktop.settings.terminal.cursorThick": "粗", + "desktop.settings.terminal.cursorThickness": "粗细", + "desktop.settings.terminal.cursorThin": "细", "desktop.settings.terminal.scrollback": "回滚行数", "desktop.settings.terminal.scrollbackDefault": "恢复默认", "desktop.settings.terminal.scrollbackHelp": "新建终端在屏幕上方保留的历史行数(100–50000)。已打开的终端保持原有上限。", @@ -4301,6 +4323,8 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.terminal.localNumber": "本地 ({number})", "desktop.terminal.noTerminals": "终端都已移到编辑器中。点击 + 在这里新建一个。", "desktop.terminal.openLinkFailed": "无法打开链接:{reason}", + "desktop.terminal.pasteImageFailed": "无法保存剪贴板里的图片:{reason}", + "desktop.terminal.pasteImageTooLarge": "剪贴板里的图片太大,无法粘贴。", "desktop.terminal.restartHint": "按 Enter 键开始新会话。", "desktop.terminal.runSelection": "在终端运行选中内容", "desktop.terminal.scrollbarLabel": "终端回滚", diff --git a/desktop/internal/i18n/zh.go b/desktop/internal/i18n/zh.go index 2e0a65d35d..9d7ed1d94f 100644 --- a/desktop/internal/i18n/zh.go +++ b/desktop/internal/i18n/zh.go @@ -304,12 +304,16 @@ var chinese = Messages{ FindPrevious: Shared(Chinese, "desktop.terminal.findPrevious"), FindNext: Shared(Chinese, "desktop.terminal.findNext"), FindClose: Shared(Chinese, "desktop.terminal.findClose"), + PasteImageTooLarge: Shared(Chinese, "desktop.terminal.pasteImageTooLarge"), FindCount: func(current, total string) string { return SharedFormat(Chinese, "desktop.terminal.findCount", map[string]string{"current": current, "total": total}) }, OpenLinkFailed: func(reason string) string { return SharedFormat(Chinese, "desktop.terminal.openLinkFailed", map[string]string{"reason": reason}) }, + PasteImageFailed: func(reason string) string { + return SharedFormat(Chinese, "desktop.terminal.pasteImageFailed", map[string]string{"reason": reason}) + }, ShellMenu: Shared(Chinese, "native.newTerminalWithShell"), DetectingShells: Shared(Chinese, "terminal.detectingShells"), NoShells: Shared(Chinese, "native.shellNotFound"), diff --git a/desktop/internal/settingswindow/controller.go b/desktop/internal/settingswindow/controller.go index a7aaae3fd6..1de050a836 100644 --- a/desktop/internal/settingswindow/controller.go +++ b/desktop/internal/settingswindow/controller.go @@ -74,6 +74,12 @@ type Values struct { // TerminalScrollback is the history lines a new terminal keeps, within // MinScrollback and MaxScrollback. TerminalScrollback int + // TerminalCursorShape is the shape the terminal cursor takes until a program asks for + // its own (CursorShapeBlock, CursorShapeBar or CursorShapeUnderline), and + // TerminalCursorThickness how thick a bar or an underline draws (CursorThicknessThin, + // CursorThicknessNormal or CursorThicknessThick). + TerminalCursorShape string + TerminalCursorThickness string // Fonts are the fonts of the editor, the terminal and the run output, as // fontprefs.Normalize returns them. Nil is fontprefs.Default, the system's fixed-pitch // font for every place. @@ -374,6 +380,9 @@ type Options struct { // SetTerminalScrollback hands a change of Values.TerminalScrollback to the settings // owner, like SetTabRows. SetTerminalScrollback func(int) + // SetTerminalCursor hands a change of Values.TerminalCursorShape and + // Values.TerminalCursorThickness to the settings owner, like SetTabRows. + SetTerminalCursor func(shape, thickness string) // SetFonts hands a change of Values.Fonts to the settings owner, like SetTabRows. The // list it receives is normalized. SetFonts func([]fontprefs.Font) diff --git a/desktop/internal/settingswindow/terminal_cursor_view.go b/desktop/internal/settingswindow/terminal_cursor_view.go new file mode 100644 index 0000000000..bbb01e636d --- /dev/null +++ b/desktop/internal/settingswindow/terminal_cursor_view.go @@ -0,0 +1,101 @@ +package settingswindow + +import ( + "github.com/vivaui/viva/ui" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// The terminal cursor shapes Values.TerminalCursorShape holds. The empty string is the block a +// terminal starts with. +const ( + CursorShapeBlock = "" + CursorShapeBar = "bar" + CursorShapeUnderline = "underline" +) + +// The terminal cursor thicknesses Values.TerminalCursorThickness holds. The empty string is +// the normal thickness. +const ( + CursorThicknessThin = "thin" + CursorThicknessNormal = "" + CursorThicknessThick = "thick" +) + +var ( + cursorShapeChoices = []string{CursorShapeBlock, CursorShapeBar, CursorShapeUnderline} + cursorThicknessChoices = []string{CursorThicknessThin, CursorThicknessNormal, CursorThicknessThick} +) + +// NormalCursorShape is shape when it is one of the shapes above and the block otherwise, so a +// value an older or newer build stored draws a cursor and shows as one choice of the page. +func NormalCursorShape(shape string) string { + if shape == CursorShapeBar || shape == CursorShapeUnderline { + return shape + } + return CursorShapeBlock +} + +// NormalCursorThickness is thickness when it is one of the thicknesses above and the normal +// one otherwise. +func NormalCursorThickness(thickness string) string { + if thickness == CursorThicknessThin || thickness == CursorThicknessThick { + return thickness + } + return CursorThicknessNormal +} + +// cursorCard is the Terminal page's cursor setting: the shape the cursor takes until a +// program asks for its own, and how thick a bar or an underline draws. The thickness stays +// open with the block chosen, as it is also the thickness of a bar or an underline a program +// asks for. Open terminals take a change at their next paint. +func (w *window) cursorCard(c ui.C) { + language := w.marketLanguage() + shape := NormalCursorShape(w.sess.values.TerminalCursorShape) + thickness := NormalCursorThickness(w.sess.values.TerminalCursorThickness) + shapeTitle := i18n.Shared(language, "desktop.settings.terminal.cursorShape") + thicknessTitle := i18n.Shared(language, "desktop.settings.terminal.cursorThickness") + w.card(c, i18n.Shared(language, "desktop.settings.terminal.cursor"), i18n.Shared(language, "desktop.settings.terminal.cursorHelp"), func() { + w.settingsRow(c, shapeTitle, "", func() { + if ui.Select(c.Part("cursor-shape"), &shape, cursorShapeChoices, func(choice string) string { + switch choice { + case CursorShapeBar: + return i18n.Shared(language, "desktop.settings.terminal.cursorShapeBar") + case CursorShapeUnderline: + return i18n.Shared(language, "desktop.settings.terminal.cursorShapeUnderline") + } + return i18n.Shared(language, "desktop.settings.terminal.cursorShapeBlock") + }).Width(selectWidth).Label(shapeTitle).Changed() { + w.setTerminalCursor(shape, thickness) + } + }) + w.settingsRow(c, thicknessTitle, "", func() { + if ui.Select(c.Part("cursor-thickness"), &thickness, cursorThicknessChoices, func(choice string) string { + switch choice { + case CursorThicknessThin: + return i18n.Shared(language, "desktop.settings.terminal.cursorThin") + case CursorThicknessThick: + return i18n.Shared(language, "desktop.settings.terminal.cursorThick") + } + return i18n.Shared(language, "desktop.settings.terminal.cursorNormal") + }).Width(selectWidth).Label(thicknessTitle).Changed() { + w.setTerminalCursor(shape, thickness) + } + }) + }) +} + +// setTerminalCursor stores the cursor chosen and hands it to the settings owner. +func (w *window) setTerminalCursor(shape, thickness string) { + if w.sess.finished.Load() { + return + } + shape, thickness = NormalCursorShape(shape), NormalCursorThickness(thickness) + if shape == NormalCursorShape(w.sess.values.TerminalCursorShape) && thickness == NormalCursorThickness(w.sess.values.TerminalCursorThickness) { + return + } + w.sess.values.TerminalCursorShape, w.sess.values.TerminalCursorThickness = shape, thickness + if w.ctrl.opts.SetTerminalCursor != nil { + w.ctrl.opts.SetTerminalCursor(shape, thickness) + } +} diff --git a/desktop/internal/settingswindow/terminal_cursor_view_test.go b/desktop/internal/settingswindow/terminal_cursor_view_test.go new file mode 100644 index 0000000000..3a301a18df --- /dev/null +++ b/desktop/internal/settingswindow/terminal_cursor_view_test.go @@ -0,0 +1,52 @@ +package settingswindow + +import ( + "slices" + "testing" + + "github.com/vivaui/viva/gfx" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/localshell" +) + +// TestTerminalCursorChoicesApplyWhenChosen covers the Terminal page's cursor card: a stored +// value the page does not offer shows as the default and is not rewritten by opening the +// page, and each choice reaches the settings owner at once with the other half kept. +func TestTerminalCursorChoicesApplyWhenChosen(t *testing.T) { + var changed [][2]string + w := newWindow(NewController(Options{ + TerminalShells: func() ([]localshell.Choice, string) { + return []localshell.Choice{{Name: "zsh", Path: "/bin/zsh", Default: true}}, "/bin/zsh" + }, + SetTerminalCursor: func(shape, thickness string) { changed = append(changed, [2]string{shape, thickness}) }, + }), Values{TerminalCursorShape: "beam", TerminalCursorThickness: CursorThicknessThin}) + w.sess.page = pageTerminal + d := openWindow(t, w) + language := w.marketLanguage() + word := func(key string) string { return i18n.Shared(language, "desktop.settings.terminal."+key) } + + if hit := d.hit(word("cursorShape")); hit.Role != gfx.RoleCombobox || hit.Value != word("cursorShapeBlock") { + t.Fatalf("an unknown shape did not show the block: %+v", hit) + } + if hit := d.hit(word("cursorThickness")); hit.Value != word("cursorThin") { + t.Fatalf("the stored thickness is not chosen: %+v", hit) + } + if len(changed) != 0 { + t.Fatalf("opening the page wrote %v", changed) + } + + d.click(word("cursorShape")) + d.click(word("cursorShapeBar")) + d.click(word("cursorThickness")) + d.click(word("cursorThick")) + d.click(word("cursorShape")) + d.click(word("cursorShapeBlock")) + want := [][2]string{{CursorShapeBar, CursorThicknessThin}, {CursorShapeBar, CursorThicknessThick}, {CursorShapeBlock, CursorThicknessThick}} + if !slices.Equal(changed, want) { + t.Fatalf("choices wrote %v, want %v", changed, want) + } + if hit := d.hit(word("cursorThickness")); hit.Value != word("cursorThick") || hit.Disabled { + t.Fatalf("with the block chosen the thickness is %+v, want the thick one still open", hit) + } +} diff --git a/desktop/internal/settingswindow/terminal_view.go b/desktop/internal/settingswindow/terminal_view.go index b33316f5fc..ccb6a1a1ab 100644 --- a/desktop/internal/settingswindow/terminal_view.go +++ b/desktop/internal/settingswindow/terminal_view.go @@ -169,6 +169,7 @@ func (w *window) terminalPage(c ui.C) { }) }) w.scrollbackCard(c) + w.cursorCard(c) }) if w.shellPick != stored && !(stored != "" && sameShell(w.shellPick, stored)) { w.setTerminalShell(w.shellPick, false) diff --git a/desktop/internal/term/csi.go b/desktop/internal/term/csi.go index 481ed13658..676b6a176e 100644 --- a/desktop/internal/term/csi.go +++ b/desktop/internal/term/csi.go @@ -469,6 +469,13 @@ func (t *Terminal) softReset() { func (t *Terminal) setCursorStyle(n int) { t.cursorSteady = n == 2 || n == 4 || n == 6 + if n == 0 { + // 0 asks for the default cursor, which is the user's choice as in Windows Terminal, + // iTerm2 and kitty rather than xterm's blinking block: vim, and the vi mode of zsh and + // fish, send it on the way out to give back the cursor they found. + t.cursor, t.cursorStyled = t.defaultCursor, false + return + } t.cursorStyled = true switch n { case 3, 4: diff --git a/desktop/internal/term/cursor_style_test.go b/desktop/internal/term/cursor_style_test.go new file mode 100644 index 0000000000..3106f9b9b9 --- /dev/null +++ b/desktop/internal/term/cursor_style_test.go @@ -0,0 +1,39 @@ +package term + +import "testing" + +// The user's default shape is the cursor's until a program asks for its own, and comes back +// when the program asks for the default with DECSCUSR 0 or resets the terminal. +func TestDefaultCursorShapeYieldsToProgramsAndComesBack(t *testing.T) { + screen := New(20, 4, 0) + if got := screen.Cursor().Style; got != CursorBlock { + t.Fatalf("a new terminal's cursor = %v, want the block", got) + } + screen.SetDefaultCursor(CursorBar) + if got := screen.Cursor().Style; got != CursorBar { + t.Fatalf("after a bar default the cursor = %v, want the bar", got) + } + + screen.Write([]byte("\x1b[2 q")) + if got := screen.Cursor().Style; got != CursorBlock { + t.Fatalf("after a program asked for a steady block the cursor = %v", got) + } + screen.SetDefaultCursor(CursorUnderline) + if got := screen.Cursor().Style; got != CursorBlock { + t.Fatalf("a new default replaced the shape a program asked for: %v", got) + } + + screen.Write([]byte("\x1b[0 q")) + if got := screen.Cursor().Style; got != CursorUnderline { + t.Fatalf("DECSCUSR 0 gave %v, want the user's underline", got) + } + screen.SetDefaultCursor(CursorBar) + if got := screen.Cursor().Style; got != CursorBar { + t.Fatalf("after DECSCUSR 0 the default no longer applies: %v", got) + } + + screen.Write([]byte("\x1b[3 q\x1bc")) + if got := screen.Cursor().Style; got != CursorBar { + t.Fatalf("after a reset the cursor = %v, want the user's bar", got) + } +} diff --git a/desktop/internal/term/selection.go b/desktop/internal/term/selection.go index 73b23ea9de..bcd784a1b9 100644 --- a/desktop/internal/term/selection.go +++ b/desktop/internal/term/selection.go @@ -67,6 +67,40 @@ func (t *Terminal) SelectedRange(anchor, focus Point) string { return result.String() } +// BlockRange returns the cells of the rectangle between two buffer points: the +// columns they span, on every line they span. Unlike SelectedRange, a +// soft-wrapped row is a line of its own here, the way the rectangle shows it on +// screen. Points beyond the retained lines clamp to them; a wide character is +// kept whole when the rectangle starts on its second cell. Blank cells at the +// right edge are dropped from each line, so a column copied out of a table keeps +// its alignment without trailing spaces. +func (t *Terminal) BlockRange(anchor, focus Point) string { + base, count := t.lineBase(), uint64(t.bufferLineCount()) + if count == 0 { + return "" + } + anchor, focus = t.clampPoint(anchor, base, count), t.clampPoint(focus, base, count) + if focus.Line < anchor.Line { + anchor.Line, focus.Line = focus.Line, anchor.Line + } + from, to := min(anchor.Column, focus.Column), max(anchor.Column, focus.Column) + + var result strings.Builder + result.Grow(int(min(focus.Line-anchor.Line+1, 1<<16)) * (to - from + 1)) + for line := anchor.Line; line <= focus.Line; line++ { + if line > anchor.Line { + result.WriteByte('\n') + } + row := t.rowOf(t.bufferLine(int(line - base))) + start := from + if start > 0 && start < len(row.Cells) && row.Cells[start].Attr&WideTail != 0 { + start-- + } + writeSelectedCells(&result, row, start, to) + } + return result.String() +} + // lineBase is the line number of retained-buffer index 0. func (t *Terminal) lineBase() uint64 { if t.onAlt { diff --git a/desktop/internal/term/selection_test.go b/desktop/internal/term/selection_test.go index 573882c56e..df611aef54 100644 --- a/desktop/internal/term/selection_test.go +++ b/desktop/internal/term/selection_test.go @@ -81,6 +81,61 @@ func TestCustomWordSeparatorsKeepPathsTogetherAndPreserveWideCells(t *testing.T) } } +func TestBlockRangeTakesTheRectangleAcrossRows(t *testing.T) { + tests := []struct { + name string + cols, rows int + input string + anchor Position + focus Position + want string + }{ + {"aligned column", 16, 4, "name value\r\nalpha 1234\r\nbeta 5678\r\n", Position{0, 8}, Position{2, 12}, "value\n1234\n5678"}, + {"backward", 16, 4, "name value\r\nalpha 1234\r\nbeta 5678\r\n", Position{2, 12}, Position{0, 8}, "value\n1234\n5678"}, + {"trailing blanks", 8, 2, "ab\r\ncd", Position{0, 1}, Position{1, 5}, "b\nd"}, + {"wide head kept whole", 6, 1, "A世Z", Position{0, 2}, Position{0, 3}, "世Z"}, + {"combining mark", 6, 1, "A世éZ", Position{0, 3}, Position{0, 4}, "éZ"}, + {"soft wrap rows stay separate", 4, 3, "abcdefgh", Position{0, 1}, Position{1, 2}, "bc\nfg"}, + {"blank rows stay empty", 5, 3, "\r\n\r\nab", Position{0, 0}, Position{1, 4}, "\n"}, + {"clamped", 8, 2, "top\r\nbottom", Position{-9, -4}, Position{20, 20}, "top\nbottom"}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + for _, chunk := range []int{len(test.input), 1} { + screen := New(test.cols, test.rows, 10) + for input := []byte(test.input); len(input) > 0; { + n := min(chunk, len(input)) + screen.Write(input[:n]) + input = input[n:] + } + if got := screen.BlockRange( + screen.PointAt(screen.clampPosition(test.anchor)), + screen.PointAt(screen.clampPosition(test.focus)), + ); got != test.want { + t.Fatalf("chunk %d block %q, want %q", chunk, got, test.want) + } + } + }) + } +} + +func TestBlockRangeFollowsItsLinesThroughScrolling(t *testing.T) { + screen := New(10, 4, 4) + screen.Write([]byte("one\r\ntwo\r\nthree\r\n")) + from, to := screen.PointAt(Position{Row: 0, Column: 1}), screen.PointAt(Position{Row: 1, Column: 2}) + if got := screen.BlockRange(from, to); got != "ne\nwo" { + t.Fatalf("before output %q", got) + } + screen.Write([]byte("four\r\nfive\r\n")) + if got := screen.BlockRange(from, to); got != "ne\nwo" { + t.Fatalf("after the lines moved into history %q", got) + } + screen.Scroll(2) + if got := screen.BlockRange(from, to); got != "ne\nwo" { + t.Fatalf("after scrolling back %q", got) + } +} + func FuzzSelectedText(f *testing.F) { f.Add([]byte("plain\r\n世界 e\xcc\x81"), uint8(0), uint8(0), uint8(2), uint8(7)) f.Add([]byte("\x1b[31mred\x1b[0m\r\nnext"), uint8(3), uint8(12), uint8(1), uint8(0)) @@ -89,13 +144,15 @@ func FuzzSelectedText(f *testing.F) { for _, value := range input { screen.Write([]byte{value}) } - selected := screen.SelectedText( - Position{Row: int(rowA), Column: int(colA)}, - Position{Row: int(rowB), Column: int(colB)}, - ) + anchor := Position{Row: int(rowA), Column: int(colA)} + focus := Position{Row: int(rowB), Column: int(colB)} + selected := screen.SelectedText(anchor, focus) if !utf8.ValidString(selected) { t.Fatalf("selection is not UTF-8: %q", selected) } + if block := screen.BlockRange(screen.PointAt(anchor), screen.PointAt(focus)); !utf8.ValidString(block) { + t.Fatalf("block is not UTF-8: %q", block) + } }) } diff --git a/desktop/internal/termview/NOTICE b/desktop/internal/termview/NOTICE index d7ceda679d..68af034161 100644 --- a/desktop/internal/termview/NOTICE +++ b/desktop/internal/termview/NOTICE @@ -29,3 +29,15 @@ adapted to the merged View: - dbd2a6f2 Clear sends PowerShell a form feed; here only when the shell runs no program - 2f73c352 the Microsoft Store PowerShell 7 alias is found and preferred - 02916ed5 PowerShell keeps its version banner +- d0759bb3 a drag with Alt (Ctrl+Alt on Linux) selects a block of columns, copied + line by line +- 4116260e Find opens with the selected text of one line as its query + +These Motty changes, older than the port, were in the parts left out at the port and are +taken now: + +- fe2570d9 a paste that finds a picture and no text saves it and types its path; +- ed6db385 here the workbench saves it in the user's cache folder, for local terminals +- 3f7979e4 the cursor shape and thickness are chosen in the settings; here DECSCUSR 0 +- 8a7476b6 also gives the chosen shape back, and the thickness applies to a shape a + program asks for diff --git a/desktop/internal/termview/blink.go b/desktop/internal/termview/blink.go index 166c77e199..dba94eacfe 100644 --- a/desktop/internal/termview/blink.go +++ b/desktop/internal/termview/blink.go @@ -14,13 +14,6 @@ const ( cursorBlinkSpan = 20 * time.Second ) -// How thick the thin cursors draw: the bar's width and the underline's height in -// logical pixels. The block cursor fills its cell and does not follow them. -const ( - cursorBarWidth = float32(3) - cursorUnderlineHeight = float32(2) -) - // cursorBlink is the phase of the terminal's cursor. type cursorBlink struct { since time.Duration // when the cursor last moved or the pane was entered diff --git a/desktop/internal/termview/block_selection_test.go b/desktop/internal/termview/block_selection_test.go new file mode 100644 index 0000000000..8640fa0b91 --- /dev/null +++ b/desktop/internal/termview/block_selection_test.go @@ -0,0 +1,99 @@ +package termview + +import ( + "testing" + + "github.com/vivaui/viva/gfx" +) + +// blockGesture drags from down to the last move with modifiers held and releases there, +// the way a block selection is drawn. +func blockGesture(rig *fontRig, modifiers gfx.Modifiers, down [2]int, moves ...[2]int) { + at := func(cell [2]int) (float32, float32) { + layout := rig.view.layout + return layout.left + (float32(cell[1])+0.5)*rig.view.cellW, layout.top + (float32(cell[0])+0.5)*rig.view.rowH + } + hit := rig.view.cfg.HitID + x, y := at(down) + rig.view.Pointer(gfx.PointerEvent{ + Kind: gfx.PointerDown, Button: gfx.PointerButtonPrimary, ClickCount: 1, Modifiers: modifiers, + Target: hit, X: x, Y: y, + }) + last := down + for _, cell := range moves { + x, y = at(cell) + rig.view.Pointer(gfx.PointerEvent{ + Kind: gfx.PointerMove, Button: gfx.PointerButtonPrimary, Captured: true, Modifiers: modifiers, + Target: hit, X: x, Y: y, + }) + last = cell + } + x, y = at(last) + rig.view.Pointer(gfx.PointerEvent{ + Kind: gfx.PointerUp, Button: gfx.PointerButtonPrimary, Captured: true, Modifiers: modifiers, + Target: hit, X: x, Y: y, + }) +} + +const blockTable = "name value\r\nalpha 1234\r\nbeta 5678\r\n" + +// Dragging with the block chord held selects the rectangle under the drag: copying it +// gives the column alone, and painting marks the same columns on each of its rows. +func TestBlockDragSelectsTheRectangleAndCopiesIt(t *testing.T) { + rig := newFontRig(t) + output(rig.view, &rig.shell.fakeShell, blockTable) + rig.paint() + blockGesture(rig, blockSelectionModifiers(), [2]int{0, 8}, [2]int{1, 10}, [2]int{2, 12}) + + if got := rig.view.SelectionText(); got != "value\n1234\n5678" { + t.Fatalf("block drag copied %q", got) + } + cols, _ := rig.view.screen.Size() + for row := 0; row < 3; row++ { + from, to, selected := rig.view.selection.span(rig.view.screen.LineNumber(row), rig.view.screen.Row(row), cols) + if !selected || from != 8 || to != 13 { + t.Fatalf("row %d span %d..%d, %v", row, from, to, selected) + } + } + if _, _, selected := rig.view.selection.span(rig.view.screen.LineNumber(3), rig.view.screen.Row(3), cols); selected { + t.Fatal("a row below the rectangle is painted as selected") + } + + // A plain drag afterwards selects text again, not a rectangle. + blockGesture(rig, 0, [2]int{0, 8}, [2]int{1, 3}) + if rig.view.selection.block { + t.Fatal("a plain drag kept the block mode") + } + if got := rig.view.SelectionText(); got != "value\nalph" { + t.Fatalf("plain drag after a block selected %q", got) + } +} + +// The chord without a drag selects nothing and leaves no block mode behind. +func TestBlockPressWithoutADragStaysAClick(t *testing.T) { + rig := newFontRig(t) + blockGesture(rig, blockSelectionModifiers(), [2]int{1, 2}) + if rig.view.selection.selected || rig.view.selection.dragging || rig.view.selection.block { + t.Fatalf("click left %+v", rig.view.selection) + } +} + +// A program that asked for the mouse keeps the chord's press; Shift hands it back to the +// terminal, and the chord then selects the rectangle. +func TestBlockSelectionYieldsToProgramsUsingTheMouse(t *testing.T) { + rig := newFontRig(t) + output(rig.view, &rig.shell.fakeShell, "\x1b[?1000h"+blockTable) + rig.paint() + + blockGesture(rig, blockSelectionModifiers(), [2]int{0, 8}, [2]int{2, 12}) + if rig.view.selection.selected { + t.Fatal("the terminal took a drag the program had the mouse for") + } + if len(rig.shell.input) == 0 { + t.Fatal("the program using the mouse received nothing") + } + blockGesture(rig, gfx.ModifierShift|blockSelectionModifiers(), [2]int{0, 8}, [2]int{2, 12}) + if got := rig.view.SelectionText(); got != "value\n1234\n5678" { + t.Fatalf("Shift+block drag selected %q", got) + } +} diff --git a/desktop/internal/termview/cursor.go b/desktop/internal/termview/cursor.go new file mode 100644 index 0000000000..839d1e4a85 --- /dev/null +++ b/desktop/internal/termview/cursor.go @@ -0,0 +1,54 @@ +package termview + +import "github.com/1lck/Lithe-IDEA/desktop/internal/term" + +// CursorThickness is how thick the thin cursors draw: the bar's width and the underline's +// height. The block cursor fills its cell whatever it is. Ported from motty 8a7476b6. +type CursorThickness uint8 + +const ( + // CursorNormal is the thickness a terminal draws with when nothing is chosen. + CursorNormal CursorThickness = iota + CursorThin + CursorThick +) + +// bar is the width of the bar cursor in logical pixels. +func (k CursorThickness) bar() float32 { + switch k { + case CursorThin: + return 2 + case CursorThick: + return 5 + } + return 3 +} + +// underline is the height of the underline cursor in logical pixels. +func (k CursorThickness) underline() float32 { + switch k { + case CursorThin: + return 1 + case CursorThick: + return 3 + } + return 2 +} + +// Cursor is the cursor the user chose for the terminal: the shape it takes until a program +// asks for its own with DECSCUSR, and how thick a bar or an underline draws, whichever chose +// the shape. The zero Cursor is the block of normal thickness a terminal starts with. Ported +// from motty 3f7979e4. +type Cursor struct { + Shape term.CursorStyle + Thickness CursorThickness +} + +// SetCursor changes the cursor to c from the next Paint on. The workbench calls it every frame +// with the cursor its settings name, so a cursor equal to the one in use changes nothing. A +// shape a program has asked for stays until the program resets the terminal or asks for the +// default again; the thickness applies to whichever shape is drawn. +func (v *View) SetCursor(c Cursor) { + v.cursorThickness = c.Thickness + v.screen.SetDefaultCursor(c.Shape) +} diff --git a/desktop/internal/termview/cursor_test.go b/desktop/internal/termview/cursor_test.go new file mode 100644 index 0000000000..5fd09b616b --- /dev/null +++ b/desktop/internal/termview/cursor_test.go @@ -0,0 +1,75 @@ +package termview + +import ( + "testing" + + "github.com/vivaui/viva/gfx" + + "github.com/1lck/Lithe-IDEA/desktop/internal/term" +) + +// cursorRectangle is the rectangle of the cursor color the last paint drew from the cursor's +// top-left corner or along its cell's bottom edge, as a bar or an underline is. +func cursorRectangle(t *testing.T, rig *fontRig, what string) gfx.Rect { + t.Helper() + x, y := rig.view.layout.left, rig.view.layout.top + return rectangleWhere(t, rig.canvas, what, func(r gfx.Rectangle) bool { + return r.Color == fontTestLook.Cursor && r.Bounds.X == x && + (r.Bounds.Y == y && r.Bounds.Height == rig.view.rowH || r.Bounds.Y+r.Bounds.Height == y+rig.view.rowH && r.Bounds.Width == rig.view.cellW) + }).Bounds +} + +// The shape chosen is the cursor's until a program asks for another, and the thickness +// chosen is how wide the bar and how tall the underline draw, whichever asked for them. +func TestChosenCursorShapesAndThicknessesPaint(t *testing.T) { + tests := []struct { + name string + cursor Cursor + program string + bar bool + thickness float32 + }{ + {"normal bar", Cursor{Shape: term.CursorBar}, "", true, 3}, + {"thin bar", Cursor{Shape: term.CursorBar, Thickness: CursorThin}, "", true, 2}, + {"thick bar", Cursor{Shape: term.CursorBar, Thickness: CursorThick}, "", true, 5}, + {"normal underline", Cursor{Shape: term.CursorUnderline}, "", false, 2}, + {"thin underline", Cursor{Shape: term.CursorUnderline, Thickness: CursorThin}, "", false, 1}, + {"thick underline", Cursor{Shape: term.CursorUnderline, Thickness: CursorThick}, "", false, 3}, + {"a program's underline at the chosen thickness", Cursor{Shape: term.CursorBar, Thickness: CursorThick}, "\x1b[4 q", false, 3}, + {"a program's bar over a chosen block", Cursor{Thickness: CursorThin}, "\x1b[6 q", true, 2}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + rig := newFontRig(t) + rig.view.SetCursor(test.cursor) + rig.print(test.program) + rig.paint() + bounds := cursorRectangle(t, rig, "bar or underline cursor") + switch { + case test.bar && (bounds.Width != test.thickness || bounds.Height != rig.view.rowH): + t.Fatalf("bar drawn %v by %v, want %v wide and the row's %v tall", bounds.Width, bounds.Height, test.thickness, rig.view.rowH) + case !test.bar && (bounds.Height != test.thickness || bounds.Width != rig.view.cellW): + t.Fatalf("underline drawn %v by %v, want the cell's %v wide and %v tall", bounds.Width, bounds.Height, rig.view.cellW, test.thickness) + } + }) + } +} + +// A block chosen, or none chosen, keeps the cursor its cell's outline while the terminal does +// not have the keyboard, whatever the thickness. +func TestChosenBlockCursorStaysTheCellsOutline(t *testing.T) { + rig := newFontRig(t) + rig.view.SetCursor(Cursor{Shape: term.CursorBar, Thickness: CursorThick}) + rig.paint() + rig.view.SetCursor(Cursor{Thickness: CursorThick}) + rig.paint() + x, y := rig.view.layout.left, rig.view.layout.top + rectangleWhere(t, rig.canvas, "left edge of the block's outline", func(r gfx.Rectangle) bool { + return r.Color == fontTestLook.Cursor && r.Bounds.X == x && r.Bounds.Y == y && r.Bounds.Width == 1 && r.Bounds.Height == rig.view.rowH + }) + for _, r := range rig.canvas.Rectangles() { + if r.Color == fontTestLook.Cursor && r.Bounds.Width > 1 && r.Bounds.Height > 1 { + t.Fatalf("a block cursor drew a bar or an underline: %+v", r.Bounds) + } + } +} diff --git a/desktop/internal/termview/input.go b/desktop/internal/termview/input.go index 97c491a93f..056e928c8a 100644 --- a/desktop/internal/termview/input.go +++ b/desktop/internal/termview/input.go @@ -247,6 +247,9 @@ func (v *View) terminalText(event app.TextEvent) app.TextState { case app.TextPaste: redraw = v.sendInput(term.EncodePaste(event.Text, v.screen.Modes().BracketedPaste)) && moved case app.TextPasteNoText: + if v.pasteImage() { + break + } // A clipboard with no words in it is not an empty one: a program that reads // pictures from the clipboard itself waits for a paste with no content to do so, as // it gets from other terminals. Without bracketed paste an empty paste is no event @@ -283,6 +286,11 @@ func (v *View) paste() { return } value, err := v.cfg.Clipboard() + // Some systems answer a text request on a clipboard holding only a picture with an + // error rather than with nothing, so the picture is looked for either way. + if (err != nil || value == "") && v.pasteImage() { + return + } if err != nil { return } @@ -291,6 +299,13 @@ func (v *View) paste() { v.sendInput(term.EncodePaste(value, v.screen.Modes().BracketedPaste)) } +// pasteImage offers a paste that found no text to Config.PasteImage and reports whether +// it was taken. A view without a live shell has nowhere to type a path, so it offers +// nothing. +func (v *View) pasteImage() bool { + return v.shell != nil && v.cfg.PasteImage != nil && v.cfg.PasteImage() +} + // scrollView moves the view by lines, positive going back into history. It is handled even // when the view does not move, so the key or press that asked is not taken for something // else. diff --git a/desktop/internal/termview/paint.go b/desktop/internal/termview/paint.go index ed729f4665..0546d35808 100644 --- a/desktop/internal/termview/paint.go +++ b/desktop/internal/termview/paint.go @@ -143,10 +143,12 @@ func (v *View) paintGrid(canvas *gfx.Canvas, layout geometry) { // The input method draws over these cells, which the rows left empty. case cursor.Style == term.CursorUnderline: // The thin cursors keep their shape against the row, like the block that fills it: - // the underline is its bottom edge and the bar runs its whole height. - canvas.Fill(gfx.Rect{X: x, Y: y + rowHeight - cursorUnderlineHeight, Width: cellWidth, Height: cursorUnderlineHeight}, cursorColor) + // the underline is its bottom edge and the bar runs its whole height. Neither is + // thicker than the cell, however small the font. + height := min(v.cursorThickness.underline(), rowHeight) + canvas.Fill(gfx.Rect{X: x, Y: y + rowHeight - height, Width: cellWidth, Height: height}, cursorColor) case cursor.Style == term.CursorBar: - canvas.Fill(gfx.Rect{X: x, Y: y, Width: cursorBarWidth, Height: rowHeight}, cursorColor) + canvas.Fill(gfx.Rect{X: x, Y: y, Width: min(v.cursorThickness.bar(), cellWidth), Height: rowHeight}, cursorColor) case !focused: // A block cursor outlines its cell while the terminal does not have the keyboard. canvas.Fill(gfx.Rect{X: x, Y: y, Width: cellWidth, Height: 1}, cursorColor) diff --git a/desktop/internal/termview/paste_image_test.go b/desktop/internal/termview/paste_image_test.go new file mode 100644 index 0000000000..6fdb9636e4 --- /dev/null +++ b/desktop/internal/termview/paste_image_test.go @@ -0,0 +1,75 @@ +package termview + +import ( + "errors" + "testing" + + "github.com/vivaui/viva/app" +) + +// A paste that finds no text asks PasteImage first. When it takes the paste nothing more is +// sent; when it declines, a program using bracketed paste gets the empty paste it waits for. +func TestPasteWithoutTextAsksForAPictureFirst(t *testing.T) { + const emptyPaste = "\x1b[200~\x1b[201~" + tests := []struct { + name string + taken bool + want string + }{ + {"taken", true, ""}, + {"declined", false, emptyPaste}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + rig := newFontRig(t) + output(rig.view, &rig.shell.fakeShell, "\x1b[?2004h") + asked := 0 + rig.view.cfg.PasteImage = func() bool { asked++; return test.taken } + + rig.view.terminalText(app.TextEvent{Kind: app.TextPasteNoText}) + if asked != 1 || string(rig.shell.input) != test.want { + t.Fatalf("text-system paste: asked %d, sent %q, want once and %q", asked, rig.shell.input, test.want) + } + + rig.shell.input = nil + rig.view.cfg.Clipboard = func() (string, error) { return "", nil } + rig.view.paste() + if asked != 2 || string(rig.shell.input) != test.want { + t.Fatalf("shortcut paste: asked %d, sent %q, want twice and %q", asked, rig.shell.input, test.want) + } + }) + } +} + +// A clipboard that holds text pastes the text and never asks for a picture; one that cannot +// be read as text still has its picture looked for, and sends nothing when there is none. +func TestPasteAsksForAPictureOnlyWithoutText(t *testing.T) { + rig := newFontRig(t) + asked := 0 + rig.view.cfg.PasteImage = func() bool { asked++; return false } + + rig.view.cfg.Clipboard = func() (string, error) { return "ls", nil } + rig.view.paste() + if asked != 0 || string(rig.shell.input) != "ls" { + t.Fatalf("text paste: asked %d, sent %q", asked, rig.shell.input) + } + + rig.shell.input = nil + rig.view.cfg.Clipboard = func() (string, error) { return "", errors.New("no text flavor") } + rig.view.paste() + if asked != 1 || len(rig.shell.input) != 0 { + t.Fatalf("unreadable clipboard: asked %d, sent %q", asked, rig.shell.input) + } +} + +// A view whose program has ended has nowhere to type a path, so it offers nothing. +func TestEndedTerminalOffersNoPicturePaste(t *testing.T) { + rig := newFontRig(t) + asked := 0 + rig.view.cfg.PasteImage = func() bool { asked++; return true } + rig.view.shell = nil + rig.view.terminalText(app.TextEvent{Kind: app.TextPasteNoText}) + if asked != 0 { + t.Fatalf("an ended terminal asked for a picture %d times", asked) + } +} diff --git a/desktop/internal/termview/selection.go b/desktop/internal/termview/selection.go index a1ce68b870..3a5cf9a576 100644 --- a/desktop/internal/termview/selection.go +++ b/desktop/internal/termview/selection.go @@ -2,6 +2,7 @@ package termview import ( "math" + "runtime" "time" "github.com/1lck/Lithe-IDEA/desktop/internal/term" @@ -25,6 +26,21 @@ type terminalSelection struct { // clicked; the drag keeps it selected whichever way it goes. unit selectionUnit origin [2]term.Point + // block selects the rectangle between anchor and focus instead of the text + // between them. It is set by the press that began the selection and kept by + // the drags and Shift-clicks that continue it. + block bool +} + +// blockSelectionModifiers is the chord held to start a block selection, by the +// platform's own terminal: Option on macOS (Terminal), Alt on Windows (Windows +// Terminal), and Ctrl+Alt on Linux (Konsole and Ghostty), where a window +// manager usually takes Alt+drag for moving the window. +func blockSelectionModifiers() gfx.Modifiers { + if runtime.GOOS == "darwin" || runtime.GOOS == "windows" { + return gfx.ModifierAlt + } + return gfx.ModifierControl | gfx.ModifierAlt } // selectionUnit is the granularity a drag snaps to. @@ -163,6 +179,15 @@ func (selection *terminalSelection) begin(point term.Point) bool { return changed } +// beginBlock starts a rectangular selection at point and leaves the drag +// running. A rectangle of one cell selects nothing, exactly as a linear +// selection of one cell does, so a press that never moves stays a click. +func (selection *terminalSelection) beginBlock(point term.Point) bool { + changed := selection.begin(point) + selection.block = true + return changed +} + // extendTo is a Shift-click: the selection, or failing one the last press, is // stretched to point, as terminals have always done. With a selection the end // nearer to point moves and the other stays, so it grows or shrinks from either @@ -234,11 +259,15 @@ func (selection *terminalSelection) selectRange(anchor, focus term.Point) { selection.dragging = false selection.selected = true selection.unit = unitCell + selection.block = false selection.edge = selectionEdge{} } // text is the selected text, wherever in the retained buffer it lies. func (selection terminalSelection) text(screen *term.Terminal) string { + if selection.block { + return screen.BlockRange(selection.anchor, selection.focus) + } return screen.SelectedRange(selection.anchor, selection.focus) } @@ -256,11 +285,15 @@ func (selection terminalSelection) span(lineNumber uint64, line term.Row, cols i return 0, 0, false } from, to := 0, cols - if lineNumber == start.Line { - from = start.Column - } - if lineNumber == end.Line { - to = end.Column + 1 + if selection.block { + from, to = min(start.Column, end.Column), max(start.Column, end.Column)+1 + } else { + if lineNumber == start.Line { + from = start.Column + } + if lineNumber == end.Line { + to = end.Column + 1 + } } if from < len(line.Cells) && line.Cells[from].Attr&term.WideTail != 0 && from > 0 { from-- @@ -349,6 +382,12 @@ func (v *View) terminalPointer(event gfx.PointerEvent) gfx.EventResult { return gfx.EventResult{Handled: true, Repaint: changed} } } + // The chord rides on a press the terminal owns: a program using the mouse + // had the press above. The press starts the rectangle and the drag that + // continues it keeps the same mode. + if chord := blockSelectionModifiers(); event.Modifiers&chord == chord { + return gfx.EventResult{Handled: true, Repaint: selection.beginBlock(v.screen.PointAt(position))} + } return gfx.EventResult{Handled: true, Repaint: selection.begin(v.screen.PointAt(position))} case gfx.PointerMove: if !selection.dragging || !event.Captured { diff --git a/desktop/internal/termview/view.go b/desktop/internal/termview/view.go index dd673abf75..d407ad8162 100644 --- a/desktop/internal/termview/view.go +++ b/desktop/internal/termview/view.go @@ -159,6 +159,12 @@ type Config struct { Exited func(status *int) // Clipboard reads the system clipboard for a paste. Nil uses app.ClipboardText. Clipboard func() (string, error) + // PasteImage is asked first when a paste into a live shell finds no text on the + // clipboard, and reports whether it took the paste over, as the workbench does + // for a picture it saves and types the path of. Nil, or a false answer, sends the + // empty paste a program that reads the clipboard itself waits for. It runs on the + // window thread and must not block. + PasteImage func() bool // OpenLink opens a link the user Command- (Control- off macOS) clicked. Nil leaves // links inert. OpenLink func(target string) @@ -245,6 +251,8 @@ type View struct { // scrollbar) uses rowH; only the text itself is drawn glyphH tall. cellW, glyphH, rowH float32 layout geometry // the grid of the last paint + // cursorThickness is how thick a bar or an underline cursor draws; SetCursor sets it. + cursorThickness CursorThickness look Look hasLook bool diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index d7582b5dfc..1d6531598f 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -326,6 +326,11 @@ type settings struct { // TerminalScrollback is the history lines a new terminal keeps; zero is // settingswindow.DefaultScrollback. TerminalScrollback int `json:"terminalScrollback,omitempty"` + // TerminalCursorShape and TerminalCursorThickness are the terminal cursor the + // Terminal page chose, as settingswindow.Values holds them; empty is the block of + // normal thickness. See terminalCursor. + TerminalCursorShape string `json:"terminalCursorShape,omitempty"` + TerminalCursorThickness string `json:"terminalCursorThickness,omitempty"` // ProcessTermination is the user's part of Core's process termination settings, as the // Process Termination page edits it; the zero value keeps Core's defaults. ProcessTermination settingswindow.ProcessTermination `json:"processTermination,omitzero"` @@ -478,6 +483,11 @@ type App struct { recentFiles recentFileState drafts draftListState editorPreferences core.EditorPreferences + // clipboardImage and pasteDirectory replace, in tests, reading the clipboard's picture + // and the cache folder a picture pasted into a terminal is saved in + // (terminal_paste_image.go); nil is the system's. + clipboardImage func() ([]byte, error) + pasteDirectory func() (string, error) // debugAttach are the host and port fields of the Debug panel's attach form. debugAttach debugAttachFields // root is the window's page; dnd are its drag and drop gestures and focus the control diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index e16c738215..5a16b23b09 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -319,6 +319,7 @@ func (a *App) terminalInput(t *terminal) { // written in. t.view.SetMessages(a.terminalMessages()) t.view.SetFont(a.terminalFont()) + t.view.SetCursor(a.terminalCursor()) t.view.Paint(dc.Canvas, dc.Rect, a.terminalLook()) } } diff --git a/desktop/internal/workbench/settings.go b/desktop/internal/workbench/settings.go index a82fddc763..466c85ac5c 100644 --- a/desktop/internal/workbench/settings.go +++ b/desktop/internal/workbench/settings.go @@ -228,6 +228,9 @@ func (a *App) newSettingsWindow() *settingswindow.Controller { SetTerminalScrollback: func(lines int) { a.post(func(a *App) { a.setTerminalScrollback(lines) }) }, + SetTerminalCursor: func(shape, thickness string) { + a.post(func(a *App) { a.setTerminalCursor(shape, thickness) }) + }, ResetLayout: func() { a.post(func(a *App) { a.resetLayout() }) }, @@ -404,6 +407,7 @@ func (a *App) openSettingsPageWith(surface actionSurface, page settingsPage, que EditorTabRows: a.settings.EditorTabRows, EditorTabOverflow: a.settings.EditorTabOverflow, EditorTabLimit: settingswindow.TabLimitOf(a.settings.EditorTabLimit), EditorTabPolicy: a.settings.EditorTabPolicy, TerminalShell: a.settings.TerminalShell, TerminalScrollback: a.terminalScrollback(), + TerminalCursorShape: settingswindow.NormalCursorShape(a.settings.TerminalCursorShape), TerminalCursorThickness: settingswindow.NormalCursorThickness(a.settings.TerminalCursorThickness), HideProjectColors: a.settings.HideProjectColors, ProjectOpenDestination: a.settings.ProjectOpenDestination, HideGitGutter: a.settings.HideGitGutter, InlineGitBlame: a.settings.InlineGitBlame, HideChangeLists: a.settings.HideChangeLists, HideParentReferences: a.settings.HideParentReferences, diff --git a/desktop/internal/workbench/terminal_cursor_test.go b/desktop/internal/workbench/terminal_cursor_test.go new file mode 100644 index 0000000000..c87c58fe0e --- /dev/null +++ b/desktop/internal/workbench/terminal_cursor_test.go @@ -0,0 +1,87 @@ +package workbench + +import ( + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow" + "github.com/1lck/Lithe-IDEA/desktop/internal/term" + "github.com/1lck/Lithe-IDEA/desktop/internal/termview" +) + +// The stored cursor names the cursor the terminals draw; a value the Terminal page does not +// offer is the default block of normal thickness. +func TestTerminalCursorFollowsTheStoredChoice(t *testing.T) { + tests := []struct { + shape, thickness string + want termview.Cursor + }{ + {"", "", termview.Cursor{}}, + {"bar", "thick", termview.Cursor{Shape: term.CursorBar, Thickness: termview.CursorThick}}, + {"underline", "thin", termview.Cursor{Shape: term.CursorUnderline, Thickness: termview.CursorThin}}, + {"beam", "heavy", termview.Cursor{}}, + } + for _, test := range tests { + a := &App{settings: settings{TerminalCursorShape: test.shape, TerminalCursorThickness: test.thickness}} + if got := a.terminalCursor(); got != test.want { + t.Errorf("%q %q: cursor %+v, want %+v", test.shape, test.thickness, got, test.want) + } + } +} + +// barWidths are the widths of the tall thin rectangles the last frame drew inside the +// terminal, the bar cursor among them. +func barWidths(h *harness, terminal *terminal) map[float32]bool { + area := h.topHit(terminal.hit) + widths := map[float32]bool{} + for _, primitive := range h.driver.Snapshot().Primitives { + bounds := primitive.Bounds + if bounds.Width > 1 && bounds.Width <= 5 && bounds.Height >= 8 && + bounds.X >= area.X && bounds.X+bounds.Width <= area.X+area.Width && bounds.Y >= area.Y && bounds.Y+bounds.Height <= area.Y+area.Height { + widths[bounds.Width] = true + } + } + return widths +} + +// A cursor chosen on the Terminal page is stored, shown back to the page, and drawn at once by +// a terminal already open. +func TestChosenTerminalCursorReachesOpenTerminals(t *testing.T) { + h, terminal, _ := pasteTerminal(t, nil) + h.settle() + if !h.app.chrome.isOpen(catalogIndex[itemTerminal]) { + h.click(center(h.button(itemTerminal))) + } + h.settle() + if terminal.hit.IsZero() { + t.Fatal("the terminal is not shown") + } + // choose hands the choice over as the settings window's SetTerminalCursor does. + choose := func(shape, thickness string) { + h.app.post(func(a *App) { a.setTerminalCursor(shape, thickness) }) + h.settle() + } + if widths := barWidths(h, terminal); widths[5] || widths[2] { + t.Fatalf("the default cursor drew a bar: %v", widths) + } + + choose(settingswindow.CursorShapeBar, settingswindow.CursorThicknessThick) + if widths := barWidths(h, terminal); !widths[5] { + t.Fatalf("a thick bar was not drawn in the open terminal: %v", widths) + } + choose(settingswindow.CursorShapeBar, settingswindow.CursorThicknessThin) + if widths := barWidths(h, terminal); !widths[2] || widths[5] { + t.Fatalf("a thin bar was not drawn in the open terminal: %v", widths) + } + + var stored settings + if _, err := h.app.store.Load(settingsFile, &stored); err != nil { + t.Fatal(err) + } + if stored.TerminalCursorShape != "bar" || stored.TerminalCursorThickness != "thin" { + t.Fatalf("stored %q %q, want bar thin", stored.TerminalCursorShape, stored.TerminalCursorThickness) + } + h.app.setTerminalCursor("beam", "") + if h.app.settings.TerminalCursorShape != settingswindow.CursorShapeBlock || h.app.settings.TerminalCursorThickness != settingswindow.CursorThicknessNormal { + t.Fatalf("an unknown shape was stored as %q %q", h.app.settings.TerminalCursorShape, h.app.settings.TerminalCursorThickness) + } +} diff --git a/desktop/internal/workbench/terminal_env.go b/desktop/internal/workbench/terminal_env.go index d02ed520e6..1fe34a2e6a 100644 --- a/desktop/internal/workbench/terminal_env.go +++ b/desktop/internal/workbench/terminal_env.go @@ -2,6 +2,8 @@ package workbench import ( "github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow" + "github.com/1lck/Lithe-IDEA/desktop/internal/term" + "github.com/1lck/Lithe-IDEA/desktop/internal/termview" ) // inheritedColorVariables are variables the window may have inherited (from a CI runner, @@ -44,3 +46,32 @@ func (a *App) setTerminalScrollback(lines int) { a.settings.TerminalScrollback = lines a.saveSettings() } + +// terminalCursor is the cursor the Terminal settings page chose, handed to every terminal at +// each paint (matrix id terminal-interaction). A value the page does not offer is the default. +func (a *App) terminalCursor() termview.Cursor { + var cursor termview.Cursor + switch settingswindow.NormalCursorShape(a.settings.TerminalCursorShape) { + case settingswindow.CursorShapeBar: + cursor.Shape = term.CursorBar + case settingswindow.CursorShapeUnderline: + cursor.Shape = term.CursorUnderline + } + switch settingswindow.NormalCursorThickness(a.settings.TerminalCursorThickness) { + case settingswindow.CursorThicknessThin: + cursor.Thickness = termview.CursorThin + case settingswindow.CursorThicknessThick: + cursor.Thickness = termview.CursorThick + } + return cursor +} + +// setTerminalCursor stores the terminal cursor; open terminals take it at their next paint. +func (a *App) setTerminalCursor(shape, thickness string) { + shape, thickness = settingswindow.NormalCursorShape(shape), settingswindow.NormalCursorThickness(thickness) + if a.settings.TerminalCursorShape == shape && a.settings.TerminalCursorThickness == thickness { + return + } + a.settings.TerminalCursorShape, a.settings.TerminalCursorThickness = shape, thickness + a.saveSettings() +} diff --git a/desktop/internal/workbench/terminal_find.go b/desktop/internal/workbench/terminal_find.go index 7dc6b3e760..3403a8a7be 100644 --- a/desktop/internal/workbench/terminal_find.go +++ b/desktop/internal/workbench/terminal_find.go @@ -3,23 +3,68 @@ package workbench import ( "net/url" "strconv" + "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/1lck/Lithe-IDEA/desktop/internal/termview" "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/text" "github.com/vivaui/viva/ui" ) +// terminalFindMaxQuery bounds, in characters, the query a selection fills Find with, so a +// whole selected screen costs no more than a selected word. +const terminalFindMaxQuery = 256 + // terminalFind is a terminal's Find bar: the query, what the last search found and // whether the bar is shown. type terminalFind struct { - open bool - field ui.Field + open bool + field ui.Field + // editor is the field's text, bound once the bar first opens so that opening it can + // select the query. + editor *text.Editor query string count, current int focus bool } +// show opens the bar with the keyboard on its field. A first open takes a selection of +// one line as the query; either way the field's text ends up selected, so typing or +// pasting a new query replaces it. +func (f *terminalFind) show(selection string) { + if f.editor == nil { + f.editor = text.NewEditor("") + f.field.Bind(f.editor) + } + if !f.open { + if query := terminalFindQuery(selection); query != "" { + f.field.SetText(query) + } + } + f.editor.SetSelection(text.Range{Start: 0, End: f.editor.RuneCount()}) + f.open, f.focus = true, true +} + +// terminalFindQuery is a terminal selection as a Find query, or "" when it is not one +// that can be searched: Find matches within a line, so a selection crossing a line +// break finds nothing and is left out, as Windows Terminal leaves it out. The query is +// cut to terminalFindMaxQuery characters, with trailing blanks dropped. +func terminalFindQuery(selected string) string { + if strings.ContainsAny(selected, "\r\n") { + return "" + } + end, kept := len(selected), 0 + for index := range selected { + if kept == terminalFindMaxQuery { + end = index + break + } + kept++ + } + return strings.TrimRight(selected[:end], " \t") +} + // focusedTerminalTab is the terminal whose grid has the keyboard. func (a *App) focusedTerminalTab(id gfx.ID) *terminal { if p := a.project; p != nil { @@ -41,7 +86,11 @@ func (a *App) terminalFindShortcut(event gfx.KeyEvent) gfx.EventResult { if t == nil { return gfx.EventResult{} } - t.find.open, t.find.focus = true, true + selection := "" + if !t.find.open && t.view.HasSelection() { + selection = t.view.SelectionText() + } + t.find.show(selection) a.performed("terminal.find.open", surfaceShortcut) return gfx.EventResult{Handled: true, Repaint: true} } diff --git a/desktop/internal/workbench/terminal_find_test.go b/desktop/internal/workbench/terminal_find_test.go new file mode 100644 index 0000000000..434a68796e --- /dev/null +++ b/desktop/internal/workbench/terminal_find_test.go @@ -0,0 +1,70 @@ +package workbench + +import ( + "strings" + "testing" + + "github.com/vivaui/viva/text" +) + +// Opening Find with a selection of one line searches for it, and the query is selected so +// that a paste replaces it. +func TestTerminalFindOpensWithTheSelectionSelected(t *testing.T) { + var find terminalFind + find.show("needle") + if !find.open || !find.focus { + t.Fatalf("show left open=%v focus=%v", find.open, find.focus) + } + if got := find.field.Text(); got != "needle" { + t.Fatalf("query = %q, want the selected text", got) + } + if got, want := find.editor.Selection(), (text.Range{Start: 0, End: 6}); got != want { + t.Fatalf("query selection = %+v, want %+v", got, want) + } +} + +// Opening again while the bar is open keeps what was typed, whatever is selected in the +// terminal now, and selects it. +func TestReopeningTerminalFindSelectsItsQuery(t *testing.T) { + var find terminalFind + find.show("") + find.editor.Insert("typed") + if got := find.editor.Selection(); got.Start != got.End { + t.Fatalf("typing left %+v selected", got) + } + find.show("other") + if got := find.field.Text(); got != "typed" { + t.Fatalf("reopening replaced the query with %q", got) + } + if got, want := find.editor.Selection(), (text.Range{Start: 0, End: 5}); got != want { + t.Fatalf("reopened selection = %+v, want %+v", got, want) + } +} + +// Find matches within a line, so a selection across a line break is no query; a long one +// is cut to the field's limit; trailing blanks are dropped. +func TestTerminalFindQueryFromASelection(t *testing.T) { + long := strings.Repeat("界", terminalFindMaxQuery+10) + tests := []struct { + name, selected, want string + }{ + {"word", "needle", "needle"}, + {"trailing blanks", "needle \t ", "needle"}, + {"two lines", "one\ntwo", ""}, + {"carriage return", "one\rtwo", ""}, + {"empty", "", ""}, + {"long", long, strings.Repeat("界", terminalFindMaxQuery)}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if got := terminalFindQuery(test.selected); got != test.want { + t.Fatalf("query %q, want %q", got, test.want) + } + }) + } + var find terminalFind + find.show("one\ntwo") + if got := find.field.Text(); got != "" { + t.Fatalf("a selection across lines filled the query with %q", got) + } +} diff --git a/desktop/internal/workbench/terminal_paste_image.go b/desktop/internal/workbench/terminal_paste_image.go new file mode 100644 index 0000000000..dcbf046bcc --- /dev/null +++ b/desktop/internal/workbench/terminal_paste_image.go @@ -0,0 +1,179 @@ +package workbench + +import ( + "context" + "errors" + "os" + "path/filepath" + "runtime" + "strings" + "time" + "unicode" + + "github.com/vivaui/viva/app" + + "github.com/1lck/Lithe-IDEA/desktop/internal/localshell" +) + +// This file pastes a picture into a terminal (matrix id terminal-interaction). A paste that finds +// a picture and no text on the clipboard saves the picture as a PNG file private to the user and +// types the file's path at the prompt, the way a dropped file is typed, so a program such as Codex +// or Claude Code reads the picture from there. A clipboard with neither keeps the empty paste +// termview sends, which programs that read the clipboard themselves wait for. +// +// The files live in the user's cache directory (Library/Caches on macOS, %LocalAppData% on +// Windows), in a folder only the user can read, and never in the application bundle or the +// installation directory, so code signing and update deltas do not see them. The window owns +// them: each paste writes one, and removes the ones older than terminalPasteKeep, which gives the +// program that was handed a path a week to read it. Ported from motty fe2570d9 and ed6db385, for +// local terminals. + +const ( + // terminalPasteKeep is how long a pasted picture stays; the next paste removes older ones. + terminalPasteKeep = 7 * 24 * time.Hour + // terminalPasteTimeout bounds saving one picture. + terminalPasteTimeout = 30 * time.Second +) + +// terminalPasteDirectory is where pasted pictures are saved: the user's cache directory. +func terminalPasteDirectory() (string, error) { + base, err := os.UserCacheDir() + if err != nil { + return "", err + } + return filepath.Join(base, "Lithe", "terminal-paste"), nil +} + +// pasteTerminalImage takes over a paste into t that found no text when the clipboard holds a +// picture, and reports whether it did; false leaves the paste as it was (termview's +// Config.PasteImage). The clipboard is read when the paste is asked for and not before, as +// asking the program that owns it what it holds is not free. +func (a *App) pasteTerminalImage(p *project, t *terminal) bool { + if t.pastingImage { + // One picture at a time: the path of a second one typed while the first is saved + // would come first, or in the middle of what the user types next. + return true + } + read := a.clipboardImage + if read == nil { + read = app.ClipboardImagePNG + } + data, err := read() + switch { + case errors.Is(err, app.ErrNoImage), errors.Is(err, app.ErrUnsupported): + return false + case errors.Is(err, app.ErrTooLarge): + a.notifyError(a.text.Terminal.PasteImageTooLarge) + return true + case err != nil: + a.operationFailed("terminal_paste_image", err) + a.notifyError(a.text.Terminal.PasteImageFailed(err.Error())) + return true + } + t.pastingImage = true + directory := a.pasteDirectory + if directory == nil { + directory = terminalPasteDirectory + } + distro, _ := localshell.WSLDistro(t.shell) + now := a.now() + a.background(p, terminalPasteTimeout, func(context.Context) func(*App) { + path, err := savePastedImage(directory, data, now) + return func(a *App) { a.finishTerminalImage(p, t, path, distro, err) } + }) + return true +} + +// finishTerminalImage types the path of a saved picture into the terminal it was pasted in, or +// says why there is none. A terminal closed in the meantime gets nothing; its picture goes with +// the next paste's tidying. +func (a *App) finishTerminalImage(p *project, t *terminal, path, distro string, err error) { + t.pastingImage = false + if p.terms.find(t.id) != t { + return + } + if err != nil { + a.operationFailed("terminal_paste_image", documentLogError(err)) + a.notifyError(a.text.Terminal.PasteImageFailed(err.Error())) + return + } + // A space follows, as it does when a file is dropped on a terminal, so the next word typed + // is not part of the path. + t.view.Paste(quotePastedPath(path, distro, runtime.GOOS) + " ") +} + +// savePastedImage writes png to a new file of its own in the folder directory names and +// returns the file's path. The folder and the file are private to the user, and the other +// pasted pictures there older than terminalPasteKeep are removed. +func savePastedImage(directory func() (string, error), png []byte, now time.Time) (string, error) { + folder, err := directory() + if err != nil { + return "", err + } + if err := os.MkdirAll(folder, 0o700); err != nil { + return "", err + } + // A folder made before, by hand or by an older build, is made private too. + if err := os.Chmod(folder, 0o700); err != nil { + return "", err + } + file, err := os.CreateTemp(folder, "paste-"+now.Format("20060102-150405")+"-*.png") + if err != nil { + return "", err + } + name := file.Name() + _, err = file.Write(png) + if closeErr := file.Close(); err == nil { + err = closeErr + } + if err != nil { + _ = os.Remove(name) + return "", err + } + prunePastedImages(folder, filepath.Base(name), now) + return name, nil +} + +// prunePastedImages removes the pasted pictures in folder older than terminalPasteKeep, all but +// keep, the one just written. Tidying is a courtesy: the paste has worked whether or not it does. +func prunePastedImages(folder, keep string, now time.Time) { + entries, err := os.ReadDir(folder) + if err != nil { + return + } + cutoff := now.Add(-terminalPasteKeep) + for _, entry := range entries { + name := entry.Name() + if name == keep || !entry.Type().IsRegular() || !strings.HasPrefix(name, "paste-") || !strings.HasSuffix(name, ".png") { + continue + } + if info, err := entry.Info(); err == nil && info.ModTime().Before(cutoff) { + _ = os.Remove(filepath.Join(folder, name)) + } + } +} + +// quotePastedPath writes path so the terminal's shell takes it as one word. In a WSL terminal +// it is the path as the distribution names it, quoted for a POSIX shell; on Windows it is in +// double quotes, which cmd.exe, PowerShell and Git Bash all read; elsewhere a backslash goes +// before every character that is not a plain path character, as Terminal and iTerm2 type a +// dropped file. +func quotePastedPath(path, distro, goos string) string { + switch { + case distro != "": + if linux, ok := localshell.WSLPath(path, distro); ok { + path = linux + } + return "'" + strings.ReplaceAll(path, "'", `'\''`) + "'" + case goos == "windows": + return `"` + strings.ReplaceAll(path, `"`, `""`) + `"` + } + var out strings.Builder + for _, r := range path { + if !unicode.IsLetter(r) && !unicode.IsDigit(r) && !strings.ContainsRune("/._-+:@%,=~", r) { + out.WriteByte('\\') + } + out.WriteRune(r) + } + return out.String() +} diff --git a/desktop/internal/workbench/terminal_paste_image_test.go b/desktop/internal/workbench/terminal_paste_image_test.go new file mode 100644 index 0000000000..a62b9e0106 --- /dev/null +++ b/desktop/internal/workbench/terminal_paste_image_test.go @@ -0,0 +1,207 @@ +package workbench + +import ( + "bytes" + "errors" + "os" + "path/filepath" + "runtime" + "strings" + "testing" + "time" + + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/ui" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" +) + +var pastedPicture = []byte("\x89PNG\r\n\x1a\npicture") + +// A picture is saved to a new private file of its own, and the pictures older than a week +// beside it go; the new one, newer ones and other files stay. +func TestSavePastedImageWritesAPrivateFileAndTidies(t *testing.T) { + folder := filepath.Join(t.TempDir(), "paste") + now := time.Date(2026, 11, 16, 9, 30, 0, 0, time.UTC) + if err := os.MkdirAll(folder, 0o755); err != nil { + t.Fatal(err) + } + old := filepath.Join(folder, "paste-20261101-080000-1.png") + recent := filepath.Join(folder, "paste-20261115-080000-2.png") + other := filepath.Join(folder, "notes.txt") + for _, path := range []string{old, recent, other} { + if err := os.WriteFile(path, []byte("x"), 0o600); err != nil { + t.Fatal(err) + } + } + for path, age := range map[string]time.Duration{old: 8 * 24 * time.Hour, recent: 24 * time.Hour, other: 30 * 24 * time.Hour} { + if err := os.Chtimes(path, now.Add(-age), now.Add(-age)); err != nil { + t.Fatal(err) + } + } + + path, err := savePastedImage(func() (string, error) { return folder, nil }, pastedPicture, now) + if err != nil { + t.Fatal(err) + } + if filepath.Dir(path) != folder || !strings.HasPrefix(filepath.Base(path), "paste-20261116-093000-") || filepath.Ext(path) != ".png" { + t.Fatalf("saved as %q", path) + } + if data, err := os.ReadFile(path); err != nil || !bytes.Equal(data, pastedPicture) { + t.Fatalf("saved %q, %v", data, err) + } + if runtime.GOOS != "windows" { + for target, want := range map[string]os.FileMode{folder: 0o700, path: 0o600} { + if info, err := os.Stat(target); err != nil || info.Mode().Perm() != want { + t.Fatalf("%s mode %v, %v; want %v", target, info.Mode().Perm(), err, want) + } + } + } + if _, err := os.Stat(old); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("a week-old picture stayed: %v", err) + } + for _, kept := range []string{recent, other} { + if _, err := os.Stat(kept); err != nil { + t.Fatalf("%s was removed: %v", kept, err) + } + } +} + +// A folder that cannot be had leaves no file and says why. +func TestSavePastedImageReportsAMissingFolder(t *testing.T) { + blocked := filepath.Join(t.TempDir(), "file") + if err := os.WriteFile(blocked, nil, 0o600); err != nil { + t.Fatal(err) + } + if path, err := savePastedImage(func() (string, error) { return filepath.Join(blocked, "paste"), nil }, pastedPicture, time.Now()); err == nil { + t.Fatalf("saved into a path under a file: %q", path) + } + if _, err := savePastedImage(func() (string, error) { return "", errors.New("no cache") }, pastedPicture, time.Now()); err == nil { + t.Fatal("no cache folder was no error") + } +} + +// The path is one word for the shell it is typed into. +func TestQuotePastedPath(t *testing.T) { + tests := []struct { + name, path, distro, goos, want string + }{ + {"plain", "/Users/me/Library/Caches/Lithe/terminal-paste/paste-1.png", "", "darwin", + "/Users/me/Library/Caches/Lithe/terminal-paste/paste-1.png"}, + {"space and quote", "/Users/my name/it's.png", "", "darwin", `/Users/my\ name/it\'s.png`}, + {"letters kept", "/home/张三/图.png", "", "linux", "/home/张三/图.png"}, + {"windows", `C:\Users\me\AppData\Local\Lithe\terminal-paste\paste-1.png`, "", "windows", + `"C:\Users\me\AppData\Local\Lithe\terminal-paste\paste-1.png"`}, + {"wsl", `C:\Users\me\it's.png`, "Ubuntu", "windows", `'/mnt/c/Users/me/it'\''s.png'`}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if got := quotePastedPath(test.path, test.distro, test.goos); got != test.want { + t.Fatalf("quoted %q, want %q", got, test.want) + } + }) + } +} + +// pasteTerminal opens a terminal whose program echoes what is typed, with the clipboard and +// the cache folder of the test. +func pasteTerminal(t *testing.T, read func() ([]byte, error)) (*harness, *terminal, string) { + t.Helper() + if runtime.GOOS == "windows" { + t.Skip("uses /bin/sh") + } + h := newHarnessWithLanguages(t, &testKernel{Client: core.NewClient()}, []string{"en-US"}) + h.open(t.TempDir()) + folder := t.TempDir() + h.app.clipboardImage = read + h.app.pasteDirectory = func() (string, error) { return folder, nil } + p := h.app.project + term := h.app.newTerminalWith(p, terminalOptions{shell: "/bin/sh", args: []string{"-c", "cat"}, dir: p.root, activate: true}) + if term == nil { + t.Fatal("the terminal was not opened") + } + term.view.Start() + return h, term, folder +} + +// A paste that finds a picture saves it and types the saved file's path at the prompt, and a +// second paste while the first is saved is taken without a second file. +func TestPastingAPictureTypesItsSavedPath(t *testing.T) { + h, term, folder := pasteTerminal(t, func() ([]byte, error) { return pastedPicture, nil }) + if !h.app.pasteTerminalImage(h.app.project, term) { + t.Fatal("a picture paste was not taken") + } + if !h.app.pasteTerminalImage(h.app.project, term) { + t.Fatal("a second paste while saving went through as an empty paste") + } + prefix := quotePastedPath(folder, "", runtime.GOOS) + string(filepath.Separator) + "paste-" + awaitStateWithin(t, h, 10*time.Second, "the saved path to be typed", func() bool { + term.view.Pump() + return strings.Contains(term.view.RetainedText(1<<16), prefix) + }) + if term.pastingImage { + t.Fatal("the terminal still waits for its picture") + } + entries, err := os.ReadDir(folder) + if err != nil || len(entries) != 1 { + t.Fatalf("the folder holds %v, %v; want one picture", entries, err) + } + if data, err := os.ReadFile(filepath.Join(folder, entries[0].Name())); err != nil || !bytes.Equal(data, pastedPicture) { + t.Fatalf("saved %q, %v", data, err) + } +} + +// No picture leaves the paste as it was; a picture too large, or a clipboard that cannot be +// read, takes the paste and says why. +func TestPictureThatCannotBePastedSaysWhy(t *testing.T) { + tests := []struct { + name string + err error + taken bool + message string + }{ + {"no picture", app.ErrNoImage, false, ""}, + {"unsupported", app.ErrUnsupported, false, ""}, + {"too large", app.ErrTooLarge, true, "The clipboard image is too large to paste."}, + {"unreadable", errors.New("pasteboard busy"), true, "Could not save the clipboard image: pasteboard busy"}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + h, term, folder := pasteTerminal(t, func() ([]byte, error) { return nil, test.err }) + if got := h.app.pasteTerminalImage(h.app.project, term); got != test.taken { + t.Fatalf("taken = %v, want %v", got, test.taken) + } + var errorsShown []string + for _, entry := range h.app.notifications.list { + if entry.kind == ui.ToastError { + errorsShown = append(errorsShown, entry.text) + } + } + if test.message == "" && len(errorsShown) != 0 || test.message != "" && (len(errorsShown) != 1 || errorsShown[0] != test.message) { + t.Fatalf("errors shown %q, want %q", errorsShown, test.message) + } + if term.pastingImage { + t.Fatal("a paste with no picture waits for one") + } + if entries, _ := os.ReadDir(folder); len(entries) != 0 { + t.Fatalf("a paste with no picture saved %v", entries) + } + }) + } +} + +// A terminal closed while its picture is saved gets nothing typed and no message. +func TestPictureForAClosedTerminalIsDropped(t *testing.T) { + h, term, _ := pasteTerminal(t, func() ([]byte, error) { return pastedPicture, nil }) + p := h.app.project + h.app.closeTerminal(p, term.id) + h.app.finishTerminalImage(p, term, "/tmp/paste-1.png", "", errors.New("late")) + if term.pastingImage { + t.Fatal("the flag stayed on") + } + for _, entry := range h.app.notifications.list { + if entry.kind == ui.ToastError { + t.Fatalf("a closed terminal's picture reported %q", entry.text) + } + } +} diff --git a/desktop/internal/workbench/terminals.go b/desktop/internal/workbench/terminals.go index c493a4b037..756b06325e 100644 --- a/desktop/internal/workbench/terminals.go +++ b/desktop/internal/workbench/terminals.go @@ -58,6 +58,9 @@ type terminal struct { // scripts are the command scripts written for commands too long for the shell's line; they are // removed when the terminal closes (terminal_commands.go). scripts []string + // pastingImage is set while a picture pasted into the terminal is being saved + // (terminal_paste_image.go). + pastingImage bool // input and draw are the Control's handlers and painter, made once with the terminal; // hit is the identity the paint declared it with. input ui.Handlers @@ -406,6 +409,7 @@ func (a *App) newTerminalWith(p *project, options terminalOptions) *terminal { OpenLink: a.openTerminalLink, } t := &terminal{id: id, number: set.freeNumber(), shell: shell, title: options.title, plugin: options.plugin} + config.PasteImage = func() bool { return a.pasteTerminalImage(p, t) } if options.plugin != nil { config.Exited = func(status *int) { a.pluginTerminalExited(p, t, status) } } diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index d620541d01..1cada9c00a 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -10857,6 +10857,8 @@ "desktop.terminal.findClose": "Close Find", "desktop.terminal.findCount": "{current} of {total}", "desktop.terminal.openLinkFailed": "Could not open the link: {reason}", + "desktop.terminal.pasteImageFailed": "Could not save the clipboard image: {reason}", + "desktop.terminal.pasteImageTooLarge": "The clipboard image is too large to paste.", "desktop.command.groupApp": "Application", "desktop.command.groupView": "View", "desktop.command.groupProject": "Project", @@ -10930,6 +10932,16 @@ "desktop.keymap.conflict": "{keys} is already used by “{action}”.", "desktop.keymap.unbindable": "A letter or symbol needs Command, Control or Option so typing never runs an action.", "desktop.keymap.help": "Click + and press the new keys. Escape cancels recording. Changes apply at once.", + "desktop.settings.terminal.cursor": "Cursor", + "desktop.settings.terminal.cursorHelp": "The shape the cursor takes until a program asks for its own, and how thick the bar and underline draw. Open terminals change at once.", + "desktop.settings.terminal.cursorShape": "Shape", + "desktop.settings.terminal.cursorShapeBlock": "Block", + "desktop.settings.terminal.cursorShapeBar": "Bar", + "desktop.settings.terminal.cursorShapeUnderline": "Underline", + "desktop.settings.terminal.cursorThickness": "Thickness", + "desktop.settings.terminal.cursorThin": "Thin", + "desktop.settings.terminal.cursorNormal": "Normal", + "desktop.settings.terminal.cursorThick": "Thick", "desktop.settings.terminal.scrollback": "Scrollback", "desktop.settings.terminal.scrollbackHelp": "How many lines of history a new terminal keeps above its screen (100–50,000). Open terminals keep their current limit.", "desktop.settings.terminal.scrollbackLines": "Lines kept", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 0d94f55d06..e0b5065c8f 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -10857,6 +10857,8 @@ "desktop.terminal.findClose": "关闭查找", "desktop.terminal.findCount": "第 {current} 个,共 {total} 个", "desktop.terminal.openLinkFailed": "无法打开链接:{reason}", + "desktop.terminal.pasteImageFailed": "无法保存剪贴板里的图片:{reason}", + "desktop.terminal.pasteImageTooLarge": "剪贴板里的图片太大,无法粘贴。", "desktop.command.groupApp": "应用", "desktop.command.groupView": "视图", "desktop.command.groupProject": "项目", @@ -10930,6 +10932,16 @@ "desktop.keymap.conflict": "{keys} 已被“{action}”使用。", "desktop.keymap.unbindable": "字母或符号需要配合 Command、Control 或 Option,避免普通输入触发操作。", "desktop.keymap.help": "点击 + 后按下新的按键,Esc 取消录制。修改立即生效。", + "desktop.settings.terminal.cursor": "光标", + "desktop.settings.terminal.cursorHelp": "程序没有指定光标形状时终端使用的形状,以及竖线和下划线光标的粗细。已打开的终端立即生效。", + "desktop.settings.terminal.cursorShape": "形状", + "desktop.settings.terminal.cursorShapeBlock": "方块", + "desktop.settings.terminal.cursorShapeBar": "竖线", + "desktop.settings.terminal.cursorShapeUnderline": "下划线", + "desktop.settings.terminal.cursorThickness": "粗细", + "desktop.settings.terminal.cursorThin": "细", + "desktop.settings.terminal.cursorNormal": "标准", + "desktop.settings.terminal.cursorThick": "粗", "desktop.settings.terminal.scrollback": "回滚行数", "desktop.settings.terminal.scrollbackHelp": "新建终端在屏幕上方保留的历史行数(100–50000)。已打开的终端保持原有上限。", "desktop.settings.terminal.scrollbackLines": "保留行数", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 652a8659ab..e3b8838d3d 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -16077,6 +16077,76 @@ "desktop" ] }, + { + "id": "desktop.settings.terminal.cursor", + "description": "Terminal settings page, cursor: the card title", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorHelp", + "description": "Terminal settings page, cursor: what the card sets", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorShape", + "description": "Terminal settings page, cursor: the label of the shape choice", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorShapeBlock", + "description": "Terminal settings page, cursor: the shape that fills the cell", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorShapeBar", + "description": "Terminal settings page, cursor: the thin vertical shape before the cell", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorShapeUnderline", + "description": "Terminal settings page, cursor: the shape under the cell", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorThickness", + "description": "Terminal settings page, cursor: the label of the thickness choice of the bar and underline", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorThin", + "description": "Terminal settings page, cursor: the thinnest bar and underline", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorNormal", + "description": "Terminal settings page, cursor: the default bar and underline thickness", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.settings.terminal.cursorThick", + "description": "Terminal settings page, cursor: the thickest bar and underline", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.settings.terminal.scrollback", "description": "Terminal settings page, scrollback", @@ -17519,6 +17589,23 @@ "reason": "string" } }, + { + "id": "desktop.terminal.pasteImageFailed", + "description": "Warning when a picture pasted into the terminal could not be saved as a file for the program to read", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.terminal.pasteImageTooLarge", + "description": "Warning when the picture on the clipboard is too large to paste into the terminal", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.terminal.restartHint", "description": "Desktop terminal: RestartHint", diff --git a/shared/platform-feature-matrix/features/terminal-interaction.json b/shared/platform-feature-matrix/features/terminal-interaction.json index 4eb6810060..7de27d87b4 100644 --- a/shared/platform-feature-matrix/features/terminal-interaction.json +++ b/shared/platform-feature-matrix/features/terminal-interaction.json @@ -2,7 +2,7 @@ "id": "terminal-interaction", "area": "工作台", "group": "终端", - "capability": "复制粘贴、搜索、调整大小、终端 Control 输入与切换快捷键及 macOS 终端 Nerd Font 优先选择", + "capability": "复制粘贴(含剪贴板图片粘贴)、搜索(选中文字预填)、块选择、调整大小、光标形状与粗细设置、终端 Control 输入与切换快捷键及 macOS 终端 Nerd Font 优先选择", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -24,7 +24,20 @@ "desktop/internal/termview/paint.go", "desktop/internal/termview/paint_test.go", "desktop/internal/termview/menu.go", - "desktop/internal/termview/menu_test.go" + "desktop/internal/termview/menu_test.go", + "desktop/internal/term/selection.go", + "desktop/internal/term/selection_test.go", + "desktop/internal/termview/block_selection_test.go", + "desktop/internal/workbench/terminal_find_test.go", + "desktop/internal/termview/paste_image_test.go", + "desktop/internal/workbench/terminal_paste_image.go", + "desktop/internal/workbench/terminal_paste_image_test.go", + "desktop/internal/term/cursor_style_test.go", + "desktop/internal/termview/cursor.go", + "desktop/internal/termview/cursor_test.go", + "desktop/internal/settingswindow/terminal_cursor_view.go", + "desktop/internal/settingswindow/terminal_cursor_view_test.go", + "desktop/internal/workbench/terminal_cursor_test.go" ] }, "windows": { @@ -49,11 +62,24 @@ "desktop/internal/termview/menu_test.go", "desktop/internal/workbench/terminal_menu.go", "desktop/internal/localshell/backend_windows.go", - "desktop/internal/localshell/shell_windows_test.go" + "desktop/internal/localshell/shell_windows_test.go", + "desktop/internal/term/selection.go", + "desktop/internal/term/selection_test.go", + "desktop/internal/termview/block_selection_test.go", + "desktop/internal/workbench/terminal_find_test.go", + "desktop/internal/termview/paste_image_test.go", + "desktop/internal/workbench/terminal_paste_image.go", + "desktop/internal/workbench/terminal_paste_image_test.go", + "desktop/internal/term/cursor_style_test.go", + "desktop/internal/termview/cursor.go", + "desktop/internal/termview/cursor_test.go", + "desktop/internal/settingswindow/terminal_cursor_view.go", + "desktop/internal/settingswindow/terminal_cursor_view_test.go", + "desktop/internal/workbench/terminal_cursor_test.go" ] }, "owner": "Terminal", - "verification": "验证复制粘贴、终端搜索、调整面板大小和高频输入不丢失。 macOS 安装原有支持列表中的 Nerd Font Mono,使用 Starship pastel-powerline 核对圆弧、Git/Bun 图标和拼接效果;注册打包 UI 字体后终端选择与 12.5pt 字号不变,未安装 Nerd Font 时回退到 Menlo 或系统等宽字体。 安装包必须包含完整 JetBrains Mono Nerd Font Mono 四个字型及许可;在未安装 Nerd Font 的机器上仍能直接显示完整提示符,粗斜体符号与文字使用相同字体度量,发行 bundle 字节不变。 Windows 终端点击识别出的 localhost、127.0.0.1 和 HTTPS 网页链接时直接打开系统默认浏览器,不显示外部链接确认;文件路径继续打开 IDE 文件,浏览器打开失败记录错误。真实 Windows 产品交互验收 pending。 macOS 保留宿主:在明暗主题切换无背景图→有图→无图,真实终端标题栏和正文随之透明/恢复,宿主及输入控件身份保持。隐藏终端后聚焦编辑器,再从活动栏重开已有会话,first responder 回到同一终端输入控件;连续调整面板尺寸和环境值不抢焦点,重开后立即隐藏会取消待交付的激活请求。运行 TerminalPlacementFeatureModelTests.retainedTerminalRestoresFocusAndWallpaperWithoutRecreatingItsSurface,并通过实际应用截图及交互验收。 隐藏保留的工具终端后,从工具会话 B 切到编辑器会话 C,确认工具会话回退到 A 并重新挂载时不请求焦点、窗口 first responder 仍为 C;同步出现任务和延迟原生回调都遵守隐藏祖先检查。重开工具窗口后才显式激活 A,缩放不抢焦点。;macOS 保留宿主圆角需在明暗主题、侧栏顶部与移动后、项目辉光改变、渐变开关及背景图切换时,与原工作台树四角像素一致(WorkbenchSurfaceBackgroundTests.retainedPaneCornersMatchWorkbenchGradient)。 终端持有键盘焦点时,除用户配置为切换终端的快捷键外,纯 Control 组合键(Ctrl-D、Ctrl-R、Ctrl-W)交回终端,不被其他应用命令截获;切换终端的绑定可从终端内关闭面板,其他修饰键组合仍走应用键位。TerminalShortcutInputPolicyTests 覆盖真实 AppKit 监听器及焦点策略;隔离的 macOS Release 包验证导入的 Control 加反引号可在终端内关闭,Control-D 仍可结束测试 shell,流程前后包内文件哈希一致。 Windows 聚焦终端或终端搜索框后按 Ctrl+Shift+F,须打开项目搜索而不弹出终端内搜索;Ctrl+F 仍搜索当前终端输出,Ctrl+Alt+F/AltGr 输入及已被其他命令处理的按键不能误开终端搜索。使用 terminal-keyboard.test.ts 验证快捷键边界,WebView2 实机验收保持 pending。 macOS #1542:显示保留的 Git Log/终端时,横纵分隔条中央及两侧偏移 4pt 仍经窗口事件完成拖动且只提交一次,宿主身份不变;根命中查询深度始终为 1,面板内部连续 100 次查询不产生额外根查询,鼠标移动不回查祖先 SwiftUI。验证禁用、收起(含嵌套分隔条)、恢复、卸载、跨窗口与登记表隔离、实时移动/裁剪、隐藏/透明和弱引用释放;保留宿主内部仍正常命中,外层边缘优先。Diff 两端收起后在普通与保留侧栏下均能经窗口拖回,不触发外层拖动。运行 GitLogReferenceResizeTests、SplitHandleHitTestTests 和 DiffScrollSynchronizationTests;旧实现先出现嵌套命中断言失败,新实现通过。较新 macOS 原生组件回归不替代 macOS 13 Intel 原报告崩溃验收,目标环境验证保持 pending。 WS-16:终端文件链接的 path:line:column、file URI 解码、~ 展开和相对路径映射由 Core terminal.parseLinkTarget 统一解析,两端只负责命中区域、文件是否存在和打开动作。Windows 不再按扩展名白名单筛选,而是对含路径分隔符、~、file:// 或 :行号 的候选逐个检查文件是否存在,所以无扩展名文件(如 build/output)也能点开,不存在的路径不再被画成链接;远程/WSL 路径没有单文件 stat 接口,改为列出父目录(与文件树同一个 ssh_read_directory / wsl_read_directory 适配器)判断文件是否存在,所以不带行号的 src/foo.ts 仍可点开,本地、WSL、远程三种根行为一致,没有扩展名启发式例外。同一行同一工作目录的结果缓存 2 秒(最多 128 条,进行中的请求共享),避免悬停时反复检查。macOS 带 :行号 的相对文件名(如 App.swift:12)不再被误当成 URL scheme。真实终端点击验收 pending。 输出到达时选区留在原来的文字上:滚动的输出不清除选区,也不打断正在进行的拖选;回滚丢弃了选区开头时,选区截到保留的最早一行,整段被丢弃时清除;进出备用屏、终端重置(RIS)和「清除」之后,新输出不会让旧选区指向别的文字(TestOutputKeepsTheSelectionOnItsText、TestOutputTrimsASelectionTheScrollbackDropped、TestBufferChangesClearASelection、TestASelectionMadeAfterClearSurvivesOutput)。每行按稳定的行标识绘制,滚动时同一行的文字纹理被复用,不同终端视图的标识互不冲突(TestRowsKeepTheirTextIdentityAcrossScrolling、TestViewsPaintUnderOwnersOfTheirOwn)。右键「清除」时,若 PowerShell 停在提示符,向它发送换页符(Ctrl+L),PSReadLine 从顶行重绘输入行,不会在清除后的空行下方继续书写;PowerShell 正在运行程序、cmd/POSIX/未知 Shell、插件终端和备用屏都不发送(TestClearSendsAFormFeedToPowerShellAtItsPrompt、TestClearSendsNoFormFeedWhereNoLineEditorReadsIt)。Windows 上 Lithe 继承了关闭 Ctrl+C 的进程状态(例如以 CREATE_NEW_PROCESS_GROUP 启动)时,启动 Shell 前重新打开 Ctrl+C,Ctrl+C 能中断伪控制台中运行的程序(TestConPTYCtrlCInterruptsAProgramInAnInheritedCtrlCDisabledGroup)。Windows 运行时测试、真实 PowerShell 清除和 Ctrl+C 验收 pending。", + "verification": "验证复制粘贴、终端搜索、调整面板大小和高频输入不丢失。 macOS 安装原有支持列表中的 Nerd Font Mono,使用 Starship pastel-powerline 核对圆弧、Git/Bun 图标和拼接效果;注册打包 UI 字体后终端选择与 12.5pt 字号不变,未安装 Nerd Font 时回退到 Menlo 或系统等宽字体。 安装包必须包含完整 JetBrains Mono Nerd Font Mono 四个字型及许可;在未安装 Nerd Font 的机器上仍能直接显示完整提示符,粗斜体符号与文字使用相同字体度量,发行 bundle 字节不变。 Windows 终端点击识别出的 localhost、127.0.0.1 和 HTTPS 网页链接时直接打开系统默认浏览器,不显示外部链接确认;文件路径继续打开 IDE 文件,浏览器打开失败记录错误。真实 Windows 产品交互验收 pending。 macOS 保留宿主:在明暗主题切换无背景图→有图→无图,真实终端标题栏和正文随之透明/恢复,宿主及输入控件身份保持。隐藏终端后聚焦编辑器,再从活动栏重开已有会话,first responder 回到同一终端输入控件;连续调整面板尺寸和环境值不抢焦点,重开后立即隐藏会取消待交付的激活请求。运行 TerminalPlacementFeatureModelTests.retainedTerminalRestoresFocusAndWallpaperWithoutRecreatingItsSurface,并通过实际应用截图及交互验收。 隐藏保留的工具终端后,从工具会话 B 切到编辑器会话 C,确认工具会话回退到 A 并重新挂载时不请求焦点、窗口 first responder 仍为 C;同步出现任务和延迟原生回调都遵守隐藏祖先检查。重开工具窗口后才显式激活 A,缩放不抢焦点。;macOS 保留宿主圆角需在明暗主题、侧栏顶部与移动后、项目辉光改变、渐变开关及背景图切换时,与原工作台树四角像素一致(WorkbenchSurfaceBackgroundTests.retainedPaneCornersMatchWorkbenchGradient)。 终端持有键盘焦点时,除用户配置为切换终端的快捷键外,纯 Control 组合键(Ctrl-D、Ctrl-R、Ctrl-W)交回终端,不被其他应用命令截获;切换终端的绑定可从终端内关闭面板,其他修饰键组合仍走应用键位。TerminalShortcutInputPolicyTests 覆盖真实 AppKit 监听器及焦点策略;隔离的 macOS Release 包验证导入的 Control 加反引号可在终端内关闭,Control-D 仍可结束测试 shell,流程前后包内文件哈希一致。 Windows 聚焦终端或终端搜索框后按 Ctrl+Shift+F,须打开项目搜索而不弹出终端内搜索;Ctrl+F 仍搜索当前终端输出,Ctrl+Alt+F/AltGr 输入及已被其他命令处理的按键不能误开终端搜索。使用 terminal-keyboard.test.ts 验证快捷键边界,WebView2 实机验收保持 pending。 macOS #1542:显示保留的 Git Log/终端时,横纵分隔条中央及两侧偏移 4pt 仍经窗口事件完成拖动且只提交一次,宿主身份不变;根命中查询深度始终为 1,面板内部连续 100 次查询不产生额外根查询,鼠标移动不回查祖先 SwiftUI。验证禁用、收起(含嵌套分隔条)、恢复、卸载、跨窗口与登记表隔离、实时移动/裁剪、隐藏/透明和弱引用释放;保留宿主内部仍正常命中,外层边缘优先。Diff 两端收起后在普通与保留侧栏下均能经窗口拖回,不触发外层拖动。运行 GitLogReferenceResizeTests、SplitHandleHitTestTests 和 DiffScrollSynchronizationTests;旧实现先出现嵌套命中断言失败,新实现通过。较新 macOS 原生组件回归不替代 macOS 13 Intel 原报告崩溃验收,目标环境验证保持 pending。 WS-16:终端文件链接的 path:line:column、file URI 解码、~ 展开和相对路径映射由 Core terminal.parseLinkTarget 统一解析,两端只负责命中区域、文件是否存在和打开动作。Windows 不再按扩展名白名单筛选,而是对含路径分隔符、~、file:// 或 :行号 的候选逐个检查文件是否存在,所以无扩展名文件(如 build/output)也能点开,不存在的路径不再被画成链接;远程/WSL 路径没有单文件 stat 接口,改为列出父目录(与文件树同一个 ssh_read_directory / wsl_read_directory 适配器)判断文件是否存在,所以不带行号的 src/foo.ts 仍可点开,本地、WSL、远程三种根行为一致,没有扩展名启发式例外。同一行同一工作目录的结果缓存 2 秒(最多 128 条,进行中的请求共享),避免悬停时反复检查。macOS 带 :行号 的相对文件名(如 App.swift:12)不再被误当成 URL scheme。真实终端点击验收 pending。 输出到达时选区留在原来的文字上:滚动的输出不清除选区,也不打断正在进行的拖选;回滚丢弃了选区开头时,选区截到保留的最早一行,整段被丢弃时清除;进出备用屏、终端重置(RIS)和「清除」之后,新输出不会让旧选区指向别的文字(TestOutputKeepsTheSelectionOnItsText、TestOutputTrimsASelectionTheScrollbackDropped、TestBufferChangesClearASelection、TestASelectionMadeAfterClearSurvivesOutput)。每行按稳定的行标识绘制,滚动时同一行的文字纹理被复用,不同终端视图的标识互不冲突(TestRowsKeepTheirTextIdentityAcrossScrolling、TestViewsPaintUnderOwnersOfTheirOwn)。右键「清除」时,若 PowerShell 停在提示符,向它发送换页符(Ctrl+L),PSReadLine 从顶行重绘输入行,不会在清除后的空行下方继续书写;PowerShell 正在运行程序、cmd/POSIX/未知 Shell、插件终端和备用屏都不发送(TestClearSendsAFormFeedToPowerShellAtItsPrompt、TestClearSendsNoFormFeedWhereNoLineEditorReadsIt)。Windows 上 Lithe 继承了关闭 Ctrl+C 的进程状态(例如以 CREATE_NEW_PROCESS_GROUP 启动)时,启动 Shell 前重新打开 Ctrl+C,Ctrl+C 能中断伪控制台中运行的程序(TestConPTYCtrlCInterruptsAProgramInAnInheritedCtrlCDisabledGroup)。Windows 运行时测试、真实 PowerShell 清除和 Ctrl+C 验收 pending。 按住 Alt(Linux 为 Ctrl+Alt)拖动选出列块,复制时每行一段、行尾空白去掉;不拖动的 Alt 点击仍是普通点击,程序接管鼠标时块选择让给程序(TestBlockDragSelectsTheRectangleAndCopiesIt、TestBlockPressWithoutADragStaysAClick、TestBlockSelectionYieldsToProgramsUsingTheMouse)。打开终端搜索时,单行选区作为查询预填并整体选中,已打开时保留已输入内容(TestTerminalFindOpensWithTheSelectionSelected、TestReopeningTerminalFindSelectsItsQuery、TestTerminalFindQueryFromASelection)。剪贴板只有图片时粘贴把图片存成用户缓存目录 Lithe/terminal-paste 下仅本人可读的 PNG,并把转义后的路径输入到提示符(WSL 终端为 /mnt 路径),一周前的图片在下次粘贴时清理;图片过大或读不出时提示原因,没有图片时仍发送空粘贴(TestPasteWithoutTextAsksForAPictureFirst、TestPastingAPictureTypesItsSavedPath、TestPictureThatCannotBePastedSaysWhy、TestSavePastedImageWritesAPrivateFileAndTidies、TestQuotePastedPath)。设置 → 终端的「光标」卡片选择方块/竖线/下划线与细/标准/粗,已打开的终端下一帧生效;程序用 DECSCUSR 指定的形状优先,DECSCUSR 0 和终端重置恢复用户选择,粗细也作用于程序指定的竖线和下划线(TestDefaultCursorShapeYieldsToProgramsAndComesBack、TestChosenCursorShapesAndThicknessesPaint、TestTerminalCursorChoicesApplyWhenChosen、TestChosenTerminalCursorReachesOpenTerminals)。Windows 真实剪贴板图片、块选择与光标设置验收 pending。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -95,5 +121,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:复制粘贴与 Control 输入在 termview/input.go;终端内查找(termview/find.go、workbench/terminal_find.go)支持上下跳转与高亮;点击 http/https 链接用系统浏览器打开(openTerminalLink,其他协议不打开);窗口大小变化时按单元格重新计算行列;终端切换快捷键走工作台快捷键。macOS 用户未选终端字体时,按 fonts.go 的 terminalNerdFonts 顺序选第一个可用的 Nerd Font:已安装的 MesloLGS Nerd Font Mono 优先,其次是发行包编译进可执行文件的 JetBrainsMono Nerd Font Mono(internal/bundledfont,lithe_bundled_fonts 构建标签),再其次其他已装 Nerd Font;都没有时用随包 JetBrains Mono。开发构建不带字体,回退到系统等宽字体。 #1907:macOS 无头终端菜单测试先消费 shell 输出的待绘制帧,再点击真实终端侧栏按钮,覆盖全选、复制和关闭;旧的直接布局调用连续 5 次失败,修复后连续 20 次通过,并通过相邻菜单用例的竞态检查。该用例使用 /bin/sh,在 Windows 跳过;原生窗口与 Windows 验收仍为 pending。 2026-11-16:同步 Motty 3a2b91dc(输出保留选区)、c3cc6f6c(行纹理复用)、546e40ae(Windows Ctrl+C)、dbd2a6f2(清除后向 PowerShell 发送换页符),见 termview/NOTICE。" + "notes": "Viva:复制粘贴与 Control 输入在 termview/input.go;终端内查找(termview/find.go、workbench/terminal_find.go)支持上下跳转与高亮;点击 http/https 链接用系统浏览器打开(openTerminalLink,其他协议不打开);窗口大小变化时按单元格重新计算行列;终端切换快捷键走工作台快捷键。macOS 用户未选终端字体时,按 fonts.go 的 terminalNerdFonts 顺序选第一个可用的 Nerd Font:已安装的 MesloLGS Nerd Font Mono 优先,其次是发行包编译进可执行文件的 JetBrainsMono Nerd Font Mono(internal/bundledfont,lithe_bundled_fonts 构建标签),再其次其他已装 Nerd Font;都没有时用随包 JetBrains Mono。开发构建不带字体,回退到系统等宽字体。 #1907:macOS 无头终端菜单测试先消费 shell 输出的待绘制帧,再点击真实终端侧栏按钮,覆盖全选、复制和关闭;旧的直接布局调用连续 5 次失败,修复后连续 20 次通过,并通过相邻菜单用例的竞态检查。该用例使用 /bin/sh,在 Windows 跳过;原生窗口与 Windows 验收仍为 pending。 2026-11-16:同步 Motty 3a2b91dc(输出保留选区)、c3cc6f6c(行纹理复用)、546e40ae(Windows Ctrl+C)、dbd2a6f2(清除后向 PowerShell 发送换页符),见 termview/NOTICE。 2026-11-16:同步 Motty d0759bb3(块选择)、4116260e(搜索预填选区),并补上移植时省略的 fe2570d9/ed6db385(剪贴板图片粘贴,仅本地终端,无开关)与 3f7979e4/8a7476b6(光标形状与粗细),见 termview/NOTICE。Motty fbd26b86 的关闭确认在 Lithe 已由 workbench/process_exit.go 的 BusyProbe 提供,未重复移植。" }