Merge branch 'master' into patch-1

pull/879/head
Furkan Pehlivan 10 months ago committed by GitHub
commit 02c6d9a634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -118,6 +118,7 @@ For a presentation highlighting this package, compile and run the program found
- [tui-deck: nextcloud deck frontend](https://github.com/mebitek/tui-deck)
- [ktop: A top-like tool for your Kubernetes clusters](https://github.com/vladimirvivien/ktop)
- [blimp: UI for weather, network latency, application status, & more](https://github.com/merlinfuchs/blimp)
- [Curly - A simple TUI leveraging curl to test endpoints](https://github.com/migcaraballo/curly)
- [amtui: Alertmanager TUI](https://github.com/pehlicd/amtui)
## Documentation

@ -104,8 +104,9 @@ func (s *stepState) Style() tcell.Style {
// to start with a different style or region, you can set the state accordingly
// but you must then set [state.unisegState] to -1.
//
// You may call uniseg.HasTrailingLineBreakInString on the last non-empty
// cluster to determine if the string ends with a hard line break.
// There is no need to call uniseg.HasTrailingLineBreakInString on the last
// non-empty cluster as this function will do this for you and adjust the
// returned boundaries accordingly.
func step(str string, state *stepState, opts stepOptions) (cluster, rest string, newState *stepState) {
// Set up initial state.
if state == nil {
@ -126,6 +127,11 @@ func step(str string, state *stepState, opts stepOptions) (cluster, rest string,
preState := state.unisegState
cluster, rest, state.boundaries, state.unisegState = uniseg.StepString(str, preState)
state.grossLength = len(cluster)
if rest == "" {
if !uniseg.HasTrailingLineBreakInString(cluster) {
state.boundaries &^= uniseg.MaskLine
}
}
// Parse tags.
if opts != 0 {
@ -173,6 +179,11 @@ func step(str string, state *stepState, opts stepOptions) (cluster, rest string,
state.region = region
cluster, rest, state.boundaries, state.unisegState = uniseg.StepString(str[length:], preState)
state.grossLength = len(cluster) + length
if rest == "" {
if !uniseg.HasTrailingLineBreakInString(cluster) {
state.boundaries &^= uniseg.MaskLine
}
}
}
// Is this an escaped tag?
if escapedTagPattern.MatchString(str[length:]) {
@ -187,7 +198,13 @@ func step(str string, state *stepState, opts stepOptions) (cluster, rest string,
_, l := utf8.DecodeRuneInString(rest[length:])
cluster += rest[length : length+l]
}
cluster, _, state.boundaries, state.unisegState = uniseg.StepString(cluster, preState)
var taglessRest string
cluster, taglessRest, state.boundaries, state.unisegState = uniseg.StepString(cluster, preState)
if taglessRest == "" {
if !uniseg.HasTrailingLineBreakInString(cluster) {
state.boundaries &^= uniseg.MaskLine
}
}
}
}
}
@ -526,8 +543,7 @@ func WordWrap(text string, width int) (lines []string) {
str := text
for len(str) > 0 {
// Parse the next character.
var c string
c, str, state = step(str, state, stepOptionsStyle)
_, str, state = step(str, state, stepOptionsStyle)
cWidth := state.Width()
// Would it exceed the line width?
@ -557,7 +573,7 @@ func WordWrap(text string, width int) (lines []string) {
// Remember this split point.
lastOption = lineLength
lastOptionWidth = lineWidth
} else if str != "" || c != "" && uniseg.HasTrailingLineBreakInString(c) {
} else {
// We must split here.
lines = append(lines, strings.TrimRight(text[:lineLength], "\n\r"))
text = text[lineLength:]

@ -6,7 +6,6 @@ import (
"github.com/gdamore/tcell/v2"
colorful "github.com/lucasb-eyer/go-colorful"
"github.com/rivo/uniseg"
)
// TabSize is the number of spaces with which a tab character will be replaced.
@ -64,6 +63,9 @@ func (w TextViewWriter) HasFocus() bool {
// screen columns, but only if the text is left-aligned. If the text is centered
// or right-aligned, tab characters are simply replaced with [TabSize] spaces.
//
// Word wrapping is enabled by default. Use [TextView.SetWrap] and
// [TextView.SetWordWrap] to change this.
//
// # Navigation
//
// If the text view is set to be scrollable (which is the default), text is kept
@ -247,6 +249,7 @@ func NewTextView() *TextView {
scrollable: true,
align: AlignLeft,
wrap: true,
wordWrap: true,
textStyle: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.PrimaryTextColor),
regionTags: false,
styleTags: false,
@ -947,7 +950,7 @@ func (t *TextView) parseAhead(width int, stop func(lineNumber int, line *textVie
st := *state
lastOptionState = &st
}
} else if str != "" || c != "" && uniseg.HasTrailingLineBreakInString(c) {
} else {
// We must split here.
if stop(len(t.lineIndex)-1, lastLine) {
return

Loading…
Cancel
Save