Debian Codegraph @

term.go

raw symbols SCIP
1 // Copyright 2019 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 term provides support functions for dealing with terminals, as
6 // commonly found on UNIX systems.
7 //
8 // Putting a terminal into raw mode is the most common requirement:
9 //
10 // oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
11 // if err != nil {
12 // panic(err)
13 // }
14 // defer term.Restore(int(os.Stdin.Fd()), oldState)
15 //
16 // Note that on non-Unix systems os.Stdin.Fd() may not be 0.
17 package termscip-go gomod golang.org/x/term . `golang.org/x/term`/
18
19 // State contains the state of a terminal.
20 type Statescip-go gomod golang.org/x/term . `golang.org/x/term`/State# struct {
21 statescip-go gomod golang.org/x/term . `golang.org/x/term`/State#state.
22 }
23
24 // IsTerminal returns whether the given file descriptor is a terminal.
25 func IsTerminalscip-go gomod golang.org/x/term . `golang.org/x/term`/IsTerminal().(fd int) bool {
26 return isTerminalscip-go gomod golang.org/x/term . `golang.org/x/term`/isTerminal().(fd)
27 }
28
29 // MakeRaw puts the terminal connected to the given file descriptor into raw
30 // mode and returns the previous state of the terminal so that it can be
31 // restored.
32 func MakeRawscip-go gomod golang.org/x/term . `golang.org/x/term`/MakeRaw().(fd int) (*Statescip-go gomod golang.org/x/term . `golang.org/x/term`/State#, error) {
33 return makeRawscip-go gomod golang.org/x/term . `golang.org/x/term`/makeRaw().(fd)
34 }
35
36 // GetState returns the current state of a terminal which may be useful to
37 // restore the terminal after a signal.
38 func GetStatescip-go gomod golang.org/x/term . `golang.org/x/term`/GetState().(fd int) (*Statescip-go gomod golang.org/x/term . `golang.org/x/term`/State#, error) {
39 return getStatescip-go gomod golang.org/x/term . `golang.org/x/term`/getState().(fd)
40 }
41
42 // Restore restores the terminal connected to the given file descriptor to a
43 // previous state.
44 func Restorescip-go gomod golang.org/x/term . `golang.org/x/term`/Restore().(fd int, oldState *Statescip-go gomod golang.org/x/term . `golang.org/x/term`/State#) error {
45 return restorescip-go gomod golang.org/x/term . `golang.org/x/term`/restore().(fd, oldState)
46 }
47
48 // GetSize returns the visible dimensions of the given terminal.
49 //
50 // These dimensions don't include any scrollback buffer height.
51 func GetSizescip-go gomod golang.org/x/term . `golang.org/x/term`/GetSize().(fd int) (width, height int, err error) {
52 return getSizescip-go gomod golang.org/x/term . `golang.org/x/term`/getSize().(fd)
53 }
54
55 // ReadPassword reads a line of input from a terminal without local echo. This
56 // is commonly used for inputting passwords and other sensitive data. The slice
57 // returned does not include the \n.
58 func ReadPasswordscip-go gomod golang.org/x/term . `golang.org/x/term`/ReadPassword().(fd int) ([]byte, error) {
59 return readPasswordscip-go gomod golang.org/x/term . `golang.org/x/term`/readPassword().(fd)
60 }