display.go 7.1 KB

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