mirror of
https://github.com/rivo/tview.git
synced 2025-04-28 13:48:53 +08: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"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@ -239,6 +240,34 @@ func (t *TextView) SetText(text string) *TextView {
|
|||||||
return t
|
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
|
// SetDynamicColors sets the flag that allows the text color to be changed
|
||||||
// dynamically. See class description for details.
|
// dynamically. See class description for details.
|
||||||
func (t *TextView) SetDynamicColors(dynamic bool) *TextView {
|
func (t *TextView) SetDynamicColors(dynamic bool) *TextView {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user