Debian Codegraph @

vt/cc.go

raw
1 package vt
2
3 import (
4 uv "github.com/charmbracelet/ultraviolet"
5 "github.com/charmbracelet/x/ansi"
6 )
7
8 // handleControl handles a control character.
9 func (e *Emulator) handleControl(r byte) {
10 e.flushGrapheme() // Flush any pending grapheme before handling control codes.
11 if !e.handleCc(r) {
12 e.logf("unhandled sequence: ControlCode %q", r)
13 }
14 }
15
16 // linefeed is the same as [index], except that it respects [ansi.LNM] mode.
17 func (e *Emulator) linefeed() {
18 e.index()
19 if e.isModeSet(ansi.LineFeedNewLineMode) {
20 e.carriageReturn()
21 }
22 }
23
24 // index moves the cursor down one line, scrolling up if necessary. This
25 // always resets the phantom state i.e. pending wrap state.
26 func (e *Emulator) index() {
27 x, y := e.scr.CursorPosition()
28 scroll := e.scr.ScrollRegion()
29 // XXX: Handle scrollback whenever we add it.
30 if y == scroll.Max.Y-1 && x >= scroll.Min.X && x < scroll.Max.X {
31 e.scr.ScrollUp(1)
32 } else if y < scroll.Max.Y-1 || !uv.Pos(x, y).In(scroll) {
33 e.scr.moveCursor(0, 1)
34 }
35 e.atPhantom = false
36 }
37
38 // horizontalTabSet sets a horizontal tab stop at the current cursor position.
39 func (e *Emulator) horizontalTabSet() {
40 x, _ := e.scr.CursorPosition()
41 e.tabstops.Set(x)
42 }
43
44 // reverseIndex moves the cursor up one line, or scrolling down. This does not
45 // reset the phantom state i.e. pending wrap state.
46 func (e *Emulator) reverseIndex() {
47 x, y := e.scr.CursorPosition()
48 scroll := e.scr.ScrollRegion()
49 if y == scroll.Min.Y && x >= scroll.Min.X && x < scroll.Max.X {
50 e.scr.ScrollDown(1)
51 } else {
52 e.scr.moveCursor(0, -1)
53 }
54 }
55
56 // backspace moves the cursor back one cell, if possible.
57 func (e *Emulator) backspace() {
58 // This acts like [ansi.CUB]
59 e.moveCursor(-1, 0)
60 }