|
|
|
@ -277,12 +277,12 @@ func decomposeText(text []byte, findColors, findRegions bool) (colorIndices [][]
@@ -277,12 +277,12 @@ func decomposeText(text []byte, findColors, findRegions bool) (colorIndices [][]
|
|
|
|
|
// Returns the number of actual bytes of the text printed (including color tags)
|
|
|
|
|
// and the actual width used for the printed runes.
|
|
|
|
|
func Print(screen tcell.Screen, text []byte, x, y, maxWidth, align int, color tcell.Color) (int, int) { |
|
|
|
|
return printWithStyle(screen, text, x, y, maxWidth, align, tcell.StyleDefault.Foreground(color)) |
|
|
|
|
return PrintStyle(screen, text, x, y, maxWidth, align, tcell.StyleDefault.Foreground(color)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// printWithStyle works like Print() but it takes a style instead of just a
|
|
|
|
|
// PrintStyle works like Print() but it takes a style instead of just a
|
|
|
|
|
// foreground color.
|
|
|
|
|
func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, style tcell.Style) (int, int) { |
|
|
|
|
func PrintStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int, style tcell.Style) (int, int) { |
|
|
|
|
if maxWidth <= 0 || len(text) == 0 { |
|
|
|
|
return 0, 0 |
|
|
|
|
} |
|
|
|
@ -294,7 +294,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
@@ -294,7 +294,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
|
|
|
|
|
if align == AlignRight { |
|
|
|
|
if strippedWidth <= maxWidth { |
|
|
|
|
// There's enough space for the entire text.
|
|
|
|
|
return printWithStyle(screen, text, x+maxWidth-strippedWidth, y, maxWidth, AlignLeft, style) |
|
|
|
|
return PrintStyle(screen, text, x+maxWidth-strippedWidth, y, maxWidth, AlignLeft, style) |
|
|
|
|
} |
|
|
|
|
// Trim characters off the beginning.
|
|
|
|
|
var ( |
|
|
|
@ -322,7 +322,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
@@ -322,7 +322,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
|
|
|
|
|
text = append(text[:escapeCharPos], text[escapeCharPos+1:]...) |
|
|
|
|
} |
|
|
|
|
// Print and return.
|
|
|
|
|
bytes, width = printWithStyle(screen, text[textPos+tagOffset:], x, y, maxWidth, AlignLeft, style) |
|
|
|
|
bytes, width = PrintStyle(screen, text[textPos+tagOffset:], x, y, maxWidth, AlignLeft, style) |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
@ -331,11 +331,11 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
@@ -331,11 +331,11 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
|
|
|
|
|
} else if align == AlignCenter { |
|
|
|
|
if strippedWidth == maxWidth { |
|
|
|
|
// Use the exact space.
|
|
|
|
|
return printWithStyle(screen, text, x, y, maxWidth, AlignLeft, style) |
|
|
|
|
return PrintStyle(screen, text, x, y, maxWidth, AlignLeft, style) |
|
|
|
|
} else if strippedWidth < maxWidth { |
|
|
|
|
// We have more space than we need.
|
|
|
|
|
half := (maxWidth - strippedWidth) / 2 |
|
|
|
|
return printWithStyle(screen, text, x+half, y, maxWidth-half, AlignLeft, style) |
|
|
|
|
return PrintStyle(screen, text, x+half, y, maxWidth-half, AlignLeft, style) |
|
|
|
|
} else { |
|
|
|
|
// Chop off runes until we have a perfect fit.
|
|
|
|
|
var choppedLeft, choppedRight, leftIndex, rightIndex int |
|
|
|
@ -390,7 +390,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
@@ -390,7 +390,7 @@ func printWithStyle(screen tcell.Screen, text []byte, x, y, maxWidth, align int,
|
|
|
|
|
escapePos++ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return printWithStyle(screen, text[leftIndex+tagOffset:], x, y, maxWidth, AlignLeft, style) |
|
|
|
|
return PrintStyle(screen, text[leftIndex+tagOffset:], x, y, maxWidth, AlignLeft, style) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|