Files
sshtermy/third_party/vt/csi_cursor.go
T
db9979andClaude 485db6d240 Code-Review 1–12: Emulator-Hänger, zweites sshTermy, Update-Selbsttest mit Rückfall, Tests (#132)
1  Terminal-Emulator: Zählparameter begrenzt (REP höchstens ein Bildschirm,
   ECH/CHT/CBT eine Zeile). "CSI 2147483647 b" hielt den Emulator minutenlang
   fest; das war der zeitweise hängende Fuzz-Test.
2  Zwei sshTermy auf demselben Tresor: Store.Fresh lädt neu, wenn das andere
   Programm gespeichert hat (vor jeder Änderung und im Sekundentakt), statt
   dessen Stand zu überschreiben. Auch ein geändertes Master-Passwort bleibt.
3  Schreibweg zum Server entkoppelt (termemu/hostqueue.go): ein hängendes
   Schreiben friert die Oberfläche nicht mehr ein.
4  Tresor wird mit fsync und eigener temporärer Datei geschrieben.
5  Sync: payloadFormat 2; TestPayloadFields verlangt bei neuen Feldern eine
   höhere Zahl, damit ältere Versionen den Abgleich verweigern statt Felder
   zu verlieren.
6  Update: Selbsttest der neuen Programmdatei vor dem Tausch (-version muss
   die angekündigte Version nennen), alte Datei bleibt bis zur Bestätigung,
   nach zwei unbestätigten Starts automatischer Rückfall (update/guard.go).
   Release-Workflow prüft die gebaute Datei genauso.
7  Actions in allen Workflows auf Commit-SHA festgelegt.
8  Tests: update (Apply, Signatur, Rückfall), cmdset, vault, store, theme.
9  Fuzz-Tests mit Zeitlimit je Eingabe (internal/fuzzguard); Tests und Fuzz
   von third_party/ansi laufen in CI und make test.
10 Farbschemata als eigenes Paket internal/ui/theme.
11 Fehler beim Speichern werden zentral gemeldet (Store.OnSaveError).
12 shellWriter liest die Shell über atomic.Pointer (Wettlauf mit Reconnect).


Claude-Session: https://claude.ai/code/session_018i4GUiL1D3QV4KrFiJxU8R

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-11 12:08:44 +01:00

116 lines
3.3 KiB
Go

package vt
import (
uv "github.com/charmbracelet/ultraviolet"
"github.com/charmbracelet/x/ansi"
)
// nextTab moves the cursor to the next tab stop n times. This respects the
// horizontal scrolling region. This performs the same function as [ansi.CHT].
func (e *Emulator) nextTab(n int) {
x, y := e.scr.CursorPosition()
scroll := e.scr.ScrollRegion()
n = min(n, e.Width()) // sshTermy: mehr Tabstopps als Spalten gibt es nicht
for range n {
ts := e.tabstops.Next(x)
if ts < x {
break
}
x = ts
}
if x >= scroll.Max.X {
x = min(scroll.Max.X-1, e.Width()-1)
}
// NOTE: We use t.scr.setCursor here because we don't want to reset the
// phantom state.
e.scr.setCursor(x, y, false)
}
// prevTab moves the cursor to the previous tab stop n times. This respects the
// horizontal scrolling region when origin mode is set. If the cursor would
// move past the leftmost valid column, the cursor remains at the leftmost
// valid column and the operation completes.
func (e *Emulator) prevTab(n int) {
x, _ := e.scr.CursorPosition()
leftmargin := 0
scroll := e.scr.ScrollRegion()
if e.isModeSet(ansi.DECOM) {
leftmargin = scroll.Min.X
}
n = min(n, e.Width()) // sshTermy: mehr Tabstopps als Spalten gibt es nicht
for range n {
ts := e.tabstops.Prev(x)
if ts > x {
break
}
x = ts
}
if x < leftmargin {
x = leftmargin
}
// NOTE: We use t.scr.setCursorX here because we don't want to reset the
// phantom state.
e.scr.setCursorX(x, false)
}
// moveCursor moves the cursor by the given x and y deltas. If the cursor
// is at phantom, the state will reset and the cursor is back in the screen.
func (e *Emulator) moveCursor(dx, dy int) {
e.scr.moveCursor(dx, dy)
e.atPhantom = false
}
// setCursor sets the cursor position. This resets the phantom state.
func (e *Emulator) setCursor(x, y int) {
e.scr.setCursor(x, y, false)
e.atPhantom = false
}
// setCursorPosition sets the cursor position. This respects [ansi.DECOM],
// Origin Mode. This performs the same function as [ansi.CUP].
func (e *Emulator) setCursorPosition(x, y int) {
mode, ok := e.modes[ansi.DECOM]
margins := ok && mode.IsSet()
e.scr.setCursor(x, y, margins)
e.atPhantom = false
}
// carriageReturn moves the cursor to the leftmost column. If [ansi.DECOM] is
// set, the cursor is set to the left margin. If not, and the cursor is on or
// to the right of the left margin, the cursor is set to the left margin.
// Otherwise, the cursor is set to the leftmost column of the screen.
// This performs the same function as [ansi.CR].
func (e *Emulator) carriageReturn() {
mode, ok := e.modes[ansi.DECOM]
margins := ok && mode.IsSet()
x, y := e.scr.CursorPosition()
if margins {
e.scr.setCursor(0, y, true)
} else if region := e.scr.ScrollRegion(); uv.Pos(x, y).In(region) {
e.scr.setCursor(region.Min.X, y, false)
} else {
e.scr.setCursor(0, y, false)
}
e.atPhantom = false
}
// repeatPreviousCharacter repeats the previous character n times. This is
// equivalent to typing the same character n times. This performs the same as
// [ansi.REP].
func (e *Emulator) repeatPreviousCharacter(n int) {
if e.lastChar == 0 {
return
}
// sshTermy: höchstens ein voller Bildschirm. Ohne Grenze hält
// "CSI 2147483647 b" den Emulator minutenlang fest (Fund des Fuzz-Tests).
n = min(n, e.Width()*e.Height())
for range n {
e.handlePrint(e.lastChar)
}
}