gizak / termui

Golang terminal dashboard
MIT License
13.16k stars 788 forks source link

A example of autoscrolling for line wrapping scene #325

Open 7yyo opened 1 year ago

7yyo commented 1 year ago
x := list.Size().X
text := splitByNChars(s, x-2)
for _, t := range text {
    list = append(list, t)
    list.ScrollDown()
}
ui.Render(w.L)
func splitByNChars(s string, n int) []string {
    var result []string
    for i := 0; i < len(s); i += n {
        end := i + n
        if end > len(s) {
            end = len(s)
        }
        result = append(result, s[i:end])
    }
    return result
}