File: straight_separator.go

package info (click to toggle)
golang-github-scylladb-termtables 0.0~git20191203.c4c0b6d-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 184 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (2)
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")
}