|
|
|
@ -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() |
|
|
|
|