summaryrefslogtreecommitdiffstats
path: root/src/terminal.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-06-11 00:04:24 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-06-11 16:09:15 +0900
commitd0b7780239dd9f9e2bf6c252e03b463990a966bd (patch)
treedbf36a5ec8b556743e03f85be367dce731975cab /src/terminal.go
parente627ca6bd7fa40ef3f9077aa49f7c9019b474997 (diff)
Add --info=right
Related: #3322
Diffstat (limited to 'src/terminal.go')
-rw-r--r--src/terminal.go43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 08ea253b..94f4c6cd 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -565,7 +565,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
if previewBox != nil && opts.Preview.aboveOrBelow() {
effectiveMinHeight += 1 + borderLines(opts.Preview.border)
}
- if opts.InfoStyle != infoDefault {
+ if opts.InfoStyle.noExtraLine() {
effectiveMinHeight--
}
effectiveMinHeight += borderLines(opts.BorderShape)
@@ -845,7 +845,7 @@ func (t *Terminal) parsePrompt(prompt string) (func(), int) {
}
func (t *Terminal) noInfoLine() bool {
- return t.infoStyle != infoDefault
+ return t.infoStyle.noExtraLine()
}
func getScrollbar(total int, height int, offset int) (int, int) {
@@ -1479,6 +1479,8 @@ func (t *Terminal) printInfo() {
printSpinner()
t.move(line+1, 2, false)
pos = 2
+ case infoRight:
+ t.move(line+1, 0, false)
case infoInlineRight:
pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1
t.move(line, pos, true)
@@ -1529,6 +1531,37 @@ func (t *Terminal) printInfo() {
if t.failed != nil && t.count == 0 {
output = fmt.Sprintf("[Command failed: %s]", *t.failed)
}
+
+ printSeparator := func(fillLength int, pad bool) {
+ // --------_
+ if t.separatorLen > 0 {
+ t.separator(t.window, fillLength)
+ t.window.Print(" ")
+ } else if pad {
+ t.window.Print(strings.Repeat(" ", fillLength+1))
+ }
+ }
+ if t.infoStyle == infoRight {
+ maxWidth := t.window.Width()
+ if t.reading {
+ // Need space for spinner and a margin column
+ maxWidth -= 2
+ }
+ output = t.trimMessage(output, maxWidth)
+ fillLength := t.window.Width() - len(output) - 2
+ if t.reading {
+ if fillLength >= 2 {
+ printSeparator(fillLength-2, true)
+ }
+ printSpinner()
+ t.window.Print(" ")
+ } else if fillLength >= 0 {
+ printSeparator(fillLength, true)
+ }
+ t.window.CPrint(tui.ColInfo, output)
+ return
+ }
+
if t.infoStyle == infoInlineRight {
pos = util.Max(pos, t.window.Width()-util.StringWidth(output)-3)
if pos >= t.window.Width() {
@@ -1539,14 +1572,14 @@ func (t *Terminal) printInfo() {
t.window.Print(" ")
pos += 2
}
+
maxWidth := t.window.Width() - pos
output = t.trimMessage(output, maxWidth)
t.window.CPrint(tui.ColInfo, output)
-
fillLength := maxWidth - len(output) - 2
- if t.separatorLen > 0 && fillLength > 0 {
+ if fillLength > 0 {
t.window.CPrint(tui.ColSeparator, " ")
- t.separator(t.window, fillLength)
+ printSeparator(fillLength, false)
}
}