forked from tslocum/cview
parent
9c3564dc42
commit
298510a685
4
modal.go
4
modal.go
|
@ -209,9 +209,9 @@ func (m *Modal) Draw(screen tcell.Screen) {
|
|||
|
||||
// Reset the text and find out how wide it is.
|
||||
m.frame.Clear()
|
||||
lines := WordWrap([]byte(m.text), width)
|
||||
lines := WordWrap(m.text, width)
|
||||
for _, line := range lines {
|
||||
m.frame.AddText(string(line), true, AlignCenter, m.textColor)
|
||||
m.frame.AddText(line, true, AlignCenter, m.textColor)
|
||||
}
|
||||
|
||||
// Set the Modal's position and size.
|
||||
|
|
8
util.go
8
util.go
|
@ -469,8 +469,8 @@ func TaggedStringWidth(text string) int {
|
|||
// This function considers color tags to have no width.
|
||||
//
|
||||
// Text is always split at newline characters ('\n').
|
||||
func WordWrap(text []byte, width int) (lines [][]byte) {
|
||||
colorTagIndices, _, _, _, escapeIndices, strippedText, _ := decomposeText(text, true, false)
|
||||
func WordWrap(text string, width int) (lines []string) {
|
||||
colorTagIndices, _, _, _, escapeIndices, strippedText, _ := decomposeText([]byte(text), true, false)
|
||||
|
||||
// Find candidate breakpoints.
|
||||
breakpoints := boundaryPattern.FindAllSubmatchIndex(strippedText, -1)
|
||||
|
@ -485,12 +485,12 @@ func WordWrap(text []byte, width int) (lines [][]byte) {
|
|||
lineWidth, overflow int
|
||||
forceBreak bool
|
||||
)
|
||||
unescape := func(substr []byte, startIndex int) []byte {
|
||||
unescape := func(substr string, startIndex int) string {
|
||||
// A helper function to unescape escaped tags.
|
||||
for index := escapePos; index >= 0; index-- {
|
||||
if index < len(escapeIndices) && startIndex > escapeIndices[index][0] && startIndex < escapeIndices[index][1]-1 {
|
||||
pos := escapeIndices[index][1] - 2 - startIndex
|
||||
return append(substr[:pos], substr[pos+1:]...)
|
||||
return substr[:pos] + substr[pos+1:]
|
||||
}
|
||||
}
|
||||
return substr
|
||||
|
|
Loading…
Reference in New Issue