gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/termios/termios_plan9.go (about) 1 // Copyright 2015-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build plan9 6 7 package termios 8 9 import ( 10 "fmt" 11 "os" 12 "path/filepath" 13 ) 14 15 // Termios is used to manipulate the control channel of a kernel. 16 type Termios struct { 17 } 18 19 // Winsize holds the window size information, it is modeled on unix.Winsize. 20 type Winsize struct { 21 Row uint16 22 Col uint16 23 Xpixel uint16 24 Ypixel uint16 25 } 26 27 // TTYIO is a wrapper that only allows Read and Write. 28 type TTYIO struct { 29 f *os.File 30 } 31 32 // New creates a new TTYIO using /dev/tty 33 func New() (*TTYIO, error) { 34 return NewWithDev("/dev/cons") 35 } 36 37 // NewWithDev creates a new TTYIO with the specified device 38 func NewWithDev(device string) (*TTYIO, error) { 39 f, err := os.OpenFile(device, os.O_RDWR, 0) 40 if err != nil { 41 return nil, err 42 } 43 return &TTYIO{f: f}, nil 44 } 45 46 // NewTTYS returns a new TTYIO. 47 func NewTTYS(port string) (*TTYIO, error) { 48 f, err := os.OpenFile(filepath.Join("/dev", port), os.O_RDWR, 0620) 49 if err != nil { 50 return nil, err 51 } 52 return &TTYIO{f: f}, nil 53 } 54 55 // GetTermios returns a filled-in Termios, from an fd. 56 func GetTermios(fd uintptr) (*Termios, error) { 57 return &Termios{}, nil 58 } 59 60 // Get terms a Termios from a TTYIO. 61 func (t *TTYIO) Get() (*Termios, error) { 62 return GetTermios(t.f.Fd()) 63 } 64 65 // SetTermios sets tty parameters for an fd from a Termios. 66 func SetTermios(fd uintptr, ti *Termios) error { 67 return fmt.Errorf("Plan 9: not yet") 68 } 69 70 // Set sets tty parameters for a TTYIO from a Termios. 71 func (t *TTYIO) Set(ti *Termios) error { 72 return SetTermios(t.f.Fd(), ti) 73 } 74 75 // GetWinSize gets window size from an fd. 76 func GetWinSize(fd uintptr) (*Winsize, error) { 77 return nil, fmt.Errorf("Plan 9: not yet") 78 } 79 80 // GetWinSize gets window size from a TTYIO. 81 func (t *TTYIO) GetWinSize() (*Winsize, error) { 82 return GetWinSize(t.f.Fd()) 83 } 84 85 // SetWinSize sets window size for an fd from a Winsize. 86 func SetWinSize(fd uintptr, w *Winsize) error { 87 return fmt.Errorf("Plan 9: not yet") 88 } 89 90 // SetWinSize sets window size for a TTYIO from a Winsize. 91 func (t *TTYIO) SetWinSize(w *Winsize) error { 92 return SetWinSize(t.f.Fd(), w) 93 } 94 95 // MakeRaw modifies Termio state so, if it used for an fd or tty, it will set it to raw mode. 96 func MakeRaw(term *Termios) *Termios { 97 raw := *term 98 return &raw 99 } 100 101 // MakeSerialBaud updates the Termios to set the baudrate 102 func MakeSerialBaud(term *Termios, baud int) (*Termios, error) { 103 t := *term 104 105 return &t, nil 106 } 107 108 // MakeSerialDefault updates the Termios to typical serial configuration: 109 // - Ignore all flow control (modem, hardware, software...) 110 // - Translate carriage return to newline on input 111 // - Enable canonical mode: Input is available line by line, with line editing 112 // enabled (ERASE, KILL are supported) 113 // - Local ECHO is added (and handled by line editing) 114 // - Map newline to carriage return newline on output 115 func MakeSerialDefault(term *Termios) *Termios { 116 t := *term 117 118 return &t 119 }