Browse Source

Panic when Title+offset > panel width.

Steve Thielemann 3 years ago
parent
commit
e2b64cc5a7
2 changed files with 12 additions and 1 deletions
  1. 4 0
      door/door.go
  2. 8 1
      door/panel.go

+ 4 - 0
door/door.go

@@ -210,6 +210,10 @@ func (d *Door) detect() {
 	if d.HasKey() {
 		buffer := make([]byte, 100)
 		r, err := syscall.Read(d.READFD, buffer)
+		if r == -1 {
+			d.Disconnected = true
+			return
+		}
 		results = string(buffer[:r])
 		output := strings.Replace(results, "\x1b", "^[", -1)
 		log.Println("DETECT:", r, err, output)

+ 8 - 1
door/panel.go

@@ -1,6 +1,9 @@
 package door
 
-import "strings"
+import (
+	"log"
+	"strings"
+)
 
 type BorderStyle int
 
@@ -38,6 +41,10 @@ func (p *Panel) Output() string {
 		// Top line / border
 		output += Goto(p.X, row) + p.BorderColor + box_style.top_left
 		if p.Title != "" {
+			if p.TitleOffset+len(p.Title) > p.Width {
+				log.Panicf("Panel (not wide enough) Width %d : Title size %d + offset %d = %d\n",
+					p.Width, len(p.Title), p.TitleOffset, p.TitleOffset+len(p.Title))
+			}
 			output += strings.Repeat(box_style.top, p.TitleOffset) + p.Title
 		}
 		output += strings.Repeat(box_style.top, p.Width-(p.TitleOffset+len(p.Title))) + box_style.top_right