Steve Thielemann преди 3 години
родител
ревизия
2297578ed8
променени са 6 файла, в които са добавени 47 реда и са изтрити 25 реда
  1. 1 8
      door/color.go
  2. 1 0
      door/convert.go
  3. 12 3
      door/input.go
  4. 6 0
      door/menu.go
  5. 17 8
      door/panel.go
  6. 10 6
      testdoor/testdoor.go

+ 1 - 8
door/color.go

@@ -62,14 +62,7 @@ func ColorText(color string) string {
 				result = append(result, 32)
 			}
 
-		case "BRO":
-			if bg {
-				result = append(result, 43)
-			} else {
-				result = append(result, 33)
-			}
-
-		case "YEL":
+		case "BRO", "YEL":
 			if bg {
 				result = append(result, 43)
 			} else {

+ 1 - 0
door/convert.go

@@ -5,6 +5,7 @@ package door
 
 // This converts CP437 to Unicode for rendering in Unicode terminals
 // like the linux telnet client.
+// This does everything but: \x07, \x08, \x0a and \x0d.
 func CP437_to_Unicode(cp437 string) string {
 	var result string
 

+ 12 - 3
door/input.go

@@ -304,6 +304,10 @@ func (d *Door) GetKey() int {
 	return c
 }
 
+func (d *Door) Key() int {
+	return d.WaitKey(Inactivity, 0)
+}
+
 func (d *Door) WaitKey(secs int64, usecs int64) int {
 	if d.Disconnected {
 		return -2
@@ -323,12 +327,17 @@ func (d *Door) WaitKey(secs int64, usecs int64) int {
 	if v == -1 {
 		errno, ok := err.(syscall.Errno)
 		if ok && errno == syscall.EINTR {
+			// Should I retry my syscall.Select here?
 			return -1
 		}
 
-		// Interrupted system call ???  What does this mean?
-		// This isn't hangup.  I'm still connected.
-		// -1 :  interrupted system call
+		/*
+			Interrupted system call ???  What does this mean?
+			This isn't hangup.  I'm still connected.
+			-1 :  interrupted system call
+			This seemed to happen when I called WaitKey many times with usecs.
+		*/
+
 		fmt.Println("-1 : ", err)
 		// hangup ?!
 		return -2

+ 6 - 0
door/menu.go

@@ -61,6 +61,12 @@ func MakeMenuRender(c1, c2, c3, c4 string) func(string) string {
 	return f
 }
 
+// Should I be using this, or write a function like the original --
+// m.AddSelection("K", "Text") to build?  (And throw away the
+// redundant) MenuOptions/MenuOption parts?  They do let me create
+// 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
 

+ 17 - 8
door/panel.go

@@ -50,18 +50,27 @@ func (p *Panel) Output() string {
 
 	for _, line := range p.Lines {
 		output += Goto(p.X, row)
-
-		// "Joining" lines code
-
-		// We are not joining lines at this time.
+		var joined bool = false
 
 		if style > 0 {
-			output += p.BorderColor + box_style.side
+			top := box_style.top
+			if line.Text[0:len(top)] == top {
+				// Yes, this line needs to be joined...
+				output += p.BorderColor + box_style.middle_left + line.Output() + p.BorderColor + box_style.middle_right
+				joined = true
+			}
 		}
-		output += line.Output()
-		if style > 0 {
-			output += p.BorderColor + box_style.side
+
+		if !joined {
+			if style > 0 {
+				output += p.BorderColor + box_style.side
+			}
+			output += line.Output()
+			if style > 0 {
+				output += p.BorderColor + box_style.side
+			}
 		}
+
 		row++
 	}
 

+ 10 - 6
testdoor/testdoor.go

@@ -93,6 +93,7 @@ func main() {
 
 	d.Write(door.Reset + door.CRNL + "Press a key to continue...")
 	d.WaitKey(120, 0)
+	d.Write(door.CRNL)
 
 	m := door.Menu{Panel: door.Panel{Width: 25,
 		X:           5,
@@ -115,12 +116,15 @@ func main() {
 		{rune('Q'), "Quit"}}
 	m.Build()
 
-	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.WaitKey(120, 0)
+	// 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.WaitKey(120, 0)
+	*/
 
 	d.Write(door.Clrscr)