aboutsummaryrefslogtreecommitdiff
path: root/utils/ncfmt
diff options
context:
space:
mode:
Diffstat (limited to 'utils/ncfmt')
-rw-r--r--utils/ncfmt/effects.go54
-rw-r--r--utils/ncfmt/incremental_print.go30
2 files changed, 84 insertions, 0 deletions
diff --git a/utils/ncfmt/effects.go b/utils/ncfmt/effects.go
new file mode 100644
index 0000000..170ed11
--- /dev/null
+++ b/utils/ncfmt/effects.go
@@ -0,0 +1,54 @@
+package ncfmt
+
+import (
+ "fmt"
+ "time"
+
+ . "github.com/gbin/goncurses"
+)
+
+func BlinkCursorUntilInput(scr *Window, pos_y int, pos_x int, interval time.Duration) Key {
+ scr.Move(pos_y, pos_x)
+ var activation_key Key
+ for {
+ Cursor(2)
+ scr.Timeout(int((interval / 3).Milliseconds()))
+ activation_key = scr.GetChar()
+ if activation_key != 0 {
+ break
+ }
+ time.Sleep(interval / 3)
+ Cursor(0)
+ time.Sleep(interval / 3)
+ }
+ return activation_key
+}
+func BlinkCursorUntilDone(scr *Window, pos_y int, pos_x int, interval time.Duration, done <-chan bool) {
+ scr.Move(pos_y, pos_x)
+ for {
+ Cursor(2)
+ select {
+ case is_done, ok := <-done:
+ if ok && is_done {
+ return
+ } else {
+ fmt.Println("Channel closed?")
+ }
+ default:
+ time.Sleep(interval / 2)
+ Cursor(0)
+ time.Sleep(interval / 2)
+
+ }
+ }
+}
+func BlinkCursorWithTime(scr *Window, pos_y int, pos_x int, duration time.Duration, interval time.Duration) {
+ scr.Move(pos_y, pos_x)
+ n := duration / interval
+ for i := 0; i < int(n); i++ {
+ Cursor(2)
+ time.Sleep(interval / 2)
+ Cursor(0)
+ time.Sleep(interval / 2)
+ }
+}
diff --git a/utils/ncfmt/incremental_print.go b/utils/ncfmt/incremental_print.go
new file mode 100644
index 0000000..8ab0f05
--- /dev/null
+++ b/utils/ncfmt/incremental_print.go
@@ -0,0 +1,30 @@
+package ncfmt
+
+import (
+ "time"
+
+ . "github.com/gbin/goncurses"
+)
+
+func IncrementalPrintMany(
+ w *Window,
+ y int,
+ x int,
+ texts []string,
+ duration time.Duration,
+) {
+ for i := 0; i < len(texts); i++ {
+ IncrementalPrint(w, texts[i], y+i, x, int(1*time.Second))
+ }
+}
+func IncrementalPrint(scr *Window, text string, from_y int, from_x int, interval_millis int) {
+ for i := 0; i < len(text); i++ {
+ ch := string([]rune(text)[i])
+ _, mx := scr.MaxYX()
+ cy := i/mx + from_y
+ cx := i%mx + 1
+ scr.MovePrint(cy, cx, ch)
+ time.Sleep(time.Duration(1000/len(text)) * time.Millisecond)
+ scr.Refresh()
+ }
+}