Browse Source

Use BOXES, which will be set to CP437 or Unicode

This is set automatically after detection.  It makes
boxes and panels easier, no need for if Unicode now.
Steve Thielemann 3 years ago
parent
commit
cc2cd2ee73
3 changed files with 15 additions and 36 deletions
  1. 8 26
      door/box.go
  2. 5 0
      door/door.go
  3. 2 10
      door/panel.go

+ 8 - 26
door/box.go

@@ -18,7 +18,9 @@ type BoxStyle struct {
 // BOXES_CP437 or BOXES_UNICODE.  That'll save us from having
 // BOXES_CP437 or BOXES_UNICODE.  That'll save us from having
 // to if Unicode when building boxes.  ;)
 // to if Unicode when building boxes.  ;)
 
 
-var BOXES = [4]BoxStyle{
+var BOXES [4]BoxStyle
+
+var BOXES_CP437 = [4]BoxStyle{
 	/*
 	/*
 		┌──┐
 		┌──┐
 		│  │
 		│  │
@@ -48,7 +50,7 @@ var BOXES = [4]BoxStyle{
 	*/
 	*/
 	BoxStyle{"\xd6", "\xb7", "\xc4", "\xba", "\xd3", "\xbd", "\xc7", "\xb6"}}
 	BoxStyle{"\xd6", "\xb7", "\xc4", "\xba", "\xd3", "\xbd", "\xc7", "\xb6"}}
 
 
-var BOXES_UNICODE = []BoxStyle{
+var BOXES_UNICODE = [4]BoxStyle{
 	BoxStyle{"\u250c", "\u2510", "\u2500", "\u2502", "\u2514", "\u2518", "\u251c", "\u2524"},
 	BoxStyle{"\u250c", "\u2510", "\u2500", "\u2502", "\u2514", "\u2518", "\u251c", "\u2524"},
 	BoxStyle{"\u2554", "\u2557", "\u2550", "\u2551", "\u255a", "\u255d", "\u2560", "\u2563"},
 	BoxStyle{"\u2554", "\u2557", "\u2550", "\u2551", "\u255a", "\u255d", "\u2560", "\u2563"},
 	BoxStyle{"\u2553", "\u2556", "\u2500", "\u2551", "\u2559", "\u255c", "\u255f", "\u2562"},
 	BoxStyle{"\u2553", "\u2556", "\u2500", "\u2551", "\u2559", "\u255c", "\u255f", "\u2562"},
@@ -61,42 +63,22 @@ type Box struct {
 }
 }
 
 
 func (b *Box) Top() string {
 func (b *Box) Top() string {
-	var style *BoxStyle
-	if Unicode {
-		style = &BOXES_UNICODE[b.Style]
-	} else {
-		style = &BOXES[b.Style]
-	}
+	var style *BoxStyle = &BOXES[b.Style]
 	return style.top_left + strings.Repeat(style.top, b.Width) + style.top_right
 	return style.top_left + strings.Repeat(style.top, b.Width) + style.top_right
 }
 }
 
 
 func (b *Box) Row(text string) string {
 func (b *Box) Row(text string) string {
-	var style *BoxStyle
-	if Unicode {
-		style = &BOXES_UNICODE[b.Style]
-	} else {
-		style = &BOXES[b.Style]
-	}
+	var style *BoxStyle = &BOXES[b.Style]
 	return style.side + text + style.side
 	return style.side + text + style.side
 }
 }
 
 
 func (b *Box) Middle() string {
 func (b *Box) Middle() string {
-	var style *BoxStyle
-	if Unicode {
-		style = &BOXES_UNICODE[b.Style]
-	} else {
-		style = &BOXES[b.Style]
-	}
+	var style *BoxStyle = &BOXES[b.Style]
 	return style.middle_left + strings.Repeat(style.top, b.Width) + style.middle_right
 	return style.middle_left + strings.Repeat(style.top, b.Width) + style.middle_right
 }
 }
 
 
 func (b *Box) Bottom() string {
 func (b *Box) Bottom() string {
-	var style *BoxStyle
-	if Unicode {
-		style = &BOXES_UNICODE[b.Style]
-	} else {
-		style = &BOXES[b.Style]
-	}
+	var style *BoxStyle = &BOXES[b.Style]
 	return style.bottom_left + strings.Repeat(style.top, b.Width) + style.bottom_right
 	return style.bottom_left + strings.Repeat(style.top, b.Width) + style.bottom_right
 }
 }
 
 

+ 5 - 0
door/door.go

@@ -218,6 +218,11 @@ func (d *Door) Init() {
 
 
 	fmt.Printf("BBS %s, User %s / Handle %s / File %d\n", d.Config.BBSID, d.Config.Real_name, d.Config.Handle, d.Config.Comm_handle)
 	fmt.Printf("BBS %s, User %s / Handle %s / File %d\n", d.Config.BBSID, d.Config.Real_name, d.Config.Handle, d.Config.Comm_handle)
 	d.detect()
 	d.detect()
+	if Unicode {
+		BOXES = BOXES_UNICODE
+	} else {
+		BOXES = BOXES_CP437
+	}
 }
 }
 
 
 // Write string to client.
 // Write string to client.

+ 2 - 10
door/panel.go

@@ -30,11 +30,7 @@ func (p *Panel) Output() string {
 	var output string
 	var output string
 
 
 	if style > 0 {
 	if style > 0 {
-		if Unicode {
-			box_style = &BOXES_UNICODE[style-1]
-		} else {
-			box_style = &BOXES[style-1]
-		}
+		box_style = &BOXES[style-1]
 	}
 	}
 
 
 	row := p.Y
 	row := p.Y
@@ -155,10 +151,6 @@ func (p *Panel) Spacer() Line {
 		pos = 1
 		pos = 1
 	}
 	}
 
 
-	if Unicode {
-		l.Text = strings.Repeat(BOXES_UNICODE[pos].top, p.Width)
-	} else {
-		l.Text = strings.Repeat(BOXES[pos].top, p.Width)
-	}
+	l.Text = strings.Repeat(BOXES[pos].top, p.Width)
 	return l
 	return l
 }
 }