package door import "strings" type BoxStyle struct { top_left string top_right string top string side string bottom_left string bottom_right string middle_left string middle_right string } // FUTURE: // Once we detect CP437 or Unicode, set BOXES to point to // BOXES_CP437 or BOXES_UNICODE. That'll save us from having // to if Unicode when building boxes. ;) var BOXES [4]BoxStyle var BOXES_CP437 = [4]BoxStyle{ /* ┌──┐ │ │ ├──┤ └──┘ */ BoxStyle{"\xda", "\xbf", "\xc4", "\xb3", "\xc0", "\xd9", "\xc3", "\xb4"}, /* ╔══╗ ║ ║ ╠══╣ ╚══╝ */ BoxStyle{"\xc9", "\xbb", "\xcd", "\xba", "\xc8", "\xbc", "\xcc", "\xb9"}, /* ╒══╕ │ │ ╞══╡ ╘══╛ */ BoxStyle{"\xd5", "\xb8", "\xcd", "\xb3", "\xd4", "\xbe", "\xc6", "\xb5"}, /* ╓──╖ ║ ║ ╟──╢ ╙──╜ */ BoxStyle{"\xd6", "\xb7", "\xc4", "\xba", "\xd3", "\xbd", "\xc7", "\xb6"}, } var BOXES_UNICODE = [4]BoxStyle{ BoxStyle{"\u250c", "\u2510", "\u2500", "\u2502", "\u2514", "\u2518", "\u251c", "\u2524"}, BoxStyle{"\u2554", "\u2557", "\u2550", "\u2551", "\u255a", "\u255d", "\u2560", "\u2563"}, BoxStyle{"\u2552", "\u2555", "\u2550", "\u2502", "\u2558", "\u255b", "\u255e", "\u2561"}, BoxStyle{"\u2553", "\u2556", "\u2500", "\u2551", "\u2559", "\u255c", "\u255f", "\u2562"}, } type Box struct { Width int Style int } func (b *Box) Top() string { var style *BoxStyle = &BOXES[b.Style] return style.top_left + strings.Repeat(style.top, b.Width) + style.top_right } func (b *Box) Row(text string) string { var style *BoxStyle = &BOXES[b.Style] return style.side + text + style.side } func (b *Box) Middle() string { var style *BoxStyle = &BOXES[b.Style] return style.middle_left + strings.Repeat(style.top, b.Width) + style.middle_right } func (b *Box) Bottom() string { var style *BoxStyle = &BOXES[b.Style] return style.bottom_left + strings.Repeat(style.top, b.Width) + style.bottom_right } func AlertBox(text string, style int) []string { var results []string b := Box{Width: StringLen(text), Style: style} results = append(results, b.Top()) results = append(results, b.Row(text)) results = append(results, b.Bottom()) return results }