aboutsummaryrefslogtreecommitdiff
path: root/ui/messages/textbase.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-22 17:23:54 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-22 17:23:54 +0300
commitcce79ab7d8481a06054166049876c8a2cbb3418f (patch)
treef796cfc0d3633563d38cc9809fd0c21c524a4dec /ui/messages/textbase.go
parent09703c6b9c343feca8ee5db263d25f174171339d (diff)
Clean up code
Diffstat (limited to 'ui/messages/textbase.go')
-rw-r--r--ui/messages/textbase.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/ui/messages/textbase.go b/ui/messages/textbase.go
index c241c0a..f805067 100644
--- a/ui/messages/textbase.go
+++ b/ui/messages/textbase.go
@@ -44,6 +44,18 @@ var (
spacePattern = regexp.MustCompile(`\s+`)
)
+func matchBoundaryPattern(extract tstring.TString) tstring.TString {
+ matches := boundaryPattern.FindAllStringIndex(extract.String(), -1)
+ if len(matches) > 0 {
+ if match := matches[len(matches)-1]; len(match) >= 2 {
+ if until := match[1]; until < len(extract) {
+ extract = extract[:until]
+ }
+ }
+ }
+ return extract
+}
+
// CalculateBuffer generates the internal buffer for this message that consists
// of the text of this message split into lines at most as wide as the width
// parameter.
@@ -63,24 +75,14 @@ func (msg *BaseTextMessage) calculateBufferWithText(text tstring.TString, width
} else {
newlines = 0
}
- // Mostly from tview/textview.go#reindexBuffer()
+ // Adapted from tview/textview.go#reindexBuffer()
for len(str) > 0 {
extract := str.Truncate(width)
if len(extract) < len(str) {
if spaces := spacePattern.FindStringIndex(str[len(extract):].String()); spaces != nil && spaces[0] == 0 {
extract = str[:len(extract)+spaces[1]]
}
-
- matches := boundaryPattern.FindAllStringIndex(extract.String(), -1)
- if len(matches) > 0 {
- match := matches[len(matches)-1]
- if len(match) >= 2 {
- until := match[1]
- if until < len(extract) {
- extract = extract[:until]
- }
- }
- }
+ extract = matchBoundaryPattern(extract)
}
msg.buffer = append(msg.buffer, extract)
str = str[len(extract):]