Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Plan 9 #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions term_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package readline

import "os"

// State contains the state of a terminal.
type State struct {
consctl *os.File
}

// MakeRaw put the terminal connected to the given file descriptor into raw
// mode and returns the previous state of the terminal so that it can be
// restored.
func MakeRaw(fd int) (*State, error) {
f, err := os.OpenFile("/dev/consctl", os.O_WRONLY, 0)
if err != nil {
return nil, err
}
if _, err := f.WriteString("rawon"); err != nil {
return nil, err
}
return &State{consctl: f}, nil
}

// Restore restores the terminal connected to the given file descriptor to a
// previous state.
func restoreTerm(fd int, state *State) error {
return state.consctl.Close()
}
44 changes: 44 additions & 0 deletions utils_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package readline

import (
"io"
"io/ioutil"
"strconv"
"syscall"
)

func SuspendMe() {
}

func GetScreenWidth() int {
const w = 0

// $COLS is set by vt(1). Read the environment variable directly
// because Go might be caching the value.
// See https://github.com/golang/go/issues/25234
b, err := ioutil.ReadFile("/env/COLS")
if err != nil {
return w
}
cols, err := strconv.Atoi(string(b))
if err != nil {
return w
}
return cols
}

// ClearScreen clears the console screen
func ClearScreen(w io.Writer) (int, error) {
return w.Write([]byte("\033[H"))
}

func DefaultIsTerminal() bool {
return true
}

func GetStdin() int {
return syscall.Stdin
}

func DefaultOnWidthChanged(f func()) {
}