mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
Change Dimensions() signature to support querying for characters or pixels
This commit is contained in:
parent
952d0bf4a5
commit
cbf0c82702
@ -61,7 +61,7 @@ func (t *VT) AttachTo(cons console.Device) {
|
||||
}
|
||||
|
||||
t.cons = cons
|
||||
t.viewportWidth, t.viewportHeight = cons.Dimensions()
|
||||
t.viewportWidth, t.viewportHeight = cons.Dimensions(console.Characters)
|
||||
t.viewportY = 0
|
||||
t.defaultFg, t.defaultBg = cons.DefaultColors()
|
||||
t.curFg, t.curBg = t.defaultFg, t.defaultBg
|
||||
|
@ -366,7 +366,7 @@ func newMockConsole(w, h uint32) *mockConsole {
|
||||
}
|
||||
}
|
||||
|
||||
func (cons *mockConsole) Dimensions() (uint32, uint32) {
|
||||
func (cons *mockConsole) Dimensions(_ console.Dimension) (uint32, uint32) {
|
||||
return cons.width, cons.height
|
||||
}
|
||||
|
||||
|
@ -14,11 +14,25 @@ const (
|
||||
ScrollDirDown
|
||||
)
|
||||
|
||||
// Dimension defines the types of dimensions that can be queried off a device.
|
||||
type Dimension uint8
|
||||
|
||||
const (
|
||||
// Characters describes the number of characters in
|
||||
// the console depending on the currently active
|
||||
// font.
|
||||
Characters Dimension = iota
|
||||
|
||||
// Pixels describes the number of pixels in the console framebuffer.
|
||||
Pixels
|
||||
)
|
||||
|
||||
// The Device interface is implemented by objects that can function as system
|
||||
// consoles.
|
||||
type Device interface {
|
||||
// Dimensions returns the width and height of the console in characters.
|
||||
Dimensions() (uint32, uint32)
|
||||
// Pixel returns the width and height of the console
|
||||
// using a particual dimension.
|
||||
Dimensions(Dimension) (uint32, uint32)
|
||||
|
||||
// DefaultColors returns the default foreground and background colors
|
||||
// used by this console.
|
||||
|
@ -70,9 +70,14 @@ func NewVgaTextConsole(columns, rows uint32, fbPhysAddr uintptr) *VgaTextConsole
|
||||
}
|
||||
}
|
||||
|
||||
// Dimensions returns the console width and height in characters.
|
||||
func (cons *VgaTextConsole) Dimensions() (uint32, uint32) {
|
||||
return cons.width, cons.height
|
||||
// Dimensions returns the console width and height in the specified dimension.
|
||||
func (cons *VgaTextConsole) Dimensions(dim Dimension) (uint32, uint32) {
|
||||
switch dim {
|
||||
case Characters:
|
||||
return cons.width, cons.height
|
||||
default:
|
||||
return cons.width * 8, cons.height * 16
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultColors returns the default foreground and background colors
|
||||
|
@ -15,9 +15,18 @@ import (
|
||||
|
||||
func TestVgaTextDimensions(t *testing.T) {
|
||||
var cons Device = NewVgaTextConsole(40, 50, 0)
|
||||
if w, h := cons.Dimensions(); w != 40 || h != 50 {
|
||||
if w, h := cons.Dimensions(Characters); w != 40 || h != 50 {
|
||||
t.Fatalf("expected console dimensions to be 80x25; got %dx%d", w, h)
|
||||
}
|
||||
|
||||
var (
|
||||
expW uint32 = 40 * 8
|
||||
expH uint32 = 50 * 16
|
||||
)
|
||||
|
||||
if w, h := cons.Dimensions(Pixels); w != expW || h != expH {
|
||||
t.Fatalf("expected console dimensions to be %dx%d; got %dx%d", expW, expH, w, h)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVgaTextDefaultColors(t *testing.T) {
|
||||
@ -68,7 +77,7 @@ func TestVgaTextFill(t *testing.T) {
|
||||
fb := make([]uint16, 80*25)
|
||||
cons := NewVgaTextConsole(80, 25, uintptr(unsafe.Pointer(&fb[0])))
|
||||
cons.fb = fb
|
||||
cw, ch := cons.Dimensions()
|
||||
cw, ch := cons.Dimensions(Characters)
|
||||
|
||||
testPat := uint16(0xDEAD)
|
||||
clearPat := uint16(cons.clearChar)
|
||||
@ -107,7 +116,7 @@ func TestVgaTextScroll(t *testing.T) {
|
||||
fb := make([]uint16, 80*25)
|
||||
cons := NewVgaTextConsole(80, 25, uintptr(unsafe.Pointer(&fb[0])))
|
||||
cons.fb = fb
|
||||
cw, ch := cons.Dimensions()
|
||||
cw, ch := cons.Dimensions(Characters)
|
||||
|
||||
t.Run("up", func(t *testing.T) {
|
||||
specs := []uint32{
|
||||
|
Loading…
x
Reference in New Issue
Block a user