mirror of
https://github.com/rivo/tview.git
synced 2024-11-15 06:12:46 +00:00
Added TextView.GetText(). Resolves #233
This commit is contained in:
parent
a45c8edf60
commit
3e289f3aca
29
textview.go
29
textview.go
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode/utf8"
|
||||
|
||||
@ -239,6 +240,34 @@ func (t *TextView) SetText(text string) *TextView {
|
||||
return t
|
||||
}
|
||||
|
||||
// GetText returns the current text of this text view. If "stripTags" is set
|
||||
// to true, any region/color tags are stripped from the text.
|
||||
func (t *TextView) GetText(stripTags bool) string {
|
||||
// Get the buffer.
|
||||
buffer := t.buffer
|
||||
if !stripTags {
|
||||
buffer = append(buffer, string(t.recentBytes))
|
||||
}
|
||||
|
||||
// Add newlines again.
|
||||
text := strings.Join(buffer, "\n")
|
||||
|
||||
// Strip from tags if required.
|
||||
if stripTags {
|
||||
if t.regions {
|
||||
text = regionPattern.ReplaceAllString(text, "")
|
||||
}
|
||||
if t.dynamicColors {
|
||||
text = colorPattern.ReplaceAllString(text, "")
|
||||
}
|
||||
if t.regions || t.dynamicColors {
|
||||
text = escapePattern.ReplaceAllString(text, `[$1$2]`)
|
||||
}
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
// SetDynamicColors sets the flag that allows the text color to be changed
|
||||
// dynamically. See class description for details.
|
||||
func (t *TextView) SetDynamicColors(dynamic bool) *TextView {
|
||||
|
Loading…
Reference in New Issue
Block a user