Merge pull request #87 from infinytum/master

Add Double Linestyle
This commit is contained in:
Jakub Sobon 2019-01-24 21:02:22 -05:00 committed by GitHub
commit df8734811c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -92,6 +92,37 @@ func TestBorder(t *testing.T) {
return ft
},
},
{
desc: "draws double border around the canvas",
canvas: image.Rect(0, 0, 4, 4),
border: image.Rect(0, 0, 4, 4),
opts: []BorderOption{
BorderLineStyle(LineStyleDouble),
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
c := testcanvas.MustNew(ft.Area())
testcanvas.MustSetCell(c, image.Point{0, 0}, lineStyleChars[LineStyleDouble][topLeftCorner])
testcanvas.MustSetCell(c, image.Point{0, 1}, lineStyleChars[LineStyleDouble][vLine])
testcanvas.MustSetCell(c, image.Point{0, 2}, lineStyleChars[LineStyleDouble][vLine])
testcanvas.MustSetCell(c, image.Point{0, 3}, lineStyleChars[LineStyleDouble][bottomLeftCorner])
testcanvas.MustSetCell(c, image.Point{1, 0}, lineStyleChars[LineStyleDouble][hLine])
testcanvas.MustSetCell(c, image.Point{1, 3}, lineStyleChars[LineStyleDouble][hLine])
testcanvas.MustSetCell(c, image.Point{2, 0}, lineStyleChars[LineStyleDouble][hLine])
testcanvas.MustSetCell(c, image.Point{2, 3}, lineStyleChars[LineStyleDouble][hLine])
testcanvas.MustSetCell(c, image.Point{3, 0}, lineStyleChars[LineStyleDouble][topRightCorner])
testcanvas.MustSetCell(c, image.Point{3, 1}, lineStyleChars[LineStyleDouble][vLine])
testcanvas.MustSetCell(c, image.Point{3, 2}, lineStyleChars[LineStyleDouble][vLine])
testcanvas.MustSetCell(c, image.Point{3, 3}, lineStyleChars[LineStyleDouble][bottomRightCorner])
testcanvas.MustApply(c, ft)
return ft
},
},
{
desc: "draws border in the canvas",
canvas: image.Rect(0, 0, 4, 4),

View File

@ -39,6 +39,19 @@ var lineStyleChars = map[LineStyle]map[linePart]rune{
vAndRight: '├',
vAndH: '┼',
},
LineStyleDouble: {
hLine: '═',
vLine: '║',
topLeftCorner: '╔',
topRightCorner: '╗',
bottomLeftCorner: '╚',
bottomRightCorner: '╝',
hAndUp: '╩',
hAndDown: '╦',
vAndLeft: '╣',
vAndRight: '╠',
vAndH: '╬',
},
}
// init verifies that all line parts are half-width runes (occupy only one
@ -75,13 +88,15 @@ func (ls LineStyle) String() string {
// lineStyleNames maps LineStyle values to human readable names.
var lineStyleNames = map[LineStyle]string{
LineStyleLight: "LineStyleLight",
LineStyleLight: "LineStyleLight",
LineStyleDouble: "LineStyleDouble",
}
// Supported line styles.
const (
LineStyleNone LineStyle = iota
LineStyleLight
LineStyleDouble
)
// linePart identifies individual line parts.