Przeglądaj źródła

Progress bars abort on key.

Steve Thielemann 1 rok temu
rodzic
commit
fe78c2bf6a
1 zmienionych plików z 21 dodań i 1 usunięć
  1. 21 1
      testdoor/display.go

+ 21 - 1
testdoor/display.go

@@ -3,6 +3,7 @@ package main
 import (
 	"bytes"
 	"fmt"
+	"log"
 	"red-green/door"
 	"strconv"
 	"strings"
@@ -96,7 +97,9 @@ func input_demo(d *door.Door) {
 	var inputColor string = door.ColorText("BRI WHI ON BLUE")
 	var inputColor2 string = door.ColorText("BRI WHI ON GREEN")
 	var prompt door.Line = door.NewLine("What is YOUR Name: ")
+
 	prompt.RenderF = door.RenderBlueYellow
+	log.Println("BEGIN INPUT DEMO")
 	d.WriteA(prompt.Output(), inputColor)
 	var name string = d.Input(25)
 	d.WriteA(door.Reset, door.CRNL)
@@ -110,8 +113,10 @@ func input_demo(d *door.Door) {
 	d.WriteA(prompt.Output(), inputColor)
 	var color string = d.Input(15)
 	d.WriteA(door.Reset, door.CRNL)
+
 	ticker.Stop()
 	StopIt <- true
+	log.Println("END INPUT DEMO")
 	d.WriteA(fmt.Sprintf("You're %s on the %s quest, and fond of %s."+door.CRNL, name, quest, color))
 }
 
@@ -167,7 +172,22 @@ func progress_bars(d *door.Door) {
 			break
 		}
 
-		time.Sleep(time.Millisecond * 100)
+		_, ex, err := d.WaitKey(time.Millisecond * 100)
+		if err == nil {
+			if ex == door.MOUSE {
+				m, ok := d.GetMouse()
+				if ok {
+					if m.Button == 1 {
+						// end loop
+						f = 99
+					}
+				}
+			} else {
+				// end loop
+				f = 99
+			}
+		}
+		// time.Sleep(time.Millisecond * 100)
 	}
 	d.WriteA(door.ShowCursor)
 }