fix(deps): update module golang.org/x/term to v0.32.0

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-05-05 18:53:33 +00:00
committed by GitHub
parent 344796ae6b
commit 32d389a19c
4 changed files with 62 additions and 14 deletions

2
go.mod
View File

@ -72,7 +72,7 @@ require (
golang.org/x/net v0.39.0 golang.org/x/net v0.39.0
golang.org/x/sync v0.14.0 golang.org/x/sync v0.14.0
golang.org/x/sys v0.33.0 golang.org/x/sys v0.33.0
golang.org/x/term v0.31.0 golang.org/x/term v0.32.0
golang.org/x/text v0.24.0 golang.org/x/text v0.24.0
google.golang.org/protobuf v1.36.6 google.golang.org/protobuf v1.36.6
gopkg.in/inf.v0 v0.9.1 gopkg.in/inf.v0 v0.9.1

4
go.sum
View File

@ -640,8 +640,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=

68
vendor/golang.org/x/term/terminal.go generated vendored
View File

@ -6,6 +6,7 @@ package term
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"runtime" "runtime"
"strconv" "strconv"
@ -36,6 +37,26 @@ var vt100EscapeCodes = EscapeCodes{
Reset: []byte{keyEscape, '[', '0', 'm'}, Reset: []byte{keyEscape, '[', '0', 'm'},
} }
// A History provides a (possibly bounded) queue of input lines read by [Terminal.ReadLine].
type History interface {
// Add will be called by [Terminal.ReadLine] to add
// a new, most recent entry to the history.
// It is allowed to drop any entry, including
// the entry being added (e.g., if it's deemed an invalid entry),
// the least-recent entry (e.g., to keep the history bounded),
// or any other entry.
Add(entry string)
// Len returns the number of entries in the history.
Len() int
// At returns an entry from the history.
// Index 0 is the most-recently added entry and
// index Len()-1 is the least-recently added entry.
// If index is < 0 or >= Len(), it panics.
At(idx int) string
}
// Terminal contains the state for running a VT100 terminal that is capable of // Terminal contains the state for running a VT100 terminal that is capable of
// reading lines of input. // reading lines of input.
type Terminal struct { type Terminal struct {
@ -86,9 +107,14 @@ type Terminal struct {
remainder []byte remainder []byte
inBuf [256]byte inBuf [256]byte
// history contains previously entered commands so that they can be // History records and retrieves lines of input read by [ReadLine] which
// accessed with the up and down keys. // a user can retrieve and navigate using the up and down arrow keys.
history stRingBuffer //
// It is not safe to call ReadLine concurrently with any methods on History.
//
// [NewTerminal] sets this to a default implementation that records the
// last 100 lines of input.
History History
// historyIndex stores the currently accessed history entry, where zero // historyIndex stores the currently accessed history entry, where zero
// means the immediately previous entry. // means the immediately previous entry.
historyIndex int historyIndex int
@ -111,6 +137,7 @@ func NewTerminal(c io.ReadWriter, prompt string) *Terminal {
termHeight: 24, termHeight: 24,
echo: true, echo: true,
historyIndex: -1, historyIndex: -1,
History: &stRingBuffer{},
} }
} }
@ -450,6 +477,23 @@ func visualLength(runes []rune) int {
return length return length
} }
// histroryAt unlocks the terminal and relocks it while calling History.At.
func (t *Terminal) historyAt(idx int) (string, bool) {
t.lock.Unlock() // Unlock to avoid deadlock if History methods use the output writer.
defer t.lock.Lock() // panic in At (or Len) protection.
if idx < 0 || idx >= t.History.Len() {
return "", false
}
return t.History.At(idx), true
}
// historyAdd unlocks the terminal and relocks it while calling History.Add.
func (t *Terminal) historyAdd(entry string) {
t.lock.Unlock() // Unlock to avoid deadlock if History methods use the output writer.
defer t.lock.Lock() // panic in Add protection.
t.History.Add(entry)
}
// handleKey processes the given key and, optionally, returns a line of text // handleKey processes the given key and, optionally, returns a line of text
// that the user has entered. // that the user has entered.
func (t *Terminal) handleKey(key rune) (line string, ok bool) { func (t *Terminal) handleKey(key rune) (line string, ok bool) {
@ -497,7 +541,7 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) {
t.pos = len(t.line) t.pos = len(t.line)
t.moveCursorToPos(t.pos) t.moveCursorToPos(t.pos)
case keyUp: case keyUp:
entry, ok := t.history.NthPreviousEntry(t.historyIndex + 1) entry, ok := t.historyAt(t.historyIndex + 1)
if !ok { if !ok {
return "", false return "", false
} }
@ -516,7 +560,7 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) {
t.setLine(runes, len(runes)) t.setLine(runes, len(runes))
t.historyIndex-- t.historyIndex--
default: default:
entry, ok := t.history.NthPreviousEntry(t.historyIndex - 1) entry, ok := t.historyAt(t.historyIndex - 1)
if ok { if ok {
t.historyIndex-- t.historyIndex--
runes := []rune(entry) runes := []rune(entry)
@ -781,7 +825,7 @@ func (t *Terminal) readLine() (line string, err error) {
if lineOk { if lineOk {
if t.echo { if t.echo {
t.historyIndex = -1 t.historyIndex = -1
t.history.Add(line) t.historyAdd(line)
} }
if lineIsPasted { if lineIsPasted {
err = ErrPasteIndicator err = ErrPasteIndicator
@ -938,19 +982,23 @@ func (s *stRingBuffer) Add(a string) {
} }
} }
// NthPreviousEntry returns the value passed to the nth previous call to Add. func (s *stRingBuffer) Len() int {
return s.size
}
// At returns the value passed to the nth previous call to Add.
// If n is zero then the immediately prior value is returned, if one, then the // If n is zero then the immediately prior value is returned, if one, then the
// next most recent, and so on. If such an element doesn't exist then ok is // next most recent, and so on. If such an element doesn't exist then ok is
// false. // false.
func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) { func (s *stRingBuffer) At(n int) string {
if n < 0 || n >= s.size { if n < 0 || n >= s.size {
return "", false panic(fmt.Sprintf("term: history index [%d] out of range [0,%d)", n, s.size))
} }
index := s.head - n index := s.head - n
if index < 0 { if index < 0 {
index += s.max index += s.max
} }
return s.entries[index], true return s.entries[index]
} }
// readPasswordLine reads from reader until it finds \n or io.EOF. // readPasswordLine reads from reader until it finds \n or io.EOF.

2
vendor/modules.txt vendored
View File

@ -1136,7 +1136,7 @@ golang.org/x/sys/unix
golang.org/x/sys/windows golang.org/x/sys/windows
golang.org/x/sys/windows/registry golang.org/x/sys/windows/registry
golang.org/x/sys/windows/svc/eventlog golang.org/x/sys/windows/svc/eventlog
# golang.org/x/term v0.31.0 # golang.org/x/term v0.32.0
## explicit; go 1.23.0 ## explicit; go 1.23.0
golang.org/x/term golang.org/x/term
# golang.org/x/text v0.24.0 # golang.org/x/text v0.24.0