Переглянути джерело

Testdoor changes thanks to staticcheck.

Steve Thielemann 3 роки тому
батько
коміт
9533fa31c3
2 змінених файлів з 63 додано та 26 видалено
  1. 50 22
      testdoor/tdfont.go
  2. 13 4
      testdoor/testdoor.go

+ 50 - 22
testdoor/tdfont.go

@@ -39,7 +39,7 @@ func normalizeBlock(block *[][]byte) {
 		}
 	}
 	// fmt.Printf("max = %d\n", max)
-	for idx, _ := range *block {
+	for idx := range *block {
 		// l := len(line)
 		for len((*block)[idx]) < max {
 			//(*block)[idx] += byte(0x20) //append((*block)[idx], byte{0x20})
@@ -78,12 +78,14 @@ func (bf *BlockFont) GetCharacter(c int) [][]byte {
 	}
 }
 
+/*
 // expandBlock the number of strings, and make it match the length of [0].
 func __expandBlock(block *[]string) {
 	// l := len((*block)[0])
 	l := len([]rune((*block)[0]))
 	*block = append(*block, strings.Repeat(" ", l))
 }
+*/
 
 func expandBlock(block *[][]byte) {
 	// l := len((*block)[0])
@@ -106,9 +108,12 @@ func (bf *BlockFont) Output(input string) ([][]byte, int) {
 		if l != 0 {
 			if len(out) == 0 {
 				// First time
-				for _, b := range block {
-					out = append(out, b)
-				}
+				out = append(out, block...)
+				/*
+					for _, b := range block {
+						out = append(out, b)
+					}
+				*/
 			} else {
 				if len(out) != 0 {
 					for l > len(out) {
@@ -122,11 +127,14 @@ func (bf *BlockFont) Output(input string) ([][]byte, int) {
 				// Ok, we have something!
 				for idx, b := range block {
 					out[idx] = append(out[idx], byte(0x20))
-					// out[idx] = append(out[idx], b)
+					out[idx] = append(out[idx], b...)
+
+					/*
+						for _, inner := range b {
+							out[idx] = append(out[idx], inner)
+						}
+					*/
 
-					for _, inner := range b {
-						out[idx] = append(out[idx], inner)
-					}
 					// out[idx] += byte(0x20) + b
 					// fmt.Printf("%s\n", CP437_to_Unicode(b))
 				}
@@ -144,6 +152,7 @@ type ColorFont struct {
 	data       [][][]byte
 }
 
+/*
 // Make []strings all the same length
 func ___normalizeColor(block *[]string) int {
 	var max int
@@ -161,6 +170,7 @@ func ___normalizeColor(block *[]string) int {
 	}
 	return max
 }
+*/
 
 func normalizeColor(block *[][]byte) int {
 	var max int
@@ -170,7 +180,7 @@ func normalizeColor(block *[][]byte) int {
 			max = l
 		}
 	}
-	for idx, _ := range *block {
+	for idx := range *block {
 		// l := len(line)
 		blank := []byte{0x20, 0x0f}
 		for len((*block)[idx]) < max {
@@ -227,6 +237,8 @@ func thedraw_to_ansi(c int) int {
 	return trans[c]
 }
 
+/*
+// Before color output was optimized
 func colorout(c int) string {
 	bg := thedraw_to_ansi(c / 16)
 	fg := c % 16
@@ -238,6 +250,7 @@ func colorout(c int) string {
 		return fmt.Sprintf("\x1b[0;%d;%dm", fg+30, bg+40)
 	}
 }
+*/
 
 type ColorParts struct {
 	Background int
@@ -304,9 +317,12 @@ func Colorize(input []byte) []byte {
 		color := int(input[pos+1])
 		// fmt.Printf("%d : CH %d / %x, Color %d / %x\n", pos, ch, ch, color, color)
 		colorstring := ColorOutput(previous, color)
-		for _, c := range []byte(colorstring) {
-			result = append(result, c)
-		}
+		result = append(result, []byte(colorstring)...)
+		/*
+			for _, c := range []byte(colorstring) {
+				result = append(result, c)
+			}
+		*/
 
 		// result = append(result, []byte(colorstring))
 
@@ -320,9 +336,11 @@ func Colorize(input []byte) []byte {
 	return result
 }
 
+/*
 func __expandColor(block *[]string, need int) {
 	*block = append(*block, strings.Repeat(" \x0f", need))
 }
+*/
 
 func expandColor(block *[][]byte, need int) {
 	blank := []byte{0x20, 0x0f}
@@ -346,9 +364,13 @@ func (bf *ColorFont) Output(input string) ([][]byte, int) {
 		if l != 0 {
 			if len(out) == 0 {
 				// First time
-				for _, b := range block {
-					out = append(out, b)
-				}
+				out = append(out, block...)
+				/*
+					for _, b := range block {
+						out = append(out, b)
+					}
+				*/
+
 			} else {
 				if len(out) != 0 {
 					for l > len(out) {
@@ -370,14 +392,20 @@ func (bf *ColorFont) Output(input string) ([][]byte, int) {
 					panic(fmt.Sprintf("len(out) %d != len(block) %d", len(out), len(block)))
 				}
 
+				blank := []byte{0x20, 0x0f}
 				// Ok, we have something!
 				for idx, b := range block {
-					// blank := []byte{0x20, 0x0f}
-					out[idx] = append(out[idx], byte(0x20))
-					out[idx] = append(out[idx], byte(0x0f))
-					for _, inner := range b {
-						out[idx] = append(out[idx], inner)
-					}
+					/*
+						out[idx] = append(out[idx], byte(0x20))
+						out[idx] = append(out[idx], byte(0x0f))
+					*/
+					out[idx] = append(out[idx], blank...)
+					out[idx] = append(out[idx], b...)
+					/*
+						for _, inner := range b {
+							out[idx] = append(out[idx], inner)
+						}
+					*/
 					//out[idx] += " \x0f" + b
 					// fmt.Printf("%s\n", CP437_to_Unicode(b))
 				}
@@ -394,7 +422,7 @@ func (bf *ColorFont) Output(input string) ([][]byte, int) {
 	// StringHexO(&out)
 	max = len(out[0]) / 2
 
-	for idx, _ := range out {
+	for idx := range out {
 		out[idx] = Colorize(out[idx])
 	}
 	return out, max

+ 13 - 4
testdoor/testdoor.go

@@ -374,16 +374,20 @@ func width_demo(d *door.Door) {
 		panel.Lines = append(panel.Lines, l)
 	}
 	message := fmt.Sprintf("Screen Size: %d X %d", door.Width, door.Height)
-	alert := door.AlertBox(message, 1)
 	d.Write(panel.Output())
+
+	// Output alert on top of panel
 	cx := (door.Width - len(message) + 2) / 2
 	cy := (door.Height - 3) / 2
+	alert := door.AlertBox(message, 1)
 	d.Write(door.ColorText("BRI YEL ON BLUE"))
 	for idx, ab := range alert {
 		d.Write(door.Goto(cx, cy+idx) + ab)
 	}
 	d.Write(door.Reset + panel.GotoEnd())
-	_ = d.Key()
+
+	// Pause for key
+	d.Key()
 
 	panel.Lines = make([]door.Line, 0)
 	background := "BUGZ Test Door in GO "
@@ -402,7 +406,7 @@ func width_demo(d *door.Door) {
 		panel.Lines = append(panel.Lines, l)
 	}
 	d.Write(panel.Output())
-	_ = d.Key()
+	d.Key()
 }
 
 func panel_demo(d *door.Door) {
@@ -424,12 +428,18 @@ func panel_demo(d *door.Door) {
 
 	single := 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")})
+	single.Lines = append(single.Lines, single.Spacer())
+	single.Lines = append(single.Lines, door.Line{Text: "More Text ", DefaultColor: door.ColorText("BRI GREEN ON BLACK")})
 
 	ds := 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")})
+	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")})
 
 	sd := 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")})
+	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")})
 
 	d.Write(door.Clrscr)
 	d.Write(p.Output())
@@ -518,7 +528,6 @@ func main() {
 			width_demo(&d)
 		case 'Q':
 			choice = -1
-			break
 		case 'C':
 			z := 0
 			a := 10 / z