Fixed multiline text modals. Fixes #696

pull/703/head
Oliver 2 years ago
parent f0544de1f2
commit 8e58f395ad

@ -1,6 +1,8 @@
package tview
import (
"strings"
"github.com/gdamore/tcell/v2"
)
@ -87,8 +89,8 @@ func (m *Modal) SetDoneFunc(handler func(buttonIndex int, buttonLabel string)) *
}
// SetText sets the message text of the window. The text may contain line
// breaks. Note that words are wrapped, too, based on the final size of the
// window.
// breaks but color tag states will not transfer to following lines. Note that
// words are wrapped, too, based on the final size of the window.
func (m *Modal) SetText(text string) *Modal {
m.text = text
return m
@ -158,7 +160,15 @@ func (m *Modal) Draw(screen tcell.Screen) {
// Reset the text and find out how wide it is.
m.frame.Clear()
lines := WordWrap(m.text, width)
var lines []string
for _, line := range strings.Split(m.text, "\n") {
if len(line) == 0 {
lines = append(lines, "")
continue
}
lines = append(lines, WordWrap(line, width)...)
}
//lines := WordWrap(m.text, width)
for _, line := range lines {
m.frame.AddText(line, true, AlignCenter, m.textColor)
}

Loading…
Cancel
Save