@@ -44,15 +44,15 @@ type ScreenInfo struct {
44
44
// and then Prefix ones, per line to draw, to generate according prefixes.
45
45
type Prefixer interface {
46
46
InitPrefixer (ViewPos , ScreenInfo ) int
47
- Prefix (currentItem , currentLine int , selected , lastLine bool ) string
47
+ Prefix (currentItem , currentLine int , selected bool ) string
48
48
}
49
49
50
50
// Suffixer is used to suffix all visible Lines.
51
51
// InitSuffixer gets called ones on the beginning of the Lines methode
52
52
// and then Suffix ones, per line to draw, to generate according suffixes.
53
53
type Suffixer interface {
54
54
InitSuffixer (ViewPos , ScreenInfo ) int
55
- Suffix (currentItem , currentLine int , selected , lastLine bool ) string
55
+ Suffix (currentItem , currentLine int , selected bool ) string
56
56
}
57
57
58
58
// Model is a bubbletea List of strings
@@ -74,8 +74,8 @@ type Model struct {
74
74
75
75
Wrap bool
76
76
77
- // PrefixFunc func(position ViewPos, height int) (func(currentIndex int, selected bool, wrapedIndex int) string, int)
78
77
PrefixGen Prefixer
78
+ SuffixGen Suffixer
79
79
80
80
LineStyle termenv.Style
81
81
SelectedStyle termenv.Style
@@ -126,28 +126,31 @@ func (m Model) View() string {
126
126
// used to display the current user interface
127
127
func (m * Model ) Lines () []string {
128
128
// get public variables as locals so they can't change while using
129
+
129
130
// check visible area
130
131
height := m .Height
131
132
width := m .Width
132
133
if height * width <= 0 {
133
134
panic ("Can't display with zero width or hight of Viewport" )
134
135
}
135
136
136
- // This is only used if the Lines methode is called befor the Update methode is called the first time
137
- var holePrefixWidth int
137
+ // Get the Width of each suf/prefix
138
+ var prefixWidth , suffixWidth int
138
139
if m .PrefixGen != nil {
139
- holePrefixWidth = m .PrefixGen .InitPrefixer (m .viewPos , ScreenInfo {Height : m .Height , Width : m .Width , Profile : termenv .ColorProfile ()})
140
+ prefixWidth = m .PrefixGen .InitPrefixer (m .viewPos , ScreenInfo {Height : m .Height , Width : m .Width , Profile : termenv .ColorProfile ()})
141
+ }
142
+ if m .SuffixGen != nil {
143
+ suffixWidth = m .SuffixGen .InitSuffixer (m .viewPos , ScreenInfo {Height : m .Height , Width : m .Width , Profile : termenv .ColorProfile ()})
140
144
}
141
145
142
146
// Get actual content width
143
- contentWidth := width - holePrefixWidth
147
+ contentWidth := width - prefixWidth - suffixWidth
144
148
145
149
// Check if there is space for the content left
146
150
if contentWidth <= 0 {
147
151
panic ("Can't display with zero width for content" )
148
152
}
149
153
150
- // If set
151
154
wrap := m .Wrap
152
155
if wrap {
153
156
// renew wrap of all items
@@ -188,16 +191,19 @@ out:
188
191
// TODO hard limit the string length
189
192
}
190
193
191
- var linePrefix string
194
+ // Surrounding content
195
+ var linePrefix , lineSuffix string
192
196
if m .PrefixGen != nil {
193
- linePrefix = m .PrefixGen .Prefix (index , 0 , item .selected , item .wrapedLenght == 0 )
197
+ linePrefix = m .PrefixGen .Prefix (index , 0 , item .selected )
198
+ }
199
+ if m .SuffixGen != nil {
200
+ lineSuffix = fmt .Sprintf ("%s%s" , strings .Repeat (" " , contentWidth - ansi .PrintableRuneWidth (content )), m .SuffixGen .Suffix (index , 0 , item .selected ))
194
201
}
195
202
196
- // join pad and first line content
197
- // NOTE line break is not added here because it would mess with the highlighting
198
- line := fmt .Sprintf ("%s%s" , linePrefix , content )
203
+ // Join all
204
+ line := fmt .Sprintf ("%s%s%s" , linePrefix , content , lineSuffix )
199
205
200
- // Selecting: handle highlighting of selected and current lines
206
+ // Highlighting of selected and current lines
201
207
style := m .LineStyle
202
208
if item .selected {
203
209
style = m .SelectedStyle
238
244
// NOTE line break is not added here because it would mess with the highlighting
239
245
var wrapPrefix string
240
246
if m .PrefixGen != nil {
241
- wrapPrefix = m .PrefixGen .Prefix (index , i + 1 , item .selected , i == item . wrapedLenght - 2 )
247
+ wrapPrefix = m .PrefixGen .Prefix (index , i + 1 , item .selected )
242
248
}
243
249
padLine := fmt .Sprintf ("%s%s" , wrapPrefix , line )
244
250
@@ -915,7 +921,7 @@ func (d *DefaultPrefixer) InitPrefixer(position ViewPos, screen ScreenInfo) int
915
921
}
916
922
917
923
// Prefix prefixes a given line
918
- func (d * DefaultPrefixer ) Prefix (currentIndex int , wrapIndex int , selected , lastLine bool ) string {
924
+ func (d * DefaultPrefixer ) Prefix (currentIndex int , wrapIndex int , selected bool ) string {
919
925
// if a number is set, prepend first line with number and both with enough spaces
920
926
firstPad := strings .Repeat (" " , d .numWidth )
921
927
var wrapPad string
0 commit comments