display.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "log"
  6. "red-green/door"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. func display_information(d *door.Door) {
  12. d.WriteS(door.Clrscr)
  13. var headerColor = door.ColorText("BRI CYAN")
  14. var keyColor = door.ColorText("BRI GREEN")
  15. var sepColor = door.ColorText("BRI YEL")
  16. var valColor = door.ColorText("CYAN")
  17. var nice_format func(string, string) string = func(key string, value string) string {
  18. return fmt.Sprintf("%s%-20s %s: %s%s", keyColor, key, sepColor, valColor, value) + door.CRNL
  19. }
  20. var offset string
  21. var header string = "DropFile: "
  22. offset = strings.Repeat(" ", len(header))
  23. d.WriteA(headerColor, header)
  24. d.WriteA(nice_format("Comm Type", strconv.Itoa(d.Config.Comm_type)))
  25. if d.Config.BBSID != "" {
  26. d.WriteA(offset, nice_format("BBS Software", d.Config.BBSID))
  27. }
  28. d.WriteA(offset, nice_format("Time Left", strconv.Itoa(d.Config.Time_left)))
  29. d.WriteA(offset, nice_format("Real Name", d.Config.Real_name))
  30. // d.Write(nice_format("Comm Handle", strconv.Itoa(d.Config.Comm_handle)))
  31. d.WriteA(offset, nice_format("Handle", d.Config.Handle))
  32. d.WriteA(offset, nice_format("User #", strconv.Itoa(d.Config.User_number)))
  33. d.WriteA(offset, nice_format("Security Level", strconv.Itoa(d.Config.Security_level)))
  34. d.WriteA(offset, nice_format("Node #", strconv.Itoa(d.Config.Node)))
  35. header = "Detected: "
  36. offset = strings.Repeat(" ", len(header))
  37. d.WriteA(door.CRNL, headerColor, header)
  38. d.WriteA(nice_format("Unicode", strconv.FormatBool(door.Unicode)))
  39. d.WriteA(offset, nice_format("CP437", strconv.FormatBool(door.CP437)))
  40. d.WriteA(offset, nice_format("Full CP437", strconv.FormatBool(door.Full_CP437)))
  41. d.WriteA(offset, nice_format("Screen Size", fmt.Sprintf("%d X %d", door.Width, door.Height)))
  42. var time time.Duration = d.TimeLeft()
  43. d.WriteA(offset, nice_format("Door Time Left", fmt.Sprintf("%d Hours, %d Minutes, %d Seconds", int(time.Hours()), int(time.Minutes())%60, int(time.Seconds())%60)))
  44. time = d.TimeUsed()
  45. d.WriteA(offset, nice_format("Door Time Used", fmt.Sprintf("%d Minutes, %d Seconds", int(time.Minutes()), int(time.Seconds())%60)))
  46. press_a_key(d)
  47. d.WriteA(door.Clrscr, door.CRNL, door.CRNL, door.CRNL)
  48. modules := GetModules()
  49. header = "Build: "
  50. offset = strings.Repeat(" ", len(header))
  51. d.WriteA(headerColor, header)
  52. gover, gitver, goarch, goos := GetVersion()
  53. d.WriteA(nice_format("go version", gover))
  54. d.WriteA(offset, nice_format("git commit", gitver))
  55. d.WriteA(offset, nice_format("Arch", goarch))
  56. d.WriteA(offset, nice_format("OS", goos))
  57. for mod, version := range modules {
  58. d.WriteA(offset, nice_format(mod, version))
  59. }
  60. }
  61. func display_ansi(d *door.Door) {
  62. var art []string = ANSIGrowl()
  63. d.WriteS(door.Clrscr)
  64. for _, line := range art {
  65. d.WriteS(line + door.CRNL)
  66. }
  67. }
  68. func input_demo(d *door.Door) {
  69. var ticker *time.Ticker = time.NewTicker(time.Second)
  70. var StopIt = make(chan bool)
  71. go func() {
  72. for {
  73. select {
  74. case <-StopIt:
  75. return
  76. case t := <-ticker.C:
  77. const tf = "January 2, 2006 03:04:05 PM MST"
  78. output := door.SavePos + door.GotoS(5, 2) + door.ColorTextS("BRI WHI ON CYAN") + t.Format(tf) + door.RestorePos
  79. d.WriteS(output)
  80. }
  81. }
  82. }()
  83. var inputColor = door.ColorText("BRI WHI ON BLUE")
  84. var inputColor2 = door.ColorText("BRI WHI ON GREEN")
  85. var prompt *door.Line = door.NewLine("What is YOUR Name: ")
  86. prompt.RenderF = door.RenderBlueYellow
  87. log.Println("BEGIN INPUT DEMO")
  88. d.WriteA(prompt.Output(), inputColor)
  89. var name string = d.Input(25)
  90. d.WriteA(door.Reset, door.CRNL)
  91. prompt.Text.Reset()
  92. prompt.Text.WriteString("What is Your Quest:")
  93. d.WriteA(prompt.Output(), inputColor2)
  94. var quest string = d.Input(35)
  95. d.WriteA(door.Reset, door.CRNL)
  96. prompt.Text.Reset()
  97. prompt.Text.WriteString("What is your Favorite CoLoR: ")
  98. d.WriteA(prompt.Output(), inputColor)
  99. var color string = d.Input(15)
  100. d.WriteA(door.Reset, door.CRNL)
  101. ticker.Stop()
  102. StopIt <- true
  103. log.Println("END INPUT DEMO")
  104. d.WriteA(fmt.Sprintf("You're %s on the %s quest, and fond of %s."+door.CRNL, name, quest, color))
  105. }
  106. func pctUpdate(pct *int64) func() int64 {
  107. return func() int64 {
  108. return *pct
  109. }
  110. }
  111. func progress_bars(d *door.Door) {
  112. d.WriteA(door.Clrscr)
  113. var barHalf *door.BarLine = &door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
  114. var barPercent *door.BarLine = &door.BarLine{Width: 30, Style: door.SOLID, PercentStyle: door.PERCENT_SPACE}
  115. barPercent.ColorRange = []door.BarRange{
  116. {Percent: 2500, Color: door.ColorText("RED")},
  117. {Percent: 5000, Color: door.ColorText("BROWN")},
  118. {Percent: 7500, Color: door.ColorText("BOLD YEL")},
  119. {Percent: 9500, Color: door.ColorText("GREEN")},
  120. {Percent: 10100, Color: door.ColorText("BRI GRE")}}
  121. var barGradient door.BarLine = door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
  122. var percentage int64
  123. barHalf.UpdateP = pctUpdate(&percentage)
  124. barPercent.UpdateP = pctUpdate(&percentage)
  125. barGradient.UpdateP = pctUpdate(&percentage)
  126. update_bars := func() {
  127. barHalf.Update()
  128. barPercent.Update()
  129. barGradient.Update()
  130. }
  131. d.WriteA(door.Goto(3, 12), "Half-Step")
  132. d.WriteA(door.Goto(25, 12), "% with space and Color Range")
  133. d.WriteA(door.Goto(57, 12), "Gradient")
  134. d.WriteA(door.HideCursor)
  135. bar_start := door.Goto(3, 15)
  136. for f := 0; f <= 100; f++ {
  137. d.WriteA(door.Goto(3, 10), door.Reset+fmt.Sprintf("Value: %d", f))
  138. percentage = int64(f * 100)
  139. update_bars()
  140. d.WriteA(bar_start, barHalf.Output(), " ", door.Reset, barPercent.Output(), door.Reset+" ", barGradient.Output())
  141. if d.Disconnect() {
  142. // don't continue to sleep if we're disconnected
  143. break
  144. }
  145. _, ex, err := d.WaitKey(time.Millisecond * 100)
  146. if err == nil {
  147. if ex == door.MOUSE {
  148. m, ok := d.GetMouse()
  149. if ok {
  150. if m.Button == 1 {
  151. // end loop
  152. f = 99
  153. }
  154. }
  155. } else {
  156. // end loop
  157. f = 99
  158. }
  159. }
  160. // time.Sleep(time.Millisecond * 100)
  161. }
  162. d.WriteA(door.ShowCursor)
  163. }
  164. func width_demo(d *door.Door) {
  165. var w int = door.Width
  166. var panel door.Panel = door.Panel{X: 1, Y: 1, Width: w}
  167. var lineColor = door.ColorText("WHI")
  168. var line string
  169. for y := 1; y <= door.Height; y++ {
  170. if y%10 == 0 {
  171. line = strings.Repeat("1234567890", w/10)
  172. for x := len(line); x < w; x++ {
  173. line += strconv.Itoa((x + 1) % 10)
  174. }
  175. } else {
  176. line = ""
  177. for x := 1; x < w; x++ {
  178. if x%10 == 0 {
  179. line += strconv.Itoa(y % 10)
  180. } else {
  181. line += " "
  182. }
  183. }
  184. }
  185. var l *door.Line = &door.Line{Text: bytes.NewBuffer([]byte(line)), DefaultColor: lineColor}
  186. panel.Lines = append(panel.Lines, l)
  187. }
  188. var message string = fmt.Sprintf("Screen Size: %d X %d", door.Width, door.Height)
  189. d.Write(panel.Output())
  190. // Output alert on top of panel
  191. var cx, cy int
  192. cx = (door.Width - len(message) + 2) / 2
  193. cy = (door.Height - 3) / 2
  194. var alert []string = door.AlertBox(message, 1)
  195. d.WriteA(door.ColorText("BRI YEL ON BLUE"))
  196. for idx, ab := range alert {
  197. d.WriteA(door.Goto(cx, cy+idx), ab)
  198. }
  199. d.WriteA(door.Reset, panel.GotoEnd())
  200. // Pause for key
  201. press_key_or_mouse(d)
  202. // d.WaitKey(door.Inactivity)
  203. panel.Lines = make([]*door.Line, 0)
  204. var background string = "BUGZ Test Door in GO "
  205. var bl int = len(background)
  206. for y := 1; y <= door.Height; y++ {
  207. offset := (y - 1) % bl
  208. line = background[offset:]
  209. for len(line) < w {
  210. if len(line)+bl <= w {
  211. line += background
  212. } else {
  213. line += background[0 : w-len(line)]
  214. }
  215. }
  216. var l *door.Line = &door.Line{Text: bytes.NewBuffer([]byte(line)), RenderF: door.RenderBlueYellow}
  217. panel.Lines = append(panel.Lines, l)
  218. }
  219. d.Write(panel.Output())
  220. // d.WaitKey(door.Inactivity)
  221. press_key_or_mouse(d)
  222. }