Support custom separator of inline info

Close #2030
Close #3084
This commit is contained in:
Junegunn Choi
2023-01-24 17:40:08 +09:00
parent ae897c8cdb
commit 618d317803
5 changed files with 43 additions and 17 deletions

View File

@@ -147,6 +147,7 @@ type labelPrinter func(tui.Window, int)
type Terminal struct {
initDelay time.Duration
infoStyle infoStyle
infoSep string
separator labelPrinter
separatorLen int
spinner []string
@@ -579,6 +580,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
t := Terminal{
initDelay: delay,
infoStyle: opts.InfoStyle,
infoSep: opts.InfoSep,
separator: nil,
spinner: makeSpinner(opts.Unicode),
queryLen: [2]int{0, 0},
@@ -1393,16 +1395,21 @@ func (t *Terminal) printInfo() {
pos = 2
case infoInline:
pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1
if pos+len(" < ") > t.window.Width() {
return
str := t.infoSep
maxWidth := t.window.Width() - pos
width := runewidth.StringWidth(str)
if width > maxWidth {
trimmed, _ := t.trimRight([]rune(str), maxWidth)
str = string(trimmed)
width = maxWidth
}
t.move(line, pos, t.separatorLen == 0)
if t.reading {
t.window.CPrint(tui.ColSpinner, " < ")
t.window.CPrint(tui.ColSpinner, str)
} else {
t.window.CPrint(tui.ColPrompt, " < ")
t.window.CPrint(tui.ColPrompt, str)
}
pos += len(" < ")
pos += width
case infoHidden:
return
}