|
@@ -1,20 +1,27 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "bytes"
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
|
|
+ "os"
|
|
"red-green/door"
|
|
"red-green/door"
|
|
"runtime/debug"
|
|
"runtime/debug"
|
|
|
|
+ "runtime/pprof"
|
|
"time"
|
|
"time"
|
|
// "net/http"
|
|
// "net/http"
|
|
// _ "net/http/pprof"
|
|
// _ "net/http/pprof"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const ENABLE_PROFILER bool = false
|
|
|
|
+
|
|
|
|
+// "runtime/pprof"
|
|
|
|
+
|
|
// Max X value we can use before hitting MemStats panel.
|
|
// Max X value we can use before hitting MemStats panel.
|
|
var MaxX int = 0
|
|
var MaxX int = 0
|
|
|
|
|
|
func press_keys(d *door.Door) {
|
|
func press_keys(d *door.Door) {
|
|
- d.Write(door.Reset + door.CRNL + "Press some keys... <ENTER> to exit.")
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL, "Press some keys... <ENTER> to exit.")
|
|
var r rune
|
|
var r rune
|
|
var ex door.Extended
|
|
var ex door.Extended
|
|
var err error
|
|
var err error
|
|
@@ -25,24 +32,24 @@ func press_keys(d *door.Door) {
|
|
m, ok := d.GetMouse()
|
|
m, ok := d.GetMouse()
|
|
if ok {
|
|
if ok {
|
|
// var m door.MouseInfo = door.Mouse
|
|
// var m door.MouseInfo = door.Mouse
|
|
- d.Write(fmt.Sprintf("M %d (%d,%d) ", m.Button, m.X, m.Y))
|
|
|
|
|
|
+ d.WriteA(fmt.Sprintf("M %d (%d,%d) ", m.Button, m.X, m.Y))
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if ex == door.NOP {
|
|
if ex == door.NOP {
|
|
- d.Write(fmt.Sprintf("%d (%x) ", r, r))
|
|
|
|
|
|
+ d.WriteA(fmt.Sprintf("%d (%x) ", r, r))
|
|
} else {
|
|
} else {
|
|
- d.Write(fmt.Sprintf("<%s> ", ex.String()))
|
|
|
|
|
|
+ d.WriteA(fmt.Sprintf("<%s> ", ex.String()))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- d.Write(door.Reset + door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL)
|
|
}
|
|
}
|
|
|
|
|
|
func press_a_key(d *door.Door) error {
|
|
func press_a_key(d *door.Door) error {
|
|
var err error
|
|
var err error
|
|
var ex door.Extended
|
|
var ex door.Extended
|
|
|
|
|
|
- d.Write(door.Reset + door.CRNL + "Press a key, or LEFT mouse click to continue...")
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL, "Press a key, or LEFT mouse click to continue...")
|
|
for {
|
|
for {
|
|
_, ex, err = d.WaitKey(door.Inactivity)
|
|
_, ex, err = d.WaitKey(door.Inactivity)
|
|
if ex == door.MOUSE {
|
|
if ex == door.MOUSE {
|
|
@@ -56,13 +63,31 @@ func press_a_key(d *door.Door) error {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- d.Write(door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.CRNL)
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
var message string
|
|
var message string
|
|
|
|
|
|
|
|
+ if ENABLE_PROFILER {
|
|
|
|
+ fp1, err1 := os.Create("cpu.pro")
|
|
|
|
+ if err1 != nil {
|
|
|
|
+ log.Fatal(err1)
|
|
|
|
+ }
|
|
|
|
+ pprof.StartCPUProfile(fp1)
|
|
|
|
+ defer pprof.StopCPUProfile()
|
|
|
|
+
|
|
|
|
+ defer func() {
|
|
|
|
+ fp2, err2 := os.Create("memory.pro")
|
|
|
|
+ if err2 != nil {
|
|
|
|
+ log.Fatal(err2)
|
|
|
|
+ }
|
|
|
|
+ pprof.WriteHeapProfile(fp2)
|
|
|
|
+
|
|
|
|
+ }()
|
|
|
|
+ }
|
|
|
|
+
|
|
/*
|
|
/*
|
|
go func() {
|
|
go func() {
|
|
http.ListenAndServe(":6060", nil)
|
|
http.ListenAndServe(":6060", nil)
|
|
@@ -80,7 +105,7 @@ func main() {
|
|
fmt.Println("ERROR:", err)
|
|
fmt.Println("ERROR:", err)
|
|
log.Println("FAILURE:", err)
|
|
log.Println("FAILURE:", err)
|
|
// Display error to user
|
|
// Display error to user
|
|
- d.Write(fmt.Sprintf(door.Reset+door.CRNL+"Exception: %v"+door.CRNL, err))
|
|
|
|
|
|
+ d.WriteA(fmt.Sprintf(door.Reset+door.CRNL+"Exception: %v"+door.CRNL, err))
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
|
|
|
|
@@ -89,10 +114,10 @@ func main() {
|
|
// Updaters work best when the screen doesn't scroll, so start
|
|
// Updaters work best when the screen doesn't scroll, so start
|
|
// us off at the very top.
|
|
// us off at the very top.
|
|
|
|
|
|
- d.Write(door.Clrscr)
|
|
|
|
|
|
+ d.WriteA(door.Clrscr)
|
|
|
|
|
|
// Start spinrite effects
|
|
// Start spinrite effects
|
|
- var ticker *time.Ticker = time.NewTicker(time.Millisecond * time.Duration(100))
|
|
|
|
|
|
+ var ticker *time.Ticker = time.NewTicker(time.Millisecond * time.Duration(100)) // 100
|
|
|
|
|
|
var spin door.SpinRiteMsg = door.SpinRiteMsgInit(15, 5,
|
|
var spin door.SpinRiteMsg = door.SpinRiteMsgInit(15, 5,
|
|
door.ColorText("RED ON GREEN"),
|
|
door.ColorText("RED ON GREEN"),
|
|
@@ -112,25 +137,31 @@ func main() {
|
|
Title: "] GoRuntime [",
|
|
Title: "] GoRuntime [",
|
|
BorderColor: door.ColorText("BOLD YELL"),
|
|
BorderColor: door.ColorText("BOLD YELL"),
|
|
}
|
|
}
|
|
- goLineUpdater := func() string {
|
|
|
|
- status := GoRoutinesStatus()
|
|
|
|
- // log.Println(status)
|
|
|
|
- return status
|
|
|
|
- }
|
|
|
|
|
|
|
|
- var goLine door.Line = door.Line{
|
|
|
|
- UpdateF: goLineUpdater,
|
|
|
|
- Width: goPanel.Width,
|
|
|
|
- DefaultColor: door.ColorText("CYAN"),
|
|
|
|
|
|
+ const DisplayGoRoutines bool = true
|
|
|
|
+
|
|
|
|
+ if DisplayGoRoutines {
|
|
|
|
+ goLineUpdater := func(u *bytes.Buffer) {
|
|
|
|
+ u.Reset()
|
|
|
|
+ u.Write(GoRoutinesStatus())
|
|
|
|
+ // log.Println(status)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var goLine door.Line = door.Line{
|
|
|
|
+ Text: &bytes.Buffer{},
|
|
|
|
+ UpdateF: goLineUpdater,
|
|
|
|
+ Width: goPanel.Width,
|
|
|
|
+ DefaultColor: door.ColorText("CYAN"),
|
|
|
|
+ }
|
|
|
|
+ // goLine.Update() // Force Update
|
|
|
|
+ goPanel.Lines = append(goPanel.Lines, goLine)
|
|
}
|
|
}
|
|
- // goLine.Update() // Force Update
|
|
|
|
- goPanel.Lines = append(goPanel.Lines, goLine)
|
|
|
|
|
|
|
|
// Display Legend on GoRuntime panel
|
|
// Display Legend on GoRuntime panel
|
|
const DisplayGoRoutineLegend bool = false
|
|
const DisplayGoRoutineLegend bool = false
|
|
// Display Memory
|
|
// Display Memory
|
|
const DisplayMemory bool = true
|
|
const DisplayMemory bool = true
|
|
- var MemoryStats map[string]string
|
|
|
|
|
|
+ var MemoryStats map[string]*bytes.Buffer = make(map[string]*bytes.Buffer)
|
|
|
|
|
|
if DisplayGoRoutineLegend {
|
|
if DisplayGoRoutineLegend {
|
|
// Line for legend.
|
|
// Line for legend.
|
|
@@ -138,26 +169,44 @@ func main() {
|
|
}
|
|
}
|
|
|
|
|
|
if DisplayMemory {
|
|
if DisplayMemory {
|
|
- memoryUpdater := func() string {
|
|
|
|
- MemoryStats = Memory()
|
|
|
|
- return fmt.Sprintf("%-8s%8s", "Sys", MemoryStats["Sys"])
|
|
|
|
|
|
+ memoryUpdater := func(u *bytes.Buffer) {
|
|
|
|
+ if u == nil {
|
|
|
|
+ u = &bytes.Buffer{}
|
|
|
|
+ }
|
|
|
|
+ u.Reset()
|
|
|
|
+ Memory(&MemoryStats)
|
|
|
|
+ fmt.Fprintf(u, "%-8s%8s", "Sys", MemoryStats["Sys"].Bytes())
|
|
}
|
|
}
|
|
|
|
+ // memoryUpdater(&bytes.Buffer{})
|
|
|
|
+
|
|
goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: memoryUpdater,
|
|
goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: memoryUpdater,
|
|
Width: goPanel.Width,
|
|
Width: goPanel.Width,
|
|
DefaultColor: door.ColorText("BLU")})
|
|
DefaultColor: door.ColorText("BLU")})
|
|
- heapUpdater := func() string {
|
|
|
|
- return fmt.Sprintf("%-8s%8s", "HeapSys", MemoryStats["Heap"])
|
|
|
|
|
|
+ heapUpdater := func(u *bytes.Buffer) {
|
|
|
|
+ if u == nil {
|
|
|
|
+ u = &bytes.Buffer{}
|
|
|
|
+ }
|
|
|
|
+ u.Reset()
|
|
|
|
+ fmt.Fprintf(u, "%-8s%8s", "HeapSys", MemoryStats["Heap"].Bytes())
|
|
}
|
|
}
|
|
goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: heapUpdater,
|
|
goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: heapUpdater,
|
|
Width: goPanel.Width,
|
|
Width: goPanel.Width,
|
|
DefaultColor: door.ColorText("BLU")})
|
|
DefaultColor: door.ColorText("BLU")})
|
|
|
|
|
|
- stackUpdater := func() string {
|
|
|
|
- return fmt.Sprintf("%-8s%8s", "StackSys", MemoryStats["StackSys"])
|
|
|
|
|
|
+ stackUpdater := func(u *bytes.Buffer) {
|
|
|
|
+ u.Reset()
|
|
|
|
+ fmt.Fprintf(u, "%-8s%8s", "StackSys", MemoryStats["StackSys"].Bytes())
|
|
}
|
|
}
|
|
goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: stackUpdater,
|
|
goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: stackUpdater,
|
|
Width: goPanel.Width,
|
|
Width: goPanel.Width,
|
|
DefaultColor: door.ColorText("BLU")})
|
|
DefaultColor: door.ColorText("BLU")})
|
|
|
|
+ gcUpdater := func(u *bytes.Buffer) {
|
|
|
|
+ u.Reset()
|
|
|
|
+ fmt.Fprintf(u, "%-8s%8s", "NumGC", MemoryStats["NumGC"].Bytes())
|
|
|
|
+ }
|
|
|
|
+ goPanel.Lines = append(goPanel.Lines, door.Line{UpdateF: gcUpdater,
|
|
|
|
+ Width: goPanel.Width,
|
|
|
|
+ DefaultColor: door.ColorText("BLU")})
|
|
}
|
|
}
|
|
|
|
|
|
var lIndex int = 0
|
|
var lIndex int = 0
|
|
@@ -165,7 +214,14 @@ func main() {
|
|
const legendUpdate = 20
|
|
const legendUpdate = 20
|
|
|
|
|
|
go func() {
|
|
go func() {
|
|
- var output string
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ r := recover()
|
|
|
|
+ if r != nil {
|
|
|
|
+ log.Printf("** FAIL: %s, %#v\n", r, r)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ // var output string
|
|
var legend []string = []string{
|
|
var legend []string = []string{
|
|
"R=run r=Runnable",
|
|
"R=run r=Runnable",
|
|
"S=Select s=Syscall",
|
|
"S=Select s=Syscall",
|
|
@@ -175,8 +231,9 @@ func main() {
|
|
"W=Wait C=Copystk",
|
|
"W=Wait C=Copystk",
|
|
}
|
|
}
|
|
if DisplayGoRoutineLegend {
|
|
if DisplayGoRoutineLegend {
|
|
- goPanel.Lines[1].Text = legend[0]
|
|
|
|
|
|
+ goPanel.Lines[1].Text = bytes.NewBuffer([]byte(legend[0]))
|
|
}
|
|
}
|
|
|
|
+
|
|
for range ticker.C {
|
|
for range ticker.C {
|
|
// output = door.SavePos + door.Goto(door.Width-16, 1) + spin.Output() +
|
|
// output = door.SavePos + door.Goto(door.Width-16, 1) + spin.Output() +
|
|
// door.Goto(door.Width-15, 3) + spin2.Output() + door.RestorePos
|
|
// door.Goto(door.Width-15, 3) + spin2.Output() + door.RestorePos
|
|
@@ -189,7 +246,7 @@ func main() {
|
|
if lIndex == len(legend) {
|
|
if lIndex == len(legend) {
|
|
lIndex = 0
|
|
lIndex = 0
|
|
}
|
|
}
|
|
- goPanel.Lines[1].Text = legend[lIndex]
|
|
|
|
|
|
+ goPanel.Lines[1].Text = bytes.NewBuffer([]byte(legend[lIndex]))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -198,19 +255,23 @@ func main() {
|
|
}
|
|
}
|
|
|
|
|
|
goPanel.Update()
|
|
goPanel.Update()
|
|
- output = door.Goto(door.Width-16, 1) + spin.Output() + goPanel.Output()
|
|
|
|
|
|
+
|
|
|
|
+ //output = door.Goto(door.Width-16, 1) + spin.Output() + goPanel.Output()
|
|
/*
|
|
/*
|
|
+
|
|
+
|
|
door.Goto(door.Width-15, 3) + spin2.Output()
|
|
door.Goto(door.Width-15, 3) + spin2.Output()
|
|
*/
|
|
*/
|
|
|
|
|
|
if !d.Disconnect() {
|
|
if !d.Disconnect() {
|
|
- d.Update(output)
|
|
|
|
|
|
+ // d.Update(output)
|
|
|
|
+ d.WriteA(door.SavePos, door.Goto(door.Width-16, 1), spin.Output(), goPanel.Output(), door.RestorePos)
|
|
} else {
|
|
} else {
|
|
|
|
+ log.Println("Ticker.Stop: Disconnected!")
|
|
ticker.Stop()
|
|
ticker.Stop()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ log.Println("range Ticker.C stopped.")
|
|
}()
|
|
}()
|
|
|
|
|
|
var wopr door.WOPR
|
|
var wopr door.WOPR
|
|
@@ -224,12 +285,12 @@ func main() {
|
|
|
|
|
|
// bold := door.Color(1, 37, 40)
|
|
// bold := door.Color(1, 37, 40)
|
|
var bolder string = door.ColorText("BOLD YEL ON BLUE")
|
|
var bolder string = door.ColorText("BOLD YEL ON BLUE")
|
|
- d.Write("Welcome to " + bolder + "go door go TestDoor." + door.Reset + door.CRNL + "..." + door.CRNL)
|
|
|
|
|
|
+ d.WriteA("Welcome to ", bolder, "go door go TestDoor.", door.Reset, door.CRNL, "...", door.CRNL)
|
|
|
|
|
|
d.EnableMouse(door.Normal)
|
|
d.EnableMouse(door.Normal)
|
|
|
|
|
|
press_a_key(&d)
|
|
press_a_key(&d)
|
|
- d.Write(door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.CRNL)
|
|
|
|
|
|
var b []string
|
|
var b []string
|
|
if door.CP437 {
|
|
if door.CP437 {
|
|
@@ -241,14 +302,14 @@ func main() {
|
|
warningColor := door.ColorText("BRI WHI ON GREEN")
|
|
warningColor := door.ColorText("BRI WHI ON GREEN")
|
|
for _, line := range b {
|
|
for _, line := range b {
|
|
// Prevent color bleeding.
|
|
// Prevent color bleeding.
|
|
- d.Write(warningColor + line + door.Reset + door.CRNL)
|
|
|
|
|
|
+ d.WriteA(warningColor, line, door.Reset, door.CRNL)
|
|
}
|
|
}
|
|
- d.Write(door.Reset + door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL)
|
|
|
|
|
|
var left time.Duration = d.TimeLeft()
|
|
var left time.Duration = d.TimeLeft()
|
|
|
|
|
|
message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
|
|
message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
|
|
- d.Write(message)
|
|
|
|
|
|
+ d.WriteA(message)
|
|
|
|
|
|
press_a_key(&d)
|
|
press_a_key(&d)
|
|
|
|
|
|
@@ -256,9 +317,9 @@ func main() {
|
|
var choice int
|
|
var choice int
|
|
|
|
|
|
for choice >= 0 {
|
|
for choice >= 0 {
|
|
- d.Write(door.Clrscr + door.HideCursor)
|
|
|
|
|
|
+ d.WriteA(door.Clrscr, door.HideCursor)
|
|
choice = mainmenu.Choose(&d)
|
|
choice = mainmenu.Choose(&d)
|
|
- d.Write(door.ShowCursor)
|
|
|
|
|
|
+ d.WriteA(door.ShowCursor)
|
|
|
|
|
|
if choice < 0 {
|
|
if choice < 0 {
|
|
break
|
|
break
|
|
@@ -267,10 +328,10 @@ func main() {
|
|
|
|
|
|
wopr.Stop()
|
|
wopr.Stop()
|
|
// Clear WOPR panels.
|
|
// Clear WOPR panels.
|
|
- d.Write(door.Reset + wopr.Clear())
|
|
|
|
|
|
+ d.WriteA(door.Reset, wopr.Clear())
|
|
|
|
|
|
r, b := mainmenu.Panel.RightBottomPos()
|
|
r, b := mainmenu.Panel.RightBottomPos()
|
|
- d.Write(door.Goto(r, b))
|
|
|
|
|
|
+ d.WriteA(door.Goto(r, b))
|
|
// fmt.Printf("Choice: %d, Option: %c\n", choice, option)
|
|
// fmt.Printf("Choice: %d, Option: %c\n", choice, option)
|
|
|
|
|
|
switch option {
|
|
switch option {
|
|
@@ -284,12 +345,12 @@ func main() {
|
|
font_demo(&d)
|
|
font_demo(&d)
|
|
press_a_key(&d)
|
|
press_a_key(&d)
|
|
case 'I':
|
|
case 'I':
|
|
- d.Write(door.Reset + door.CRNL + door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL, door.CRNL)
|
|
input_demo(&d)
|
|
input_demo(&d)
|
|
press_a_key(&d)
|
|
press_a_key(&d)
|
|
case 'M':
|
|
case 'M':
|
|
// Why is this so far down on the screen? (Scrolls)
|
|
// Why is this so far down on the screen? (Scrolls)
|
|
- d.Write(door.Reset + door.CRNL + "TO DO: Provide menu of options to select from..." + door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL, "TO DO: Provide menu of options to select from...", door.CRNL)
|
|
press_a_key(&d)
|
|
press_a_key(&d)
|
|
case 'P':
|
|
case 'P':
|
|
progress_bars(&d)
|
|
progress_bars(&d)
|
|
@@ -320,7 +381,7 @@ func main() {
|
|
// d.Write("\x1b[?1000l") // disable mouse
|
|
// d.Write("\x1b[?1000l") // disable mouse
|
|
// d.Write("\x1b[?1002l")
|
|
// d.Write("\x1b[?1002l")
|
|
d.DisableMouse()
|
|
d.DisableMouse()
|
|
- d.Write(door.Reset + door.CRNL)
|
|
|
|
|
|
+ d.WriteA(door.Reset, door.CRNL)
|
|
|
|
|
|
if d.Config.BBSID != "" {
|
|
if d.Config.BBSID != "" {
|
|
message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
|
|
message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
|
|
@@ -328,7 +389,7 @@ func main() {
|
|
message = "Returning to the BBS..." + door.CRNL
|
|
message = "Returning to the BBS..." + door.CRNL
|
|
}
|
|
}
|
|
|
|
|
|
- d.Write(message)
|
|
|
|
|
|
+ d.WriteA(message)
|
|
|
|
|
|
d.WaitKey(time.Second)
|
|
d.WaitKey(time.Second)
|
|
left = d.TimeLeft()
|
|
left = d.TimeLeft()
|
|
@@ -336,10 +397,10 @@ func main() {
|
|
ticker.Stop()
|
|
ticker.Stop()
|
|
|
|
|
|
message = fmt.Sprintf("You had %0.2f minutes remaining!"+door.CRNL, left.Minutes())
|
|
message = fmt.Sprintf("You had %0.2f minutes remaining!"+door.CRNL, left.Minutes())
|
|
- d.Write(message)
|
|
|
|
|
|
+ d.WriteA(message)
|
|
|
|
|
|
left = d.TimeUsed()
|
|
left = d.TimeUsed()
|
|
- d.Write(fmt.Sprintf("You used %0.2f seconds / %0.2f minutes."+door.CRNL, left.Seconds(), left.Minutes()))
|
|
|
|
|
|
+ d.WriteA(fmt.Sprintf("You used %0.2f seconds / %0.2f minutes."+door.CRNL, left.Seconds(), left.Minutes()))
|
|
|
|
|
|
fmt.Println("Ending testdoor.go")
|
|
fmt.Println("Ending testdoor.go")
|
|
}
|
|
}
|