Skip to content

Commit

Permalink
Erase full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
jspc committed Oct 28, 2022
1 parent 9ad5a43 commit bbb0138
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
8 changes: 8 additions & 0 deletions drivers/cga/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ type Backend interface {
WriteByte(ch byte)
}

type EraseMethod uint8

const (
EraseMethod_Unknown EraseMethod = iota
EraseMethod_Line
EraseMethod_All
)

const (
CRTPORT = 0x3d4
bs = '\b'
Expand Down
28 changes: 22 additions & 6 deletions drivers/cga/cga.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ func setCursorColumn(n int) {
getbackend().SetPos(pos)
}

func eraseLine(method int) {
func eraseLine(method EraseMethod) {
backend := getbackend()
pos := backend.GetPos()
switch method {
case 0:
case EraseMethod_Line:
end := (pos/80 + 1) * 80
for i := pos; i < end; i++ {
backend.WritePos(i, ' ')
}

case EraseMethod_All:
for i := 0; i < 25*80; i++ {
backend.WritePos(i, ' ')
}

default:
panic("unsupported erase line method")
}
Expand All @@ -38,7 +44,7 @@ func eraseLine(method int) {
func writeCSI(action byte, params []string) {
// fmt.Fprintf(os.Stderr, "action:%c, params:%v\n", action, params)
switch action {
// set cursor
// set cursor column
case 'G':
if len(params) == 0 {
setCursorColumn(1)
Expand All @@ -49,11 +55,21 @@ func writeCSI(action byte, params []string) {
// erase line
case 'K':
if len(params) == 0 {
eraseLine(0)
eraseLine(EraseMethod_Line)
} else {
n, _ := strconv.Atoi(params[0])
eraseLine(n)
//n, _ := strconv.Atoi(params[0])
eraseLine(EraseMethod_Unknown)
}

// Erase screen - note; this action *looks* like it ought
// to be just <ESC>[J - which is 'erase from current line to
// bottom of screen', but I actually want it to mimic <ESC>[2J
// which is 'erase screen and return to top'
//
// Hopefully nobody ever uses my fork if they expect that functionality
case 'J':
eraseLine(EraseMethod_All)

default:
panic("unsupported CSI action")
}
Expand Down

0 comments on commit bbb0138

Please sign in to comment.