Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/vendor/github.com/chzyer/readline/term_linux.go
2875 views
1
// Copyright 2013 The Go 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
package readline
6
7
import (
8
"syscall"
9
"unsafe"
10
)
11
12
// These constants are declared here, rather than importing
13
// them from the syscall package as some syscall packages, even
14
// on linux, for example gccgo, do not declare them.
15
const ioctlReadTermios = 0x5401 // syscall.TCGETS
16
const ioctlWriteTermios = 0x5402 // syscall.TCSETS
17
18
func getTermios(fd int) (*Termios, error) {
19
termios := new(Termios)
20
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
21
if err != 0 {
22
return nil, err
23
}
24
return termios, nil
25
}
26
27
func setTermios(fd int, termios *Termios) error {
28
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlWriteTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
29
if err != 0 {
30
return err
31
}
32
return nil
33
}
34
35