Skip to content

Commit

Permalink
Merge pull request #87 from infinytum/master
Browse files Browse the repository at this point in the history
Add Double Linestyle
  • Loading branch information
mum4k committed Jan 25, 2019
2 parents 1e1dc15 + 41cbc3c commit df87348
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
31 changes: 31 additions & 0 deletions draw/border_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 16 additions & 1 deletion draw/line_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit df87348

Please sign in to comment.