forked from tslocum/cview
Document adding TextView.SetMaxLines
This commit is contained in:
parent
40808e7840
commit
3feec6ebfb
|
@ -1,6 +1,7 @@
|
|||
v1.4.6 (WIP)
|
||||
- Add Box.ShowFocus
|
||||
- Add List.GetOffset, List.SetOffset and List.SetSelectedTextAttributes
|
||||
- Add TextView.SetMaxLines
|
||||
- Add Vim-style keybindings to List
|
||||
- Fix List not updating selected item before calling selected handlers
|
||||
- Do not handle right click on List when there is no context menu
|
||||
|
|
35
textview.go
35
textview.go
|
@ -136,7 +136,7 @@ type TextView struct {
|
|||
// The index of the first line shown in the text view.
|
||||
lineOffset int
|
||||
|
||||
// The maximum number of liens the text view will hold (set to 0 for no limit)
|
||||
// The maximum number of newlines the text view will hold (0 = unlimited).
|
||||
maxLines int
|
||||
|
||||
// If set to true, the text view will always remain at the end of the content.
|
||||
|
@ -197,16 +197,13 @@ type TextView struct {
|
|||
// NewTextView returns a new text view.
|
||||
func NewTextView() *TextView {
|
||||
return &TextView{
|
||||
Box: NewBox(),
|
||||
highlights: make(map[string]struct{}),
|
||||
lineOffset: -1,
|
||||
scrollable: true,
|
||||
align: AlignLeft,
|
||||
wrap: true,
|
||||
textColor: Styles.PrimaryTextColor,
|
||||
regions: false,
|
||||
dynamicColors: false,
|
||||
maxLines: 0,
|
||||
Box: NewBox(),
|
||||
highlights: make(map[string]struct{}),
|
||||
lineOffset: -1,
|
||||
scrollable: true,
|
||||
align: AlignLeft,
|
||||
wrap: true,
|
||||
textColor: Styles.PrimaryTextColor,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,16 +391,18 @@ func (t *TextView) SetHighlightedFunc(handler func(added, removed, remaining []s
|
|||
}
|
||||
|
||||
func (t *TextView) clipBuffer() {
|
||||
if t.maxLines > 0 {
|
||||
lenbuf := len(t.buffer)
|
||||
if lenbuf > t.maxLines {
|
||||
t.buffer = t.buffer[lenbuf-t.maxLines:]
|
||||
}
|
||||
if t.maxLines <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
lenbuf := len(t.buffer)
|
||||
if lenbuf > t.maxLines {
|
||||
t.buffer = t.buffer[lenbuf-t.maxLines:]
|
||||
}
|
||||
}
|
||||
|
||||
// SetMaxLines establishes the maximum amount of lines the text view will hold
|
||||
// before discarding older data from the buffer
|
||||
// SetMaxLines sets the maximum number of newlines the text view will hold
|
||||
// before discarding older data from the buffer.
|
||||
func (t *TextView) SetMaxLines(maxLines int) *TextView {
|
||||
t.maxLines = maxLines
|
||||
t.clipBuffer()
|
||||
|
|
Loading…
Reference in New Issue