Merge pull request #40 from jesseduffield/add-title-prefix

This commit is contained in:
Stefan Haller 2023-09-09 09:41:55 +02:00 committed by GitHub
commit fc7119a393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

14
gui.go
View File

@ -1020,6 +1020,14 @@ func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error {
}
tabs := v.Tabs
prefix := v.TitlePrefix
if prefix != "" {
if len(v.FrameRunes) > 0 {
prefix += string(v.FrameRunes[0])
} else {
prefix += "─"
}
}
separator := " - "
charIndex := 0
currentTabStart := -1
@ -1043,6 +1051,12 @@ func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error {
str := strings.Join(tabs, separator)
x := v.x0 + 2
for _, ch := range prefix {
if err := g.SetRune(x, v.y0, ch, fgColor, bgColor); err != nil {
return err
}
x += runewidth.RuneWidth(ch)
}
for i, ch := range str {
if x < 0 {
continue

View File

@ -122,6 +122,10 @@ type View struct {
// If Frame is true, Title allows to configure a title for the view.
Title string
// If non-empty, TitlePrefix is prepended to the title of a view regardless on
// the the currently selected tab (if any.)
TitlePrefix string
Tabs []string
TabIndex int
@ -1348,7 +1352,10 @@ func (v *View) GetClickedTabIndex(x int) int {
return 0
}
charX := 1
charX := len(v.TitlePrefix) + 1
if v.TitlePrefix != "" {
charX += 1
}
if x <= charX {
return -1
}