1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Use uint32 instead of uint16 for TTY coordinates

This commit is contained in:
Achilleas Anagnostopoulos 2017-07-08 08:47:22 +01:00
parent fd3ca91138
commit 4845f7a4ca
3 changed files with 35 additions and 35 deletions

View File

@ -42,11 +42,11 @@ type Device interface {
// CursorPosition returns the current cursor x,y coordinates. Both // CursorPosition returns the current cursor x,y coordinates. Both
// coordinates are 1-based (top-left corner has coordinates 1,1). // coordinates are 1-based (top-left corner has coordinates 1,1).
CursorPosition() (uint16, uint16) CursorPosition() (uint32, uint32)
// SetCursorPosition sets the current cursor position to (x,y). Both // SetCursorPosition sets the current cursor position to (x,y). Both
// coordinates are 1-based (top-left corner has coordinates 1,1). // coordinates are 1-based (top-left corner has coordinates 1,1).
// Implementations are expected to clip the cursor position to their // Implementations are expected to clip the cursor position to their
// viewport. // viewport.
SetCursorPosition(x, y uint16) SetCursorPosition(x, y uint32)
} }

View File

@ -17,14 +17,14 @@ type VT struct {
cons console.Device cons console.Device
// Terminal dimensions // Terminal dimensions
termWidth uint16 termWidth uint32
termHeight uint16 termHeight uint32
viewportWidth uint16 viewportWidth uint32
viewportHeight uint16 viewportHeight uint32
// The number of additional lines of output that are buffered by the // The number of additional lines of output that are buffered by the
// terminal to support scrolling up. // terminal to support scrolling up.
scrollback uint16 scrollback uint32
// The terminal contents. Each character occupies 3 bytes and uses the // The terminal contents. Each character occupies 3 bytes and uses the
// format: (ASCII char, fg, bg) // format: (ASCII char, fg, bg)
@ -34,9 +34,9 @@ type VT struct {
tabWidth uint8 tabWidth uint8
defaultFg, curFg uint8 defaultFg, curFg uint8
defaultBg, curBg uint8 defaultBg, curBg uint8
cursorX uint16 cursorX uint32
cursorY uint16 cursorY uint32
viewportY uint16 viewportY uint32
dataOffset uint dataOffset uint
state State state State
} }
@ -45,7 +45,7 @@ type VT struct {
// tab expansion whereas the scrollback parameter defines the line count that // tab expansion whereas the scrollback parameter defines the line count that
// gets buffered by the terminal to provide scrolling beyond the console // gets buffered by the terminal to provide scrolling beyond the console
// height. // height.
func NewVT(tabWidth uint8, scrollback uint16) *VT { func NewVT(tabWidth uint8, scrollback uint32) *VT {
return &VT{ return &VT{
tabWidth: tabWidth, tabWidth: tabWidth,
scrollback: scrollback, scrollback: scrollback,
@ -93,9 +93,9 @@ func (t *VT) SetState(newState State) {
// If the terminal became active, update the console with its contents // If the terminal became active, update the console with its contents
if t.state == StateActive && t.cons != nil { if t.state == StateActive && t.cons != nil {
for y := uint16(1); y <= t.viewportHeight; y++ { for y := uint32(1); y <= t.viewportHeight; y++ {
offset := (y - 1 + t.viewportY) * (t.viewportWidth * 3) offset := (y - 1 + t.viewportY) * (t.viewportWidth * 3)
for x := uint16(1); x <= t.viewportWidth; x, offset = x+1, offset+3 { for x := uint32(1); x <= t.viewportWidth; x, offset = x+1, offset+3 {
t.cons.Write(t.data[offset], t.data[offset+1], t.data[offset+2], x, y) t.cons.Write(t.data[offset], t.data[offset+1], t.data[offset+2], x, y)
} }
} }
@ -103,12 +103,12 @@ func (t *VT) SetState(newState State) {
} }
// CursorPosition returns the current cursor position. // CursorPosition returns the current cursor position.
func (t *VT) CursorPosition() (uint16, uint16) { func (t *VT) CursorPosition() (uint32, uint32) {
return t.cursorX, t.cursorY return t.cursorX, t.cursorY
} }
// SetCursorPosition sets the current cursor position to (x,y). // SetCursorPosition sets the current cursor position to (x,y).
func (t *VT) SetCursorPosition(x, y uint16) { func (t *VT) SetCursorPosition(x, y uint32) {
if t.cons == nil { if t.cons == nil {
return return
} }

View File

@ -11,8 +11,8 @@ import (
func TestVtPosition(t *testing.T) { func TestVtPosition(t *testing.T) {
specs := []struct { specs := []struct {
inX, inY uint16 inX, inY uint32
expX, expY uint16 expX, expY uint32
}{ }{
{20, 20, 20, 20}, {20, 20, 20, 20},
{100, 20, 80, 20}, {100, 20, 80, 20},
@ -21,7 +21,7 @@ func TestVtPosition(t *testing.T) {
{100, 100, 80, 25}, {100, 100, 80, 25},
} }
term := NewVT(4, 0) var term Device = NewVT(4, 0)
// SetCursorPosition without an attached console is a no-op // SetCursorPosition without an attached console is a no-op
term.SetCursorPosition(2, 2) term.SetCursorPosition(2, 2)
@ -70,7 +70,7 @@ func TestVtWrite(t *testing.T) {
} }
specs := []struct { specs := []struct {
x, y uint16 x, y uint32
expByte uint8 expByte uint8
}{ }{
{1, 1, '1'}, {1, 1, '1'},
@ -121,7 +121,7 @@ func TestVtWrite(t *testing.T) {
} }
specs := []struct { specs := []struct {
x, y uint16 x, y uint32
expByte uint8 expByte uint8
}{ }{
{1, 1, '1'}, {1, 1, '1'},
@ -161,13 +161,13 @@ func TestVtLineFeedHandling(t *testing.T) {
// line feed. Cursor position will be automatically clipped to // line feed. Cursor position will be automatically clipped to
// the viewport bounds // the viewport bounds
term.SetCursorPosition(1, term.viewportHeight+1) term.SetCursorPosition(1, term.viewportHeight+1)
for i := uint16(0); i < term.viewportWidth-1; i++ { for i := uint32(0); i < term.viewportWidth-1; i++ {
term.WriteByte(byte('0' + (i % 10))) term.WriteByte(byte('0' + (i % 10)))
} }
// Emulate viewportHeight line feeds. The last one should cause a scroll // Emulate viewportHeight line feeds. The last one should cause a scroll
term.SetCursorPosition(0, 0) // cursor is set to (1,1) term.SetCursorPosition(0, 0) // cursor is set to (1,1)
for i := uint16(0); i < term.viewportHeight; i++ { for i := uint32(0); i < term.viewportHeight; i++ {
term.lf(true) term.lf(true)
} }
@ -178,7 +178,7 @@ func TestVtLineFeedHandling(t *testing.T) {
// Set cursor one line above the last; this line should now // Set cursor one line above the last; this line should now
// contain the scrolled contents // contain the scrolled contents
term.SetCursorPosition(1, term.viewportHeight-1) term.SetCursorPosition(1, term.viewportHeight-1)
for col, offset := uint16(1), term.dataOffset; col <= term.viewportWidth; col, offset = col+1, offset+3 { for col, offset := uint32(1), term.dataOffset; col <= term.viewportWidth; col, offset = col+1, offset+3 {
expByte := byte('0' + ((col - 1) % 10)) expByte := byte('0' + ((col - 1) % 10))
if col == term.viewportWidth { if col == term.viewportWidth {
expByte = ' ' expByte = ' '
@ -191,7 +191,7 @@ func TestVtLineFeedHandling(t *testing.T) {
// Set cursor to the last line. This line should now be cleared // Set cursor to the last line. This line should now be cleared
term.SetCursorPosition(1, term.viewportHeight) term.SetCursorPosition(1, term.viewportHeight)
for col, offset := uint16(1), term.dataOffset; col <= term.viewportWidth; col, offset = col+1, offset+3 { for col, offset := uint32(1), term.dataOffset; col <= term.viewportWidth; col, offset = col+1, offset+3 {
expByte := uint8(' ') expByte := uint8(' ')
if term.data[offset] != expByte { if term.data[offset] != expByte {
t.Errorf("expected char at (%d, %d) to be %q; got %q", col, term.viewportHeight, expByte, term.data[offset]) t.Errorf("expected char at (%d, %d) to be %q; got %q", col, term.viewportHeight, expByte, term.data[offset])
@ -210,20 +210,20 @@ func TestVtLineFeedHandling(t *testing.T) {
// line feed. Cursor position will be automatically clipped to // line feed. Cursor position will be automatically clipped to
// the viewport bounds // the viewport bounds
term.SetCursorPosition(1, term.viewportHeight+1) term.SetCursorPosition(1, term.viewportHeight+1)
for i := uint16(0); i < term.viewportWidth-1; i++ { for i := uint32(0); i < term.viewportWidth-1; i++ {
term.WriteByte(byte('0' + (i % 10))) term.WriteByte(byte('0' + (i % 10)))
} }
// Fill first line including the last column // Fill first line including the last column
term.SetCursorPosition(1, 1) term.SetCursorPosition(1, 1)
for i := uint16(0); i < term.viewportWidth; i++ { for i := uint32(0); i < term.viewportWidth; i++ {
term.WriteByte(byte('0' + (i % 10))) term.WriteByte(byte('0' + (i % 10)))
} }
// Emulate viewportHeight line feeds. The last one should cause a scroll // Emulate viewportHeight line feeds. The last one should cause a scroll
// in the console but only a viewport adjustment in the terminal // in the console but only a viewport adjustment in the terminal
term.SetCursorPosition(0, 0) // cursor is set to (1,1) term.SetCursorPosition(0, 0) // cursor is set to (1,1)
for i := uint16(0); i < term.viewportHeight; i++ { for i := uint32(0); i < term.viewportHeight; i++ {
term.lf(true) term.lf(true)
} }
@ -231,7 +231,7 @@ func TestVtLineFeedHandling(t *testing.T) {
t.Fatalf("expected console to be scrolled up 1 time; got %d", cons.scrollUpCount) t.Fatalf("expected console to be scrolled up 1 time; got %d", cons.scrollUpCount)
} }
if expViewportY := uint16(1); term.viewportY != expViewportY { if expViewportY := uint32(1); term.viewportY != expViewportY {
t.Fatalf("expected terminal viewportY to be adjusted to %d; got %d", expViewportY, term.viewportY) t.Fatalf("expected terminal viewportY to be adjusted to %d; got %d", expViewportY, term.viewportY)
} }
@ -240,7 +240,7 @@ func TestVtLineFeedHandling(t *testing.T) {
term.SetCursorPosition(1, 1) term.SetCursorPosition(1, 1)
offset := term.dataOffset - uint(term.viewportWidth*3) offset := term.dataOffset - uint(term.viewportWidth*3)
for col := uint16(1); col <= term.viewportWidth; col, offset = col+1, offset+3 { for col := uint32(1); col <= term.viewportWidth; col, offset = col+1, offset+3 {
expByte := byte('0' + ((col - 1) % 10)) expByte := byte('0' + ((col - 1) % 10))
if term.data[offset] != expByte { if term.data[offset] != expByte {
@ -361,7 +361,7 @@ func TestVTProbe(t *testing.T) {
} }
type mockConsole struct { type mockConsole struct {
width, height uint16 width, height uint32
fg, bg uint8 fg, bg uint8
chars []uint8 chars []uint8
fgAttrs []uint8 fgAttrs []uint8
@ -371,7 +371,7 @@ type mockConsole struct {
scrollDownCount int scrollDownCount int
} }
func newMockConsole(w, h uint16) *mockConsole { func newMockConsole(w, h uint32) *mockConsole {
return &mockConsole{ return &mockConsole{
width: w, width: w,
height: h, height: h,
@ -383,7 +383,7 @@ func newMockConsole(w, h uint16) *mockConsole {
} }
} }
func (cons *mockConsole) Dimensions() (uint16, uint16) { func (cons *mockConsole) Dimensions() (uint32, uint32) {
return cons.width, cons.height return cons.width, cons.height
} }
@ -391,7 +391,7 @@ func (cons *mockConsole) DefaultColors() (uint8, uint8) {
return cons.fg, cons.bg return cons.fg, cons.bg
} }
func (cons *mockConsole) Fill(x, y, width, height uint16, fg, bg uint8) { func (cons *mockConsole) Fill(x, y, width, height uint32, fg, bg uint8) {
yEnd := y + height - 1 yEnd := y + height - 1
xEnd := x + width - 1 xEnd := x + width - 1
@ -405,7 +405,7 @@ func (cons *mockConsole) Fill(x, y, width, height uint16, fg, bg uint8) {
} }
} }
func (cons *mockConsole) Scroll(dir console.ScrollDir, lines uint16) { func (cons *mockConsole) Scroll(dir console.ScrollDir, lines uint32) {
switch dir { switch dir {
case console.ScrollDirUp: case console.ScrollDirUp:
cons.scrollUpCount++ cons.scrollUpCount++
@ -421,7 +421,7 @@ func (cons *mockConsole) Palette() color.Palette {
func (cons *mockConsole) SetPaletteColor(index uint8, color color.RGBA) { func (cons *mockConsole) SetPaletteColor(index uint8, color color.RGBA) {
} }
func (cons *mockConsole) Write(b byte, fg, bg uint8, x, y uint16) { func (cons *mockConsole) Write(b byte, fg, bg uint8, x, y uint32) {
offset := ((y - 1) * cons.width) + (x - 1) offset := ((y - 1) * cons.width) + (x - 1)
cons.chars[offset] = b cons.chars[offset] = b
cons.fgAttrs[offset] = fg cons.fgAttrs[offset] = fg