From 78c87ab165d2a60c17778c68eb9932d6b1f6ce0c Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Wed, 5 Jul 2017 15:52:45 +0100 Subject: [PATCH] Cleanup and revise TTY interface --- src/gopheros/device/tty/device.go | 44 +++++++++++++++++++++++++++ src/gopheros/kernel/driver/tty/tty.go | 19 ------------ 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 src/gopheros/device/tty/device.go delete mode 100644 src/gopheros/kernel/driver/tty/tty.go diff --git a/src/gopheros/device/tty/device.go b/src/gopheros/device/tty/device.go new file mode 100644 index 0000000..a0f4e4d --- /dev/null +++ b/src/gopheros/device/tty/device.go @@ -0,0 +1,44 @@ +package tty + +import ( + "gopheros/device/video/console" + "io" +) + +// State defines the supported terminal state values. +type State uint8 + +const ( + // StateInactive marks the terminal as inactive. Any writes will be + // buffered and not synced to the attached console. + StateInactive State = iota + + // StateActive marks the terminal as active. Any writes will be + // buffered and also synced to the attached console. + StateActive +) + +// Device is implemented by objects that can be used as a terminal device. +type Device interface { + io.Writer + io.ByteWriter + + // AttachTo connects a TTY to a console instance. + AttachTo(console.Device) + + // State returns the TTY's state. + State() State + + // SetState updates the TTY's state. + SetState(State) + + // CursorPosition returns the current cursor x,y coordinates. Both + // coordinates are 1-based (top-left corner has coordinates 1,1). + CursorPosition() (uint16, uint16) + + // SetCursorPosition sets the current cursor position to (x,y). Both + // coordinates are 1-based (top-left corner has coordinates 1,1). + // Implementations are expected to clip the cursor position to their + // viewport. + SetCursorPosition(x, y uint16) +} diff --git a/src/gopheros/kernel/driver/tty/tty.go b/src/gopheros/kernel/driver/tty/tty.go deleted file mode 100644 index f46ce2f..0000000 --- a/src/gopheros/kernel/driver/tty/tty.go +++ /dev/null @@ -1,19 +0,0 @@ -package tty - -import "io" - -// Tty is implemented by objects that can register themselves as ttys. -type Tty interface { - io.Writer - io.ByteWriter - - // Position returns the current cursor position (x, y). - Position() (uint16, uint16) - - // SetPosition sets the current cursor position to (x,y). Console implementations - // must clip the provided cursor position if it exceeds the console dimensions. - SetPosition(x, y uint16) - - // Clear clears the terminal. - Clear() -}