123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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
- }
- var boxes = [4]BoxStyle{
- /*
- ┌──┐
- │ │
- ├──┤
- └──┘
- */
- BoxStyle{"\xda", "\xbf", "\xc4", "\xb3", "\xc0", "\xd9", "\xc3", "\xb4"},
- /*
- ╔══╗
- ║ ║
- ╠══╣
- ╚══╝
- */
- BoxStyle{"\xc9", "\xbb", "\xcd", "\xba", "\xc8", "\xbc", "\xcc", "\xb9"},
- /*
- ╒══╕
- │ │
- ╞══╡
- ╘══╛
- */
- BoxStyle{"\xd6", "\xb8", "\xcd", "\xb3", "\xd4", "\xbe", "\xc6", "\xb5"},
- /*
- ╓──╖
- ║ ║
- ╟──╢
- ╙──╜
- */
- BoxStyle{"\xd6", "\xb7", "\xc4", "\xba", "\xd3", "\xbd", "\xc7", "\xb6"}}
- var unicode_boxes = []BoxStyle{
- BoxStyle{"\u250c", "\u2510", "\u2500", "\u2502", "\u2514", "\u2518", "\u251c", "\u2524"},
- BoxStyle{"\u2554", "\u2557", "\u2550", "\u2551", "\u255a", "\u255d", "\u2560", "\u2563"},
- BoxStyle{"\u2553", "\u2556", "\u2500", "\u2551", "\u2559", "\u255c", "\u255f", "\u2562"},
- BoxStyle{"\u2552", "\u2555", "\u2550", "\u2502", "\u2558", "\u255b", "\u255e", "\u2561"},
- }
- type Box struct {
- Width int
- Style int
- }
- func (b *Box) Top() string {
- var style *BoxStyle
- if Unicode {
- style = &unicode_boxes[b.Style]
- } else {
- style = &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
- if Unicode {
- style = &unicode_boxes[b.Style]
- } else {
- style = &boxes[b.Style]
- }
- return style.side + text + style.side
- }
- func (b *Box) Middle() string {
- var style *BoxStyle
- if Unicode {
- style = &unicode_boxes[b.Style]
- } else {
- style = &boxes[b.Style]
- }
- return style.middle_left + strings.Repeat(style.top, b.Width) + style.middle_right
- }
- func (b *Box) Bottom() string {
- var style *BoxStyle
- if Unicode {
- style = &unicode_boxes[b.Style]
- } else {
- style = &boxes[b.Style]
- }
- return style.bottom_left + strings.Repeat(style.top, b.Width) + style.bottom_right
- }
|