forked from scylladb/termtables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
straight_separator.go
36 lines (31 loc) · 1.13 KB
/
straight_separator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2012 Apcera Inc. All rights reserved.
package termtables
import (
"strings"
"unicode/utf8"
)
// A StraightSeparator is a horizontal line with associated information about
// what sort of position it takes in the table, so as to control which shapes
// will be used where vertical lines are expected to touch this horizontal
// line.
type StraightSeparator struct {
where lineType
}
// Render returns a string representing this separator, with all border
// crossings appropriately chosen.
func (s *StraightSeparator) Render(style *renderStyle) string {
// loop over getting dashes
width := 0
for i := 0; i < style.columns; i++ {
width += style.PaddingLeft + style.CellWidth(i) + style.PaddingRight + utf8.RuneCountInString(style.BorderI)
}
switch s.where {
case LINE_TOP:
return style.BorderTopLeft + strings.Repeat(style.BorderX, width-1) + style.BorderTopRight
case LINE_INNER, LINE_SUBTOP:
return style.BorderLeft + strings.Repeat(style.BorderX, width-1) + style.BorderRight
case LINE_BOTTOM:
return style.BorderBottomLeft + strings.Repeat(style.BorderX, width-1) + style.BorderBottomRight
}
panic("not reached")
}