1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
package main
import (
"fmt"
"math/rand"
"time"
"atomicgo.dev/cursor"
)
func main() {
fmt.Println("Multiline cursor area demo")
fmt.Println("--------------------------")
area := cursor.NewArea()
header := "This is a multiline demo\nwith 2 lines:\n"
area.Update(header)
content := header
for i := 1; i < 6; i++ {
if i%2 == 0 {
content += fmt.Sprintf(" + %d\n", i)
} else {
content += fmt.Sprintf(" - line: %d", i)
}
time.Sleep(1 * time.Second)
area.Update(content)
}
time.Sleep(1 * time.Second)
area.Update("Test varying area sizes now")
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(1, 2))
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(2, 9))
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(3, 5))
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(4, 0))
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(5, 6))
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(6, 1))
time.Sleep(500 * time.Millisecond)
area.Update(buildContent(7, 3))
time.Sleep(1 * time.Second)
fmt.Println("\n--- DONE")
}
func buildContent(idx int, n int) string {
content := fmt.Sprintf(">>> START OF CONTENT %d/%d <<<\n", idx, n)
for i := 0; i < n; i++ {
for i := 0; i < 5; i++ {
content += words[rand.Intn(len(words))] + " "
}
content += "\n"
}
return content
}
var words = []string{
"ball", "summer", "hint", "mountain", "island", "onion", "world",
"run", "hit", "fly", "swim", "crawl", "build", "dive", "jump",
"crazy", "funny", "strange", "yellow", "red", "blue", "green", "white",
}
|