2 Commits 6b631d28ba ... 1e7c854ac7

Autor SHA1 Mensagem Data
  Bugz 1e7c854ac7 Remove goroutine legend. Add memory. 1 ano atrás
  Bugz 614462537a Abort NoMoreSecrets on key/left mouse click. 1 ano atrás
4 arquivos alterados com 97 adições e 48 exclusões
  1. 26 22
      door/nomoresecrets.go
  2. 1 1
      door/wopr.go
  3. 1 1
      testdoor/runtime-info.go
  4. 69 24
      testdoor/testdoor.go

+ 26 - 22
door/nomoresecrets.go

@@ -63,6 +63,28 @@ func nonRandom() byte {
 	return rb
 }
 
+// NoMoreSecrets Sleep
+//
+//	This allows the user to abort the effect with a key or left mouse click.
+func NMSSleep(Door *Door, sleep time.Duration) bool {
+	_, ex, err := Door.WaitKey(sleep)
+	if err == nil {
+		if ex == MOUSE {
+			m, ok := Door.GetMouse()
+			if ok {
+				if m.Button == 1 {
+					log.Println("NoMore")
+					return true
+				}
+			}
+			return false
+		}
+		log.Println("NoMore")
+		return true
+	}
+	return false
+}
+
 /*
 NoMoreSecrets - render output as random, then fade in the original text.
 
@@ -260,12 +282,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Jumble_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-				break
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Jumble_Loop_Speed))
 		}
 
 		for {
@@ -318,11 +335,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Reveal_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Reveal_Loop_Speed))
 
 			if revealed {
 				break
@@ -465,12 +478,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Jumble_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-				break
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Jumble_Loop_Speed))
 		}
 
 		for {
@@ -514,11 +522,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Reveal_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Reveal_Loop_Speed))
 			if revealed {
 				break
 			}

+ 1 - 1
door/wopr.go

@@ -178,7 +178,7 @@ func (w *WOPR) Animate(d *Door) {
 		// time.Sleep(time.Second - time.Duration(til)) // sec16 - (til % sec16))) //int64(time.Second) - til)) // time.Now().UnixMilli()%1000) * time.Millisecond)
 
 		// time.Second / 16
-		w.Ticker = time.NewTicker(time.Duration(sec16)) // time.Microsecond * time.Duration(62500))
+		w.Ticker = time.NewTicker(time.Duration(sec16))
 
 		var output string
 

+ 1 - 1
testdoor/runtime-info.go

@@ -28,7 +28,7 @@ func GoRoutinesStatus() string {
 		"sleep":        "S",
 		"select":       "s", // missing
 		"chan receive": "<", // missing
-		"chan send":    ">",
+		"chan send":    ">", // missing
 	}
 	// 2K works, we don't have to grow any more.
 	if buffer == nil {

+ 69 - 24
testdoor/testdoor.go

@@ -115,6 +115,7 @@ func about_test_door(d *door.Door) {
 	door.NoMoreSecrets(about.Output(), d, &better)
 }
 
+// Build door.Menu (Main menu)
 func MainMenu() door.Menu {
 	// Make the main menu
 	// Width was 45
@@ -138,7 +139,7 @@ func MainMenu() door.Menu {
 	// m.AddSelection("C", "Crash")
 	menu.AddSelection("D", "Display Information")
 	menu.AddSelection("F", "Font Demo")
-	menu.AddSelection("I", "Input Prompt Demo")
+	menu.AddSelection("I", "Input Demo")
 	menu.AddSelection("M", "Menu Demo")
 	menu.AddSelection("P", "Progress Bars Demo")
 	menu.AddSelection("S", "Show Panel")
@@ -630,6 +631,7 @@ type TrackPanels struct {
 	BColor string
 }
 
+// Find the Panel that was mouse clicked.
 func FindPanel(m door.Mouse, panels []TrackPanels) int {
 	for idx, p := range panels {
 		hit, _, _ := p.Panel.Within(int(m.X), int(m.Y))
@@ -837,17 +839,18 @@ func main() {
 		door.ColorText("RED ON GREEN"),
 		[]string{"RED", "GREEN", "SOFTWARE"})
 
-	var spin2 door.SpinRite = door.SpinRiteInit(13, 5,
-		door.ColorText("BRI CYA ON BLUE"))
-
+	/*
+		var spin2 door.SpinRite = door.SpinRiteInit(13, 5,
+			door.ColorText("BRI CYA ON BLUE"))
+	*/
 	// Add in the GoRoutine Status panel
 
-	var goPanel door.Panel = door.Panel{X: 0,
-		Y:           1,
-		Width:       18,
+	var goPanel door.Panel = door.Panel{X: door.Width - 19,
+		Y:           3,
+		Width:       16,
 		Style:       door.DOUBLE,
-		Title:       "] GoRoutines [",
-		BorderColor: door.ColorText("BOLD YEL ON BLU"),
+		Title:       "] GoRuntime [",
+		BorderColor: door.ColorText("BOLD YELL"),
 	}
 	goLineUpdater := func() string {
 		status := GoRoutinesStatus()
@@ -856,12 +859,47 @@ func main() {
 	}
 
 	var goLine door.Line = door.Line{
-		UpdateF: goLineUpdater,
-		Width:   goPanel.Width,
+		UpdateF:      goLineUpdater,
+		Width:        goPanel.Width,
+		DefaultColor: door.ColorText("CYAN"),
 	}
 	// goLine.Update() // Force Update
 	goPanel.Lines = append(goPanel.Lines, goLine)
-	goPanel.Lines = append(goPanel.Lines, door.Line{Width: goPanel.Width})
+
+	// Display Legend on GoRuntime panel
+	const DisplayGoRoutineLegend bool = false
+	// Display Memory
+	const DisplayMemory bool = true
+	var MemoryStats map[string]string
+
+	if DisplayGoRoutineLegend {
+		// Line for legend.
+		goPanel.Lines = append(goPanel.Lines, door.Line{Width: goPanel.Width})
+	}
+
+	if DisplayMemory {
+		memoryUpdater := func() string {
+			MemoryStats = Memory()
+			return fmt.Sprintf("%-8s%8s", "Sys", MemoryStats["Sys"])
+		}
+		goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: memoryUpdater,
+			Width:        goPanel.Width,
+			DefaultColor: door.ColorText("BLU")})
+		heapUpdater := func() string {
+			return fmt.Sprintf("%-8s%8s", "HeapSys", MemoryStats["Heap"])
+		}
+		goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: heapUpdater,
+			Width:        goPanel.Width,
+			DefaultColor: door.ColorText("BLU")})
+
+		stackUpdater := func() string {
+			return fmt.Sprintf("%-8s%8s", "StackSys", MemoryStats["StackSys"])
+		}
+		goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: stackUpdater,
+			Width:        goPanel.Width,
+			DefaultColor: door.ColorText("BLU")})
+	}
+
 	var lIndex int = 0
 	var legendCount int = 0
 	const legendUpdate = 20
@@ -876,20 +914,23 @@ func main() {
 			"I=Idle D=Dead",
 			"W=Wait C=Copystk",
 		}
-		goPanel.Lines[1].Text = legend[0]
-
+		if DisplayGoRoutineLegend {
+			goPanel.Lines[1].Text = legend[0]
+		}
 		for range ticker.C {
 			// output = door.SavePos + door.Goto(door.Width-16, 1) + spin.Output() +
 			//	door.Goto(door.Width-15, 3) + spin2.Output() + door.RestorePos
 
-			legendCount++
-			if legendCount >= legendUpdate {
-				legendCount = 0
-				lIndex++
-				if lIndex == len(legend) {
-					lIndex = 0
+			if DisplayGoRoutineLegend {
+				legendCount++
+				if legendCount >= legendUpdate {
+					legendCount = 0
+					lIndex++
+					if lIndex == len(legend) {
+						lIndex = 0
+					}
+					goPanel.Lines[1].Text = legend[lIndex]
 				}
-				goPanel.Lines[1].Text = legend[lIndex]
 			}
 
 			if goPanel.X == 0 {
@@ -897,8 +938,12 @@ func main() {
 			}
 
 			goPanel.Update()
-			output = door.Goto(door.Width-16, 1) + spin.Output() +
-				door.Goto(door.Width-15, 3) + spin2.Output() + goPanel.Output()
+			output = door.Goto(door.Width-16, 1) + spin.Output() + goPanel.Output()
+			/*
+				    +
+					door.Goto(door.Width-15, 3) + spin2.Output()
+			*/
+
 			if !d.Disconnect() {
 				d.Update(output)
 			} else {
@@ -909,7 +954,7 @@ func main() {
 	}()
 
 	var wopr door.WOPR
-	wopr.Init(d.StartTime, d.TimeOut, "") // TimeUsed(), d.TimeLeft(), "")
+	wopr.Init(d.StartTime, d.TimeOut, "")
 	wopr.ElapsedPanel.X = door.Width - 19
 	wopr.ElapsedPanel.Y = door.Height - 15
 	wopr.RemainingPanel.X = door.Width - 19