|
@@ -3,6 +3,7 @@ package main
|
|
|
import (
|
|
|
"fmt"
|
|
|
"red-green/door"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -12,98 +13,31 @@ func pctUpdate(pct *int64) func() int64 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func press_a_key(d *door.Door) {
|
|
|
+// Can I add a function to Door?
|
|
|
+// NO: cannot define new methods on non-local type door.Door
|
|
|
+
|
|
|
+/*
|
|
|
+func (d *door.Door) PressAKey() {
|
|
|
d.Write(door.Reset + door.CRNL + "Press a key to continue...")
|
|
|
d.Key()
|
|
|
d.Write(door.CRNL)
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
-func main() {
|
|
|
- fmt.Println("Starting testdoor.go")
|
|
|
- d := door.Door{}
|
|
|
-
|
|
|
- d.Init()
|
|
|
- reset := door.Reset
|
|
|
- bold := door.Color(1, 37, 40)
|
|
|
- bolder := door.ColorText("BLI BOLD YEL ON BLUE")
|
|
|
- d.Write("Welcome to " + bolder + "door32.sys" + reset + door.CRNL + "..." + door.CRNL)
|
|
|
- key := d.Key()
|
|
|
- message := fmt.Sprintf("Key %s%d / %x%s"+door.CRNL, bold, key, key, reset)
|
|
|
- d.Write(message)
|
|
|
- b := door.Box{20, 1}
|
|
|
- d.Write(b.Top() + door.CRNL)
|
|
|
- // or %-20s
|
|
|
- message = fmt.Sprintf("%20s", "SHAZAM!")
|
|
|
-
|
|
|
- d.Write(b.Row(message) + door.CRNL)
|
|
|
- d.Write(b.Middle() + door.CRNL)
|
|
|
- d.Write(b.Row(fmt.Sprintf("%-20s", "Meow?")) + door.CRNL)
|
|
|
- d.Write(b.Bottom() + door.CRNL)
|
|
|
-
|
|
|
- left := d.TimeLeft()
|
|
|
-
|
|
|
- message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
|
|
|
- d.Write(message)
|
|
|
-
|
|
|
- inputColor := door.ColorText("BRI WHI ON BLUE")
|
|
|
-
|
|
|
- prompt := door.Line{Text: "What is YOUR Name: "}
|
|
|
- prompt.RenderF = door.RenderBlueYellow
|
|
|
- d.Write(prompt.Output() + inputColor)
|
|
|
- // d.Write("What is your name: " + inputColor)
|
|
|
- name := d.Input(25)
|
|
|
- d.Write(door.Reset + door.CRNL)
|
|
|
-
|
|
|
- if false {
|
|
|
- bar := door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
|
|
|
-
|
|
|
- bar2 := door.BarLine{Width: 30, Style: door.PERCENT_SPACE}
|
|
|
-
|
|
|
- bar2.ColorRange = []door.BarRange{
|
|
|
- {2500, door.ColorText("RED")},
|
|
|
- {5000, door.ColorText("BROWN")},
|
|
|
- {7500, door.ColorText("BOLD YEL")},
|
|
|
- {9500, door.ColorText("GREEN")},
|
|
|
- {10100, door.ColorText("BRI GRE")}}
|
|
|
-
|
|
|
- bar3 := door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
|
|
|
-
|
|
|
- var percentage int64
|
|
|
- bar.UpdateP = pctUpdate(&percentage)
|
|
|
- bar2.UpdateP = pctUpdate(&percentage)
|
|
|
- bar3.UpdateP = pctUpdate(&percentage)
|
|
|
-
|
|
|
- bar_start := door.Goto(3, 15)
|
|
|
-
|
|
|
- for f := 0; f <= 100; f++ {
|
|
|
- percentage = int64(f * 100)
|
|
|
- d.Write(bar_start)
|
|
|
- bar.Update()
|
|
|
- d.Write(bar.Output())
|
|
|
- d.Write(" " + door.Reset)
|
|
|
- bar2.Update()
|
|
|
- d.Write(bar2.Output())
|
|
|
- d.Write(door.Reset + " ")
|
|
|
- bar3.Update()
|
|
|
- d.Write(bar3.Output())
|
|
|
-
|
|
|
- if d.Disconnected {
|
|
|
- break
|
|
|
- }
|
|
|
-
|
|
|
- time.Sleep(time.Millisecond * 100)
|
|
|
- // d.WaitKey(0, 55000)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- press_a_key(&d)
|
|
|
+func press_a_key(d *door.Door) int {
|
|
|
+ d.Write(door.Reset + door.CRNL + "Press a key to continue...")
|
|
|
+ k := d.Key()
|
|
|
+ d.Write(door.CRNL)
|
|
|
+ return k
|
|
|
+}
|
|
|
|
|
|
- m := door.Menu{Panel: door.Panel{Width: 25,
|
|
|
+func MainMenu() door.Menu {
|
|
|
+ // Make the main menu
|
|
|
+ m := door.Menu{Panel: door.Panel{Width: 45,
|
|
|
X: 5,
|
|
|
Y: 5,
|
|
|
Style: door.DOUBLE,
|
|
|
- Title: "Please Select:",
|
|
|
+ Title: "[ Main Menu: ]",
|
|
|
TitleOffset: 3,
|
|
|
BorderColor: door.ColorText("BRI CYAN ON BLA")}}
|
|
|
m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
|
|
@@ -114,32 +48,36 @@ func main() {
|
|
|
door.ColorText("BOLD WHI ON BLUE"),
|
|
|
door.ColorText("BOLD YEL ON BLUE"),
|
|
|
door.ColorText("BOLD CYAN ON BLUE"))
|
|
|
- m.AddSelection("1", "Play A Game")
|
|
|
- m.AddSelection("A", "Ask BUGZ for Help")
|
|
|
- m.AddSelection("D", "Drop to DOS")
|
|
|
+
|
|
|
+ m.AddSelection("A", "ANSI Display")
|
|
|
+ m.AddSelection("D", "Display Information (dropfile, screen)")
|
|
|
+ m.AddSelection("I", "Input Prompt Demo")
|
|
|
+ m.AddSelection("P", "Progress Bars Demo")
|
|
|
+
|
|
|
m.AddSelection("Q", "Quit")
|
|
|
- /*
|
|
|
- m.MenuOptions = []door.MenuOption{{rune('1'), "Play A Game"},
|
|
|
- {rune('A'), "Ask BUGZ for Help"},
|
|
|
- {rune('D'), "Drop to DOS"},
|
|
|
- {rune('Q'), "Quit"}}
|
|
|
- m.Build()
|
|
|
- */
|
|
|
-
|
|
|
- // Yes, the render functions are working
|
|
|
- /*
|
|
|
- test := door.Line{Text: "[T] Testing Render...", RenderF: m.SelectedR}
|
|
|
- d.Write(test.Output() + door.Reset + door.CRNL)
|
|
|
- test.RenderF = m.UnselectedR
|
|
|
- d.Write(test.Output() + door.Reset + door.CRNL)
|
|
|
- d.Write(door.Reset + door.CRNL + "Press a key to continue...")
|
|
|
- d.Key()
|
|
|
- */
|
|
|
+ return m
|
|
|
+}
|
|
|
|
|
|
+func display_information(d *door.Door) {
|
|
|
d.Write(door.Clrscr)
|
|
|
|
|
|
- item := m.Choose(&d)
|
|
|
+ keyColor := door.ColorText("BRI GREEN")
|
|
|
+ sepColor := door.ColorText("BRI YEL")
|
|
|
+ valColor := door.ColorText("CYAN")
|
|
|
+ nice_format := func(key string, value string) string {
|
|
|
+ return fmt.Sprintf("%s%-20s %s: %s%s", keyColor, key, sepColor, valColor, value) + door.CRNL
|
|
|
+ }
|
|
|
+
|
|
|
+ d.Write(nice_format("BBS Software", d.Config.BBSID))
|
|
|
+ d.Write(nice_format("Real Name", d.Config.Real_name))
|
|
|
+ d.Write(nice_format("Handle", d.Config.Handle))
|
|
|
+ d.Write(nice_format("Node #", strconv.Itoa(d.Config.Node)))
|
|
|
+ d.Write(nice_format("Unicode", strconv.FormatBool(door.Unicode)))
|
|
|
+ d.Write(nice_format("CP437", strconv.FormatBool(door.CP437)))
|
|
|
+ d.Write(nice_format("Screen Size", fmt.Sprintf("%d X %d", door.Width, door.Height)))
|
|
|
+}
|
|
|
|
|
|
+func display_ansi(d *door.Door) {
|
|
|
SPACE := [...]string{
|
|
|
"\x1b[?7h\x1b[255D\x1b[0;1;32m\xdc\x1b[42m\xb2\xb2\xb2\xb2\xdb\x1b[40m\xdc \x1b[42m\xb1\xb1\xb2\xb2\xdb\xdb\x1b[4C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b[11C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b[40m",
|
|
|
"\x1b[42m\xb1\xb1\x1b[4C\xdb\x1b[2C\xb1\xb1\x1b[2C\xdb\xdb\x1b[2C\xb0\xb1\x1b[2C\xb2\xdb\x1b[2C\xb0\xb1\x1b[3C\xdb\xdb\x1b[1C\xb0\xb1\x1b[3C\xdb\xdb\x1b[9C\xb0\xb1\x1b[2C\xb2\xdb\x1b[2C\xb0\xb1\x1b[3C\xdb\xdb\x1b[1C\xb0\xb1\x1b[3C\xdb\xdb\x1b[40m",
|
|
@@ -161,17 +99,138 @@ func main() {
|
|
|
d.Write(line + door.CRNL)
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+func input_demo(d *door.Door) {
|
|
|
+ inputColor := door.ColorText("BRI WHI ON BLUE")
|
|
|
+ inputColor2 := door.ColorText("BRI WHI ON GREEN")
|
|
|
+ prompt := door.Line{Text: "What is YOUR Name: "}
|
|
|
+ prompt.RenderF = door.RenderBlueYellow
|
|
|
+ d.Write(prompt.Output() + inputColor)
|
|
|
+ name := d.Input(25)
|
|
|
+ d.Write(door.Reset + door.CRNL)
|
|
|
+ prompt.Text = "What is Your Quest: "
|
|
|
+ d.Write(prompt.Output() + inputColor2)
|
|
|
+ quest := d.Input(35)
|
|
|
+ d.Write(door.Reset + door.CRNL)
|
|
|
+ prompt.Text = "What is your Favorite CoLoR: "
|
|
|
+ d.Write(prompt.Output() + inputColor2)
|
|
|
+ color := d.Input(15)
|
|
|
+ d.Write(door.Reset + door.CRNL)
|
|
|
+ d.Write(fmt.Sprintf("You're %s on the %s quest, and fond of %s."+door.CRNL, name, quest, color))
|
|
|
+}
|
|
|
+
|
|
|
+func progress_bars(d *door.Door) {
|
|
|
+ d.Write(door.Clrscr)
|
|
|
+
|
|
|
+ bar := door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
|
|
|
+ bar2 := door.BarLine{Width: 30, Style: door.PERCENT_SPACE}
|
|
|
+
|
|
|
+ bar2.ColorRange = []door.BarRange{
|
|
|
+ {2500, door.ColorText("RED")},
|
|
|
+ {5000, door.ColorText("BROWN")},
|
|
|
+ {7500, door.ColorText("BOLD YEL")},
|
|
|
+ {9500, door.ColorText("GREEN")},
|
|
|
+ {10100, door.ColorText("BRI GRE")}}
|
|
|
+
|
|
|
+ bar3 := door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
|
|
|
+
|
|
|
+ var percentage int64
|
|
|
+ bar.UpdateP = pctUpdate(&percentage)
|
|
|
+ bar2.UpdateP = pctUpdate(&percentage)
|
|
|
+ bar3.UpdateP = pctUpdate(&percentage)
|
|
|
+
|
|
|
+ d.Write(door.Reset + "Half-Step, Percentage with space and Color Range, Gradient..." + door.CRNL)
|
|
|
+
|
|
|
+ bar_start := door.Goto(3, 15)
|
|
|
+
|
|
|
+ for f := 0; f <= 100; f++ {
|
|
|
+ percentage = int64(f * 100)
|
|
|
+
|
|
|
+ bar.Update()
|
|
|
+ bar2.Update()
|
|
|
+ bar3.Update()
|
|
|
+
|
|
|
+ d.Write(bar_start + bar.Output() + " " + door.Reset + bar2.Output() + door.Reset + " " + bar3.Output())
|
|
|
+
|
|
|
+ if d.Disconnected {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ time.Sleep(time.Millisecond * 100)
|
|
|
+ }
|
|
|
|
|
|
- d.Write(door.Reset + door.CRNL + door.CRNL)
|
|
|
- d.Write(fmt.Sprintf("You chose %d from the menu."+door.CRNL, item))
|
|
|
+}
|
|
|
|
|
|
- press_a_key(&d)
|
|
|
+func main() {
|
|
|
+ var message string
|
|
|
+
|
|
|
+ fmt.Println("Starting testdoor.go")
|
|
|
+ d := door.Door{}
|
|
|
+
|
|
|
+ d.Init()
|
|
|
+
|
|
|
+ bold := door.Color(1, 37, 40)
|
|
|
+ bolder := door.ColorText("BLI BOLD YEL ON BLUE")
|
|
|
+ d.Write("Welcome to " + bolder + "door32.sys" + door.Reset + door.CRNL + "..." + door.CRNL)
|
|
|
+ key := press_a_key(&d)
|
|
|
+ d.Write(fmt.Sprintf("Key %s%d / %x%s", bold, key, key, door.Reset) + door.CRNL)
|
|
|
+
|
|
|
+ b := door.AlertBox("Warning: golang is in use!", 1)
|
|
|
+ d.Write(door.ColorText("BRI WHI ON GREEN"))
|
|
|
+ for _, line := range b {
|
|
|
+ d.Write(line + door.CRNL)
|
|
|
+ }
|
|
|
+ d.Write(door.Reset + door.CRNL)
|
|
|
+
|
|
|
+ left := d.TimeLeft()
|
|
|
|
|
|
- message = fmt.Sprintf("Returning %s to the BBS..."+door.CRNL, name)
|
|
|
+ message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
|
|
|
d.Write(message)
|
|
|
|
|
|
- d.WaitKey(3, 0)
|
|
|
+ press_a_key(&d)
|
|
|
+
|
|
|
+ mainmenu := MainMenu()
|
|
|
+ var choice int
|
|
|
+
|
|
|
+ for choice >= 0 {
|
|
|
+ d.Write(door.Clrscr)
|
|
|
+ choice = mainmenu.Choose(&d)
|
|
|
+
|
|
|
+ if choice < 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ option := mainmenu.GetOption(choice)
|
|
|
+
|
|
|
+ // fmt.Printf("Choice: %d, Option: %c\n", choice, option)
|
|
|
+
|
|
|
+ switch option {
|
|
|
+ case 'A':
|
|
|
+ display_ansi(&d)
|
|
|
+ press_a_key(&d)
|
|
|
+ case 'D':
|
|
|
+ display_information(&d)
|
|
|
+ press_a_key(&d)
|
|
|
+ case 'I':
|
|
|
+ d.Write(door.Reset + door.CRNL + door.CRNL)
|
|
|
+ input_demo(&d)
|
|
|
+ press_a_key(&d)
|
|
|
+ case 'P':
|
|
|
+ progress_bars(&d)
|
|
|
+ press_a_key(&d)
|
|
|
+ case 'Q':
|
|
|
+ choice = -1
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ d.Write(door.Reset + door.CRNL)
|
|
|
+
|
|
|
+ message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
|
|
|
+ d.Write(message)
|
|
|
|
|
|
+ d.WaitKey(2, 0)
|
|
|
left = d.TimeLeft()
|
|
|
|
|
|
message = fmt.Sprintf("You had %0.2f minutes / %0.2f seconds remaining!"+door.CRNL, left.Minutes(), left.Seconds())
|