Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#325·termui

A example of autoscrolling for line wrapping scene

Author: 7yyoCreated Jun 17, 2023Updated Jun 17, 2023
go
x := list.Size().X
text := splitByNChars(s, x-2)
for _, t := range text {
	list = append(list, t)
	list.ScrollDown()
}
ui.Render(w.L)
go
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
}

Source: gizak/termui

View original on GitHubView discussion on GitHub