Explorar o código

Code cleanup. More var, less :=

Steve Thielemann %!s(int64=2) %!d(string=hai) anos
pai
achega
48cc0a9271

+ 15 - 8
door/door.go

@@ -110,7 +110,10 @@ func (d *Door) Disconnect() bool {
 
 // Read the BBS door file.  We only support door32.sys.
 func (d *Door) ReadDropfile(filename string) {
-	file, err := os.Open(filename)
+	var file *os.File
+	var err error
+
+	file, err = os.Open(filename)
 	if err != nil {
 		log.Panicf("Open(%s): %s\n", filename, err)
 	}
@@ -121,7 +124,7 @@ func (d *Door) ReadDropfile(filename string) {
 	// read line by line
 	// The scanner handles DOS and linux file endings.
 
-	scanner := bufio.NewScanner(file)
+	var scanner *bufio.Scanner = bufio.NewScanner(file)
 	for scanner.Scan() {
 		line := scanner.Text()
 		lines = append(lines, line)
@@ -185,7 +188,8 @@ func (d *Door) detect() {
 	var results string
 
 	for {
-		r := d.getch()
+		var r int
+		r = d.getch()
 		if r < 0 {
 			break
 		}
@@ -214,7 +218,7 @@ func (d *Door) detect() {
 	}
 
 	// get screen size
-	pos := strings.LastIndex(results, "\x1b")
+	var pos int = strings.LastIndex(results, "\x1b")
 	if pos != -1 {
 		pos++
 		if results[pos] == '[' {
@@ -222,7 +226,7 @@ func (d *Door) detect() {
 			results = results[pos:]
 			pos = strings.Index(results, ";")
 			if pos != -1 {
-				height := results[:pos]
+				var height string = results[:pos]
 				Height, _ = strconv.Atoi(height)
 				pos++
 				results = results[pos:]
@@ -249,7 +253,8 @@ func (d *Door) Init(doorname string) {
 	d.Pushback = NewFIFOBuffer(5)
 
 	// Get path to binary, and chdir to it.
-	binaryPath, _ := os.Executable()
+	var binaryPath string
+	binaryPath, _ = os.Executable()
 	binaryPath = filepath.Dir(binaryPath)
 	_ = os.Chdir(binaryPath)
 
@@ -263,8 +268,10 @@ func (d *Door) Init(doorname string) {
 	d.ReadDropfile(dropfile)
 
 	// Logfile will be doorname - node #
-	logfilename := fmt.Sprintf("%s-%d.log", doorname, d.Config.Node)
-	logf, err := os.OpenFile(logfilename, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
+	var logfilename string = fmt.Sprintf("%s-%d.log", doorname, d.Config.Node)
+	var logf *os.File
+	var err error
+	logf, err = os.OpenFile(logfilename, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
 	if err != nil {
 		log.Panicf("Error creating log file %s: %v", logfilename, err)
 	}

+ 1 - 0
door/help_test.go

@@ -6,6 +6,7 @@ import (
 
 // testing helper routines
 
+// setupSockets: return server and client (that's connected to server)
 func setupSockets() (server net.Conn, client net.Conn) {
 	// establish network socket connection to set Comm_handle
 	var err error

+ 3 - 3
door/input.go

@@ -61,7 +61,7 @@ func (d *Door) getkey_or_pushback() int {
 	}
 
 	if false {
-		key := d.getch()
+		var key int = d.getch()
 		log.Printf("%d / %X\n", key, key)
 		return key
 	} else {
@@ -105,7 +105,7 @@ func (d *Door) GetKey() int {
 
 	if c == 0 {
 		// possibly doorway mode
-		tries := 0
+		var tries int = 0
 		c2 = d.getkey_or_pushback()
 		for c2 < 0 {
 			if tries > 7 {
@@ -273,7 +273,7 @@ func (d *Door) WaitKey(secs int64, usecs int64) int {
 		return d.GetKey()
 	}
 
-	timeout := time.Duration(secs)*time.Second + time.Duration(usecs)*time.Microsecond
+	var timeout time.Duration = time.Duration(secs)*time.Second + time.Duration(usecs)*time.Microsecond
 
 	select {
 	case res, ok := <-d.readerChannel:

+ 4 - 2
door/input_linux.go

@@ -21,9 +21,11 @@ func Reader(handle int, d *Door) {
 		}
 	}()
 
-	buffer := make([]byte, 1)
+	var buffer []byte = make([]byte, 1)
 	for {
-		read, err := syscall.Read(handle, buffer)
+		var read int
+		var err error
+		read, err = syscall.Read(handle, buffer)
 		if err != nil {
 			log.Printf("Reader ERR: %#v\n", err)
 			close(d.readerChannel)

+ 1 - 1
door/input_windows.go

@@ -23,7 +23,7 @@ func Reader(d *Door) {
 		}
 	}()
 
-	buffer := make([]byte, 1)
+	var buffer []byte = make([]byte, 1)
 	WSA_Buffer := syscall.WSABuf{Len: 1, Buf: &buffer[0]}
 	read := uint32(0)
 	flags := uint32(0)

+ 3 - 3
door/line.go

@@ -87,7 +87,7 @@ func (l *Line) Update() bool {
 	if l.UpdateF == nil {
 		return false
 	}
-	NewText := l.UpdateF()
+	var NewText string = l.UpdateF()
 	if NewText != l.Text {
 		l.Text = NewText
 		return true
@@ -168,8 +168,8 @@ func (r *Render) Append(color string, len int) {
 func RenderBlueYellow(text string) string {
 	var r Render = Render{Line: text}
 
-	blue := ColorText("BOLD BLUE")
-	yellow := ColorText("BOLD YELLOW")
+	var blue string = ColorText("BOLD BLUE")
+	var yellow string = ColorText("BOLD YELLOW")
 
 	for _, letter := range text {
 		if unicode.IsUpper(letter) {

+ 9 - 10
door/line_test.go

@@ -6,9 +6,9 @@ import (
 )
 
 func TestLine(t *testing.T) {
-	line := Line{Text: "Test Me"}
-	output := line.Output()
-	expect := "Test Me"
+	var line Line = Line{Text: "Test Me"}
+	var output string = line.Output()
+	var expect string = "Test Me"
 
 	if output != expect {
 		t.Errorf("Line: Expected %#v, got %#v", expect, output)
@@ -30,8 +30,8 @@ func TestLine(t *testing.T) {
 	// line.DefaultColor = ""
 	line.RenderF = RenderBlueYellow
 	output = line.Output()
-	blue := ColorText("BOLD BLUE")
-	yellow := ColorText("BOLD YELLOW")
+	var blue string = ColorText("BOLD BLUE")
+	var yellow string = ColorText("BOLD YELLOW")
 
 	expect = blue + "T" + yellow + "est " + blue + "M" + yellow + "e"
 	if output != expect {
@@ -41,14 +41,14 @@ func TestLine(t *testing.T) {
 }
 
 func TestLineUpdate(t *testing.T) {
-	counter := 0
+	var counter int = 0
 	uf := func() string {
 		return fmt.Sprintf("Count: %d", counter)
 	}
-	line := Line{Text: "", UpdateF: uf}
+	var line Line = Line{Text: "", UpdateF: uf}
 	line.Update()
-	output := line.Output()
-	expect := "Count: 0"
+	var output string = line.Output()
+	var expect string = "Count: 0"
 
 	if output != expect {
 		t.Errorf("LineUpdate: Expected %#v, got %#v", expect, output)
@@ -69,5 +69,4 @@ func TestLineUpdate(t *testing.T) {
 	if output != expect {
 		t.Errorf("LineUpdate: Expected %#v, got %#v", expect, output)
 	}
-
 }

+ 4 - 0
door/menu.go

@@ -18,6 +18,7 @@ type Menu struct {
 	SelectedR   func(string) string
 	UnselectedR func(string) string
 	Options     []rune
+	Activated   func(int, *Door) // Which option is active
 	// MenuOptions []MenuOption
 	Panel
 }
@@ -128,6 +129,9 @@ func (m *Menu) Choose(d *Door) int {
 				}
 				d.Write(m.GotoEnd() + blank)
 			}
+			if m.Activated != nil {
+				m.Activated(m.Chosen, d)
+			}
 		}
 
 		if update_and_exit {

+ 24 - 18
door/menu_test.go

@@ -4,6 +4,7 @@ import (
 	"flag"
 	"fmt"
 	"io/ioutil"
+	"net"
 	"os"
 	"runtime"
 	"strings"
@@ -12,16 +13,17 @@ import (
 )
 
 func TestMenuRender(t *testing.T) {
-	bracket := ColorText("BLUE")
-	option := ColorText("BRI GREEN")
-	upper := ColorText("CYAN")
-	lower := ColorText("MAGENTA")
+	var bracket string = ColorText("BLUE")
+	var option string = ColorText("BRI GREEN")
+	var upper string = ColorText("CYAN")
+	var lower string = ColorText("MAGENTA")
+
+	var render func(string) string = MakeMenuRender(bracket, option, upper, lower)
 
-	render := MakeMenuRender(bracket, option, upper, lower)
 	// Fake menu line
-	input := "[X] BUGZ test"
-	got := render(input)
-	expected := bracket + "[" + option + "X" + bracket + "]"
+	var input string = "[X] BUGZ test"
+	var got string = render(input)
+	var expected string = bracket + "[" + option + "X" + bracket + "]"
 	expected += lower + " " + upper + "BUGZ" + lower + " test"
 
 	if got != expected {
@@ -36,7 +38,7 @@ func TestMenuSize(t *testing.T) {
 		}
 	}()
 
-	m := Menu{Panel: Panel{Width: 5,
+	var m Menu = Menu{Panel: Panel{Width: 5,
 		X:     1,
 		Y:     1,
 		Style: DOUBLE,
@@ -47,7 +49,9 @@ func TestMenuSize(t *testing.T) {
 }
 
 func TestMenuConnection(t *testing.T) {
-	tmpFile, err := ioutil.TempFile(os.TempDir(), "test-")
+	var tmpFile *os.File
+	var err error
+	tmpFile, err = ioutil.TempFile(os.TempDir(), "test-")
 	if err != nil {
 		panic("Cannot create temporary file")
 	}
@@ -56,14 +60,15 @@ func TestMenuConnection(t *testing.T) {
 	defer os.Remove(tmpFile.Name())
 
 	// establish network socket connection to set Comm_handle
-	server, client := setupSockets()
+	var server, client net.Conn
+	server, client = setupSockets()
 
 	// We're not testing closed connections, so:
 	defer server.Close()
 	defer client.Close()
 
 	// pre-load unicode 90x40 response
-	buffer := []byte("\x1b[1;1R\x1b[2;3R\x1b[40;90R")
+	var buffer []byte = []byte("\x1b[1;1R\x1b[2;3R\x1b[40;90R")
 	server.Write(buffer)
 	runtime.Gosched()
 
@@ -72,14 +77,14 @@ func TestMenuConnection(t *testing.T) {
 	defer close_fd(fd)
 
 	// Create door32.sys file
-	dfc := DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, 12}
+	var dfc DropfileConfig = DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, 12}
 
 	tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n",
 		dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle,
 		dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node))
 	tmpFile.Close()
 
-	d := Door{ReaderCanClose: true}
+	var d Door = Door{ReaderCanClose: true}
 	// If I call d.Init() more then once flag complains about flag redefined.
 	// Reset flags
 	flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
@@ -115,7 +120,7 @@ func TestMenuConnection(t *testing.T) {
 	server.SetReadDeadline(time.Time{})
 
 	// Ready to test!
-	m := Menu{Panel: Panel{Width: 10,
+	var m Menu = Menu{Panel: Panel{Width: 10,
 		X:     2,
 		Y:     2,
 		Style: DOUBLE,
@@ -137,7 +142,7 @@ func TestMenuConnection(t *testing.T) {
 
 	// preload the key buffer with commands
 	// BUG:  I can't use \x1b[A because of the way extended codes work there.
-	keys := "\x00\x50\x00\x50\r" // down, down, ENTER
+	var keys string = "\x00\x50\x00\x50\r" // down, down, ENTER
 	server.Write([]byte(keys))
 	time.Sleep(time.Millisecond)
 	runtime.Gosched()
@@ -150,7 +155,7 @@ func TestMenuConnection(t *testing.T) {
 		t.Errorf("Error <0 from Choose: %d", choice)
 	}
 
-	option := m.GetOption(choice)
+	var option rune = m.GetOption(choice)
 
 	if choice != 3 {
 		t.Errorf("Expected menu option 3, got %d / %c", choice, option)
@@ -162,7 +167,8 @@ func TestMenuConnection(t *testing.T) {
 
 	// Read the display output
 	server.SetReadDeadline(time.Now().Add(time.Millisecond * 50))
-	r, err := server.Read(buffer)
+	var r int
+	r, err = server.Read(buffer)
 	if err != nil {
 		t.Errorf("server.Read: %s", err)
 	}

+ 2 - 1
door/nomoresecrets.go

@@ -185,7 +185,8 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 			var pos int = 0
 
 			for idx, char := range work {
-				_, found := revealpos[idx]
+				var found bool
+				_, found = revealpos[idx]
 				if found {
 					for charpos[pos] != idx {
 						pos++

+ 25 - 0
door/nomoresecrets_test.go

@@ -0,0 +1,25 @@
+package door
+
+import (
+	"math/rand"
+	"testing"
+)
+
+func TestRandom(t *testing.T) {
+	rand.Seed(10)
+	var byteBuffer []byte
+	var expectBuffer []byte = []byte{0x61, 0xb5, 0xc8, 0xac, 0x79, 0x39, 0xde, 0xda, 0x62, 0xd3, 0x90, 0x4c, 0x63, 0x72, 0xa7, 0x93, 0x9b, 0xb0, 0x9c, 0x9d, 0x31, 0xd5, 0xbb, 0x9a, 0x32, 0xc4, 0x41, 0x77, 0x9d, 0xb1, 0xc3, 0x36, 0x8e, 0x63, 0xc7, 0xdd, 0x6c, 0xab, 0x80, 0x9a, 0x32, 0xc4, 0xa5, 0x9b, 0xa9, 0x60, 0xa8, 0xaa, 0xbc, 0xca, 0x85, 0x70, 0x7e, 0xd2, 0x2a, 0x3c, 0x6f, 0xab, 0x2c, 0xa5, 0x6f, 0x33, 0x89, 0xc7, 0x47, 0x5d, 0xbf, 0x50, 0x76, 0x2b, 0xd9, 0x2e, 0xdc, 0xae, 0xbb, 0xd6, 0x59, 0xda, 0x8a, 0xde, 0x38, 0xae, 0xd4, 0xa9, 0x8d, 0x65, 0xbc, 0x7d, 0xbe, 0xd4, 0xb2, 0x88, 0xb4, 0x39, 0xce, 0xb9, 0xb8, 0x26, 0x93, 0x5b}
+	byteBuffer = make([]byte, 100)
+	var x int
+	for x = 0; x < 100; x++ {
+		byteBuffer[x] = getRandom()
+		if expectBuffer[x] != byteBuffer[x] {
+			t.Errorf("%d %d != %d\n", x, expectBuffer[x], byteBuffer[x])
+		}
+	}
+
+}
+
+func TestNoMoreSecrets(t *testing.T) {
+
+}

+ 12 - 9
door/panel.go

@@ -37,7 +37,7 @@ func (p *Panel) Output() string {
 		box_style = &BOXES[style-1]
 	}
 
-	row := p.Y
+	var row int = p.Y
 	if style > 0 {
 		// Top line / border
 		output += Goto(p.X, row) + p.BorderColor + box_style.top_left
@@ -90,9 +90,10 @@ func (p *Panel) Output() string {
 func (p *Panel) Update() string {
 	var output string
 	var style int = int(p.Style)
+	var row, col int
 
-	row := p.Y
-	col := p.X
+	row = p.Y
+	col = p.X
 	if style > 0 {
 		row++
 		col++
@@ -114,22 +115,24 @@ func (p *Panel) UpdateLine(index int) string {
 	var style int = int(p.Style)
 
 	p.Lines[index].Update()
+	var row, col int
 
-	row := p.Y + index
-	col := p.X
+	row = p.Y + index
+	col = p.X
 	if style > 0 {
 		row++
 		col++
 	}
-	line := &p.Lines[index]
+	var line *Line = &p.Lines[index]
 	output += Goto(col, row) + line.Output()
 	return output
 }
 
 // Goto the end
 func (p *Panel) GotoEnd() string {
-	row := p.Y
-	col := p.X
+	var row, col int
+	row = p.Y
+	col = p.X
 	if p.Style > 0 {
 		row++
 		col += 2
@@ -152,7 +155,7 @@ func Single(bs BorderStyle) bool {
 
 // Create a spacer line that will be connected maybe to the sides.
 func (p *Panel) Spacer() Line {
-	l := Line{}
+	var l Line = Line{}
 	var pos int
 
 	if Single(p.Style) {

+ 14 - 14
door/panel_test.go

@@ -7,18 +7,18 @@ import (
 )
 
 func TestPanel(t *testing.T) {
-	p := Panel{X: 5, Y: 7, Width: 10, Style: DOUBLE, Title: "Test"}
+	var p Panel = Panel{X: 5, Y: 7, Width: 10, Style: DOUBLE, Title: "Test"}
 	p.Lines = append(p.Lines, Line{Text: "1234567890"})
 	p.Lines = append(p.Lines, Line{Text: "abcdefghij"})
 
-	expected := Goto(5, 7) + "╔Test══════╗" + Goto(5, 8) + "║1234567890║" + Goto(5, 9) + "║abcdefghij║" + Goto(5, 10) + "╚══════════╝"
-	got := p.Output()
+	var expected string = Goto(5, 7) + "╔Test══════╗" + Goto(5, 8) + "║1234567890║" + Goto(5, 9) + "║abcdefghij║" + Goto(5, 10) + "╚══════════╝"
+	var got string = p.Output()
 
-	es := strings.SplitAfter(expected, "5H")
-	gs := strings.SplitAfter(got, "5H")
+	var es []string = strings.SplitAfter(expected, "5H")
+	var gs []string = strings.SplitAfter(got, "5H")
 
 	for idx, exp := range es {
-		g := gs[idx]
+		var g string = gs[idx]
 		if g != exp {
 			t.Errorf("Panel expected %#v, got %#v", exp, g)
 		}
@@ -35,27 +35,27 @@ func TestPanel(t *testing.T) {
 }
 
 func TestPanelSpacer(t *testing.T) {
-	p := Panel{X: 1, Y: 1, Width: 5, Style: SINGLE}
+	var p Panel = Panel{X: 1, Y: 1, Width: 5, Style: SINGLE}
 	p.Lines = append(p.Lines, p.Spacer())
-	expected := Goto(1, 1) + "┌─────┐" + Goto(1, 2) + "├─────┤" + Goto(1, 3) + "└─────┘"
-	got := p.Output()
+	var expected string = Goto(1, 1) + "┌─────┐" + Goto(1, 2) + "├─────┤" + Goto(1, 3) + "└─────┘"
+	var got string = p.Output()
 	if expected != got {
 		t.Errorf("Panel Spacer expected %#v, got %#v", expected, got)
 	}
 }
 
 func TestPanelUpdate(t *testing.T) {
-	p := Panel{X: 2, Y: 2, Width: 3, Style: DOUBLE_SINGLE}
+	var p Panel = Panel{X: 2, Y: 2, Width: 3, Style: DOUBLE_SINGLE}
 	var x int = 0
-	updater := func() string {
+	var updater func() string = func() string {
 		return fmt.Sprintf("%3d", x)
 	}
-	l := Line{UpdateF: updater}
+	var l Line = Line{UpdateF: updater}
 	l.Update()
 	p.Lines = append(p.Lines, l)
 
-	expected := Goto(2, 2) + "╒═══╕" + Goto(2, 3) + "│  0│" + Goto(2, 4) + "╘═══╛"
-	got := p.Output()
+	var expected string = Goto(2, 2) + "╒═══╕" + Goto(2, 3) + "│  0│" + Goto(2, 4) + "╘═══╛"
+	var got string = p.Output()
 
 	if expected != got {
 		t.Errorf("Panel Update expected %#v, got %#v", expected, got)

+ 26 - 24
door/tdfont.go

@@ -33,7 +33,7 @@ func normalizeBlock(block *[][]byte) {
 	var max int
 	// StringO(block)
 	for _, line := range *block {
-		l := len(line)
+		var l int = len(line)
 		if max < l {
 			max = l
 		}
@@ -63,7 +63,7 @@ func (bf *BlockFont) GetCharacter(c int) [][]byte {
 	// 33-126 are the possible characters.
 	if c >= 33 && c <= 126 {
 		c -= 33
-		idx := bf.Characters[c]
+		var idx int = bf.Characters[c]
 		if idx == -1 {
 			// This character is not supported by this font.
 			return result
@@ -80,8 +80,8 @@ func (bf *BlockFont) GetCharacter(c int) [][]byte {
 
 func expandBlock(block *[][]byte) {
 	// l := len((*block)[0])
-	l := len((*block)[0])
-	blank := []byte{0x20}
+	var l int = len((*block)[0])
+	var blank []byte = []byte{0x20}
 	*block = append(*block, bytes.Repeat(blank, l))
 }
 
@@ -94,7 +94,7 @@ func (bf *BlockFont) Output(input string) ([]string, int) {
 		// fmt.Printf("%d %x\n", ch, ch)
 		block := bf.GetCharacter(int(ch))
 		// fmt.Println("ok")
-		l := len(block)
+		var l int = len(block)
 		max += l
 		if l != 0 {
 			if len(out) == 0 {
@@ -162,7 +162,7 @@ func normalizeColor(block *[][]byte) int {
 	}
 	for idx := range *block {
 		// l := len(line)
-		blank := []byte{0x20, 0x0f}
+		var blank []byte = []byte{0x20, 0x0f}
 		for len((*block)[idx]) < max {
 			(*block)[idx] = append((*block)[idx], blank...)
 
@@ -181,14 +181,14 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
 	var result [][]byte
 
 	if c == 32 {
-		blank := []byte{0x20, 0x0f, 0x20, 0x0f}
+		var blank []byte = []byte{0x20, 0x0f, 0x20, 0x0f}
 		result = append(result, blank) // " \x0f \x0f")
 		return result, len(result[0]) / 2
 	}
 
 	if c >= 33 && c <= 126 {
 		c -= 33
-		idx := cf.Characters[c]
+		var idx int = cf.Characters[c]
 		if idx == -1 {
 			return result, 0
 		}
@@ -196,7 +196,7 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
 		// fmt.Println("Character:")
 		// BytesArrayHexed(&result)
 		// fmt.Println("normalizing...")
-		max := normalizeColor(&result)
+		var max int = normalizeColor(&result)
 		// BytesArrayHexed(&result)
 		// StringHexO(&result)
 		return result, max
@@ -206,7 +206,7 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
 }
 
 func thedraw_to_ansi(c int) int {
-	trans := []int{0, 4, 2, 6, 1, 5, 3, 7}
+	var trans []int = []int{0, 4, 2, 6, 1, 5, 3, 7}
 	//             0, 1, 2, 3, 4, 5, 6, 7
 	return trans[c]
 }
@@ -237,8 +237,8 @@ func ColorSplit(color int) ColorParts {
 }
 
 func ColorOutput(previous int, color int) string {
-	prev := ColorSplit(previous)
-	c := ColorSplit(color)
+	var prev ColorParts = ColorSplit(previous)
+	var c ColorParts = ColorSplit(color)
 	var codes []int8
 
 	if c.Bold {
@@ -287,10 +287,10 @@ func Colorize(input []byte) []byte {
 	// BytesHexed(input)
 
 	for pos := 0; pos < len(input); pos += 2 {
-		ch := input[pos]
-		color := int(input[pos+1])
+		var ch byte = input[pos]
+		var color int = int(input[pos+1])
 		// fmt.Printf("%d : CH %d / %x, Color %d / %x\n", pos, ch, ch, color, color)
-		colorstring := ColorOutput(previous, color)
+		var colorstring string = ColorOutput(previous, color)
 		result = append(result, []byte(colorstring)...)
 		/*
 			for _, c := range []byte(colorstring) {
@@ -317,7 +317,7 @@ func __expandColor(block *[]string, need int) {
 */
 
 func expandColor(block *[][]byte, need int) {
-	blank := []byte{0x20, 0x0f}
+	var blank []byte = []byte{0x20, 0x0f}
 	// *block = append(*block, strings.Repeat(" \x0f", need))
 	*block = append(*block, bytes.Repeat(blank, need))
 }
@@ -328,12 +328,14 @@ func (bf *ColorFont) Output(input string) ([]string, int) {
 
 	for _, ch := range input {
 		// fmt.Printf("%d %x\n", ch, ch)
-		block, blklen := bf.GetCharacter(int(ch))
+		var block [][]byte
+		var blklen int
+		block, blklen = bf.GetCharacter(int(ch))
 		if blklen == 0 {
 			continue
 		}
 
-		l := len(block)
+		var l int = len(block)
 		max += blklen
 		if l != 0 {
 			if len(out) == 0 {
@@ -366,7 +368,7 @@ func (bf *ColorFont) Output(input string) ([]string, int) {
 					panic(fmt.Sprintf("len(out) %d != len(block) %d", len(out), len(block)))
 				}
 
-				blank := []byte{0x20, 0x0f}
+				var blank []byte = []byte{0x20, 0x0f}
 				// Ok, we have something!
 				for idx, b := range block {
 					/*
@@ -450,15 +452,15 @@ func (cf *ColorFont) Scan(find_color int) ColorMap {
 	var Targets ColorMap = make(ColorMap, 0)
 	// Scan the font looking for the given color FG/BG
 	// Covert color code to TheDraw Color
-	actual := byte(thedraw_to_ansi(find_color))
+	var actual byte = byte(thedraw_to_ansi(find_color))
 
 	for charIndex := range cf.Data {
 		for lineIndex := range cf.Data[charIndex] {
 			var found bool = false
 			var patches [][2]int = make([][2]int, 0)
 			for offset := 1; offset < len(cf.Data[charIndex][lineIndex]); offset += 2 {
-				color := cf.Data[charIndex][lineIndex][offset]
-				style := MatchStyle(color, actual)
+				var color byte = cf.Data[charIndex][lineIndex][offset]
+				var style int = MatchStyle(color, actual)
 				if style != 0 {
 					// log.Printf("color: %x actual %x style: %d\n", color, actual, style)
 					patches = append(patches, [2]int{offset, style})
@@ -466,7 +468,7 @@ func (cf *ColorFont) Scan(find_color int) ColorMap {
 				}
 			}
 			if found {
-				pos := [2]int{charIndex, lineIndex}
+				var pos [2]int = [2]int{charIndex, lineIndex}
 				Targets[pos] = make([][2]int, len(patches))
 				for i := range patches {
 					Targets[pos][i] = patches[i]
@@ -482,7 +484,7 @@ func (cf *ColorFont) Scan(find_color int) ColorMap {
 // Scan.
 func (cf *ColorFont) Modify(new_color int, Targets ColorMap) {
 	// Covert color code to TheDraw Color
-	actual := byte(thedraw_to_ansi(new_color))
+	var actual byte = byte(thedraw_to_ansi(new_color))
 	for pos, patch := range Targets {
 		for _, p := range patch {
 			cf.Data[pos[0]][pos[1]][p[0]] = PatchColor(cf.Data[pos[0]][pos[1]][p[0]], actual, p[1])

+ 6 - 6
door/write.go

@@ -21,18 +21,18 @@ func find_ansicolor(text string) [][]int {
 	var color_codes [][]int
 
 	// word, _ := regexp.Compile("\x1b\\[([0-9;]+)m")
-	colors := FindANSIColor.FindAllStringIndex(text, -1)
+	var colors [][]int = FindANSIColor.FindAllStringIndex(text, -1)
 	// regexp seems to be ignoring the capture groups.
 	// colors := word.FindAllSubmatchIndex([]byte(text), len(text))
 	for _, pos := range colors {
-		txt := text[pos[0]+2 : pos[1]-1]
+		var txt string = text[pos[0]+2 : pos[1]-1]
 		if txt == "" {
 			txt = "0"
 		}
 		// log.Printf("Text: [%s]\n", txt)
-		codes := strings.Split(txt, ";")
+		var codes []string = strings.Split(txt, ";")
 		// log.Printf("Codes: [%#v]\n", codes)
-		code := make([]int, len(codes))
+		var code []int = make([]int, len(codes))
 		for idx, c := range codes {
 			var err error
 			code[idx], err = strconv.Atoi(c)
@@ -81,8 +81,8 @@ func ParseColorArray(colorarray []int) ANSIColorParts {
 func (d *Door) UpdateLastColor(output string, LastColor *[]int) {
 	// use the last color information + whatever is in the string to
 	// track the last color set
-	updated := ParseColorArray(*LastColor)
-	colors := find_ansicolor(output)
+	var updated ANSIColorParts = ParseColorArray(*LastColor)
+	var colors [][]int = find_ansicolor(output)
 	for _, codes := range colors {
 		if codes[0] == 0 {
 			updated = ParseColorArray(codes)

+ 6 - 5
door/write_windows.go

@@ -43,13 +43,14 @@ func Writer(d *Door) {
 					d.UpdateLastColor(output, &d.LastColor)
 				}
 
-				l := uint32(len(output))
-				buffer := []byte(output)
+				var l uint32 = uint32(len(output))
+				var buffer []byte = []byte(output)
 				WSA_Buffer := syscall.WSABuf{Len: uint32(l), Buf: &buffer[0]}
 
-				UitnZero_1 := uint32(0)
-				DataWrite := uint32(0)
-				err := syscall.WSASend(handle, &WSA_Buffer, 1, &DataWrite, UitnZero_1, nil, nil)
+				var UitnZero_1 uint32 = uint32(0)
+				var DataWrite uint32 = uint32(0)
+				var err error
+				err = syscall.WSASend(handle, &WSA_Buffer, 1, &DataWrite, UitnZero_1, nil, nil)
 				if err != nil {
 					fmt.Printf("write: %d bytes, error: %#v\n", DataWrite, err)
 				}