mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-22 08:04:18 +02:00
Short circuit help view sooner if we can
This commit is contained in:
parent
2e16f2682e
commit
40724af7e1
1 changed files with 7 additions and 3 deletions
10
ui/stash.go
10
ui/stash.go
|
|
@ -706,16 +706,18 @@ func stashHelpView(m stashModel) string {
|
|||
// builds the help view from various sections pieces, truncating it if the view
|
||||
// would otherwise wrap to two lines.
|
||||
func stashHelpViewBuilder(windowWidth int, sections ...string) string {
|
||||
if len(sections) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
const truncationWidth = 1 // width of "…"
|
||||
|
||||
var (
|
||||
s string
|
||||
next string
|
||||
maxWidth = windowWidth - stashViewHorizontalPadding - truncationWidth
|
||||
)
|
||||
|
||||
if len(sections) == 0 {
|
||||
return s
|
||||
}
|
||||
for i := 0; i < len(sections); i++ {
|
||||
|
||||
// If we need this more often we'll formalize something rather than
|
||||
|
|
@ -731,6 +733,8 @@ func stashHelpViewBuilder(windowWidth int, sections ...string) string {
|
|||
next += stashHelpDivider
|
||||
}
|
||||
|
||||
// Only this (and the following) help text items if we have the
|
||||
// horizontal space
|
||||
if ansi.PrintableRuneWidth(s)+ansi.PrintableRuneWidth(next) >= maxWidth {
|
||||
s += common.Subtle("…")
|
||||
break
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue