Browse Source

Cleaned up testdoor with new Line.Width.

Steve Thielemann 2 years ago
parent
commit
af27c3af89
2 changed files with 22 additions and 20 deletions
  1. 1 1
      testdoor/go.mod
  2. 21 19
      testdoor/testdoor.go

+ 1 - 1
testdoor/go.mod

@@ -6,4 +6,4 @@ replace red-green/door => ../door
 
 
 require red-green/door v0.0.0-00010101000000-000000000000
 require red-green/door v0.0.0-00010101000000-000000000000
 
 
-require github.com/mitchellh/go-wordwrap v1.0.1 // indirect
+require github.com/mitchellh/go-wordwrap v1.0.1

+ 21 - 19
testdoor/testdoor.go

@@ -58,7 +58,7 @@ func about_test_door(d *door.Door) {
 	}
 	}
 
 
 	about.Lines = append(about.Lines,
 	about.Lines = append(about.Lines,
-		door.Line{Text: fmt.Sprintf("%*s", -W, copyright),
+		door.Line{Text: copyright, Width: W,
 			DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
 			DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
 	for _, text := range []string{"",
 	for _, text := range []string{"",
 		"This door was written by Bugz.",
 		"This door was written by Bugz.",
@@ -67,7 +67,7 @@ func about_test_door(d *door.Door) {
 		"to screen sizes, uses door32.sys, supports TheDraw Fonts",
 		"to screen sizes, uses door32.sys, supports TheDraw Fonts",
 		"(the fonts are compiled into the door), has NoMoreSecrets",
 		"(the fonts are compiled into the door), has NoMoreSecrets",
 		"effect, and runs on Linux and Windows."} {
 		"effect, and runs on Linux and Windows."} {
-		about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, text)})
+		about.Lines = append(about.Lines, door.Line{Text: text, Width: W})
 	}
 	}
 
 
 	var better door.NoMoreSecretsConfig = door.NoMoreSecretsDefault
 	var better door.NoMoreSecretsConfig = door.NoMoreSecretsDefault
@@ -147,7 +147,7 @@ func MainMenu() door.Menu {
 	// Position the description panel beside the menu. m.Width + m.X + 2 (1 one to give it a space)
 	// Position the description panel beside the menu. m.Width + m.X + 2 (1 one to give it a space)
 	var descPanel door.Panel = door.Panel{X: menu.Width + menu.X + 2 + 1, Y: menu.Y, Width: panelWidth, Style: door.SINGLE, BorderColor: door.ColorText("WHI ON BLU")}
 	var descPanel door.Panel = door.Panel{X: menu.Width + menu.X + 2 + 1, Y: menu.Y, Width: panelWidth, Style: door.SINGLE, BorderColor: door.ColorText("WHI ON BLU")}
 	for x := 0; x < maxLines; x++ {
 	for x := 0; x < maxLines; x++ {
-		descPanel.Lines = append(descPanel.Lines, door.Line{Text: ""})
+		descPanel.Lines = append(descPanel.Lines, door.Line{Text: "", Width: panelWidth})
 	}
 	}
 
 
 	menu.Activated = func(item int, d *door.Door) {
 	menu.Activated = func(item int, d *door.Door) {
@@ -155,9 +155,9 @@ func MainMenu() door.Menu {
 		var lines []string = strings.Split(wordwrap.WrapString(line, uint(panelWidth)), "\n")
 		var lines []string = strings.Split(wordwrap.WrapString(line, uint(panelWidth)), "\n")
 		for idx, _ := range descPanel.Lines {
 		for idx, _ := range descPanel.Lines {
 			if idx >= len(lines) {
 			if idx >= len(lines) {
-				descPanel.Lines[idx].Text = strings.Repeat(" ", panelWidth)
+				descPanel.Lines[idx].Text = ""
 			} else {
 			} else {
-				descPanel.Lines[idx].Text = fmt.Sprintf("%-*s", panelWidth, lines[idx])
+				descPanel.Lines[idx].Text = lines[idx]
 			}
 			}
 		}
 		}
 		d.Write(door.SavePos + descPanel.Output() + door.RestorePos)
 		d.Write(door.SavePos + descPanel.Output() + door.RestorePos)
@@ -532,7 +532,6 @@ func width_demo(d *door.Door) {
 
 
 func panel_demo(d *door.Door) {
 func panel_demo(d *door.Door) {
 	var width int = 55
 	var width int = 55
-	var fmtStr string = "%-55s"
 	var p door.Panel = door.Panel{X: 5, Y: 5, Width: width, Style: door.DOUBLE, BorderColor: door.ColorText("CYAN ON BLUE"), Title: "[ Panel Demo ]"}
 	var p door.Panel = door.Panel{X: 5, Y: 5, Width: width, Style: door.DOUBLE, BorderColor: door.ColorText("CYAN ON BLUE"), Title: "[ Panel Demo ]"}
 
 
 	var lineColor string = door.ColorText("BRIGHT WHI ON BLUE")
 	var lineColor string = door.ColorText("BRIGHT WHI ON BLUE")
@@ -541,26 +540,28 @@ func panel_demo(d *door.Door) {
 		if door.Unicode {
 		if door.Unicode {
 			line = strings.Replace(line, "(C)", "\u00a9", -1)
 			line = strings.Replace(line, "(C)", "\u00a9", -1)
 		}
 		}
-		var l door.Line = door.Line{Text: fmt.Sprintf(fmtStr, line), DefaultColor: lineColor}
+		var l door.Line = door.Line{Text: line, Width: width, DefaultColor: lineColor}
 		p.Lines = append(p.Lines, l)
 		p.Lines = append(p.Lines, l)
 	}
 	}
 	p.Lines = append(p.Lines, p.Spacer())
 	p.Lines = append(p.Lines, p.Spacer())
-	p.Lines = append(p.Lines, door.Line{Text: fmt.Sprintf(fmtStr, "Welcome to golang!"), DefaultColor: lineColor})
+	p.Lines = append(p.Lines, door.Line{Text: "Welcome to golang!", Width: width, DefaultColor: lineColor})
 
 
-	var single door.Panel = door.Panel{X: 6, Y: 12, Width: 10, Style: door.SINGLE, BorderColor: door.ColorText("WHITE ON BLUE"), Title: "< Single >"}
-	single.Lines = append(single.Lines, door.Line{Text: "Example   ", DefaultColor: door.ColorText("WHI ON BLACK")})
+	width = 10
+	var single door.Panel = door.Panel{X: 6, Y: 12, Width: width, Style: door.SINGLE, BorderColor: door.ColorText("WHITE ON BLUE"), Title: "< Single >"}
+	single.Lines = append(single.Lines, door.Line{Text: "Example", Width: width, DefaultColor: door.ColorText("WHI ON BLACK")})
 	single.Lines = append(single.Lines, single.Spacer())
 	single.Lines = append(single.Lines, single.Spacer())
-	single.Lines = append(single.Lines, door.Line{Text: "More Text ", DefaultColor: door.ColorText("BRI GREEN ON BLACK")})
+	single.Lines = append(single.Lines, door.Line{Text: "More Text", Width: width, DefaultColor: door.ColorText("BRI GREEN ON BLACK")})
 
 
-	var ds door.Panel = door.Panel{X: 26, Y: 12, Width: 15, Style: door.DOUBLE_SINGLE, BorderColor: door.ColorText("BRI CYAN ON GREEN"), Title: "Double", TitleOffset: 3}
-	ds.Lines = append(ds.Lines, door.Line{Text: "Double / Single", DefaultColor: door.ColorText("BRI WHI ON GREEN")})
+	width = 15
+	var ds door.Panel = door.Panel{X: 26, Y: 12, Width: width, Style: door.DOUBLE_SINGLE, BorderColor: door.ColorText("BRI CYAN ON GREEN"), Title: "Double", TitleOffset: 3}
+	ds.Lines = append(ds.Lines, door.Line{Text: "Double / Single", Width: width, DefaultColor: door.ColorText("BRI WHI ON GREEN")})
 	ds.Lines = append(ds.Lines, ds.Spacer())
 	ds.Lines = append(ds.Lines, ds.Spacer())
-	ds.Lines = append(ds.Lines, door.Line{Text: "Some Other Text", DefaultColor: door.ColorText("BRI CYAN ON GREEN")})
+	ds.Lines = append(ds.Lines, door.Line{Text: "Some Other Text", Width: width, DefaultColor: door.ColorText("BRI CYAN ON GREEN")})
 
 
-	var sd door.Panel = door.Panel{X: 46, Y: 12, Width: 15, Style: door.SINGLE_DOUBLE, BorderColor: door.ColorText("BRI YELL ON RED")}
-	sd.Lines = append(sd.Lines, door.Line{Text: "Single / Double", DefaultColor: door.ColorText("BRI WHI ON RED")})
+	var sd door.Panel = door.Panel{X: 46, Y: 12, Width: width, Style: door.SINGLE_DOUBLE, BorderColor: door.ColorText("BRI YELL ON RED")}
+	sd.Lines = append(sd.Lines, door.Line{Text: "Single / Double", Width: width, DefaultColor: door.ColorText("BRI WHI ON RED")})
 	sd.Lines = append(sd.Lines, sd.Spacer())
 	sd.Lines = append(sd.Lines, sd.Spacer())
-	sd.Lines = append(sd.Lines, door.Line{Text: "Text Goes Here ", DefaultColor: door.ColorText("BRI GREEN ON RED")})
+	sd.Lines = append(sd.Lines, door.Line{Text: "Text Goes Here ", Width: width, DefaultColor: door.ColorText("BRI GREEN ON RED")})
 
 
 	d.Write(door.Clrscr)
 	d.Write(door.Clrscr)
 	d.Write(p.Output())
 	d.Write(p.Output())
@@ -579,11 +580,12 @@ func main() {
 
 
 	defer func() {
 	defer func() {
 		if err := recover(); err != nil {
 		if err := recover(); err != nil {
+			// This displays stack trace stderr
+			debug.PrintStack()
+			fmt.Println("ERROR:", err)
 			log.Println("FAILURE:", err)
 			log.Println("FAILURE:", err)
 			// Display error to user
 			// Display error to user
 			d.Write(fmt.Sprintf(door.Reset+door.CRNL+"Exception: %v"+door.CRNL, err))
 			d.Write(fmt.Sprintf(door.Reset+door.CRNL+"Exception: %v"+door.CRNL, err))
-			// This displays stack trace stderr
-			debug.PrintStack()
 		}
 		}
 	}()
 	}()