Преглед изворни кода

Menu removed MenuOption/MenuOptions/Build.

Steve Thielemann пре 3 година
родитељ
комит
08817f137c
3 измењених фајлова са 32 додато и 4 уклоњено
  1. 18 0
      door/door.go
  2. 7 1
      door/input.go
  3. 7 3
      door/menu.go

+ 18 - 0
door/door.go

@@ -1,3 +1,21 @@
+/*
+Package door: a golang implementation of a BBS door for linux that
+support door32.sys.
+
+    import (
+			"door"
+		)
+
+		int main() {
+			d = door.Door{}
+			d.Init() // Process commandline switches, initialize door, detect screen size.
+
+			d.Write("Welcome to my awesome door, written in "+door.ColorText("BLINK BOLD WHITE")+"golang"+door.Reset+"."+door.CRNL)
+			d.Write("Press a key...")
+			d.Key()
+			d.Write(door.CRNL)
+		}
+*/
 package door
 
 import (

+ 7 - 1
door/input.go

@@ -362,6 +362,12 @@ retry:
 	return int(buffer[0])
 }
 
+// Outputs spaces and backspaces
+// If you have set a background color, this shows the input area.
+func (d *Door) DisplayInput(max int) {
+	d.Write(strings.Repeat(" ", max) + strings.Repeat("\x08", max))
+}
+
 // Input a string of max length.
 // This displays the input area if a bg color was set.
 // This handles timeout, input, backspace, and enter.
@@ -369,7 +375,7 @@ func (d *Door) Input(max int) string {
 	var line string
 
 	// draw input area
-	d.Write(strings.Repeat(" ", max) + strings.Repeat("\x08", max))
+	d.DisplayInput(max)
 
 	var c int
 

+ 7 - 3
door/menu.go

@@ -5,17 +5,19 @@ import (
 	"unicode"
 )
 
+/*
 type MenuOption struct {
 	Ch   rune
 	Text string
 }
+*/
 
 type Menu struct {
 	Chosen      int
 	SelectedR   func(string) string
 	UnselectedR func(string) string
 	Options     []rune
-	MenuOptions []MenuOption
+	// MenuOptions []MenuOption
 	Panel
 }
 
@@ -74,6 +76,7 @@ func (m *Menu) AddSelection(key string, text string) {
 // the menu in larger chunks -- but it is redundant.
 // Once the menu is built, I really could delete the MenuOptions.
 
+/*
 func (m *Menu) Build() {
 	// Take MenuOptions and build the Menu
 
@@ -88,6 +91,7 @@ func (m *Menu) Build() {
 		m.Lines = append(m.Lines, Line{Text: text, RenderF: m.UnselectedR})
 	}
 }
+*/
 
 func (m *Menu) Choose(d *Door) int {
 	var changed []int
@@ -130,8 +134,8 @@ func (m *Menu) Choose(d *Door) int {
 		changed = make([]int, 0)
 
 		use_numberpad := true
-		for _, option := range m.MenuOptions {
-			if option.Ch == rune('8') || option.Ch == rune('2') {
+		for _, option := range m.Options {
+			if option == rune('8') || option == rune('2') {
 				use_numberpad = false
 			}
 		}