File: grid.go

package info (click to toggle)
golang-github-achannarasappa-term-grid 0.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 762 bytes parent folder | download
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
// Package grid provides the functionality to render a configurable text grid
// for use in terminal UI application
package grid

import "strings"

// Grid contains settings that apply to the entire grid
type Grid struct {
	Rows             []Row
	GutterVertical   int
	GutterHorizontal int
}

type gridConfig struct {
	widthGutter int
}

// Renders a grid based on the settings defined by the argument Grid, Row(s), and Cell(s)
// Outputs a string with the settings applied
func Render(grid Grid) string {

	var rows = make([]string, 0)

	config := gridConfig{
		widthGutter: grid.GutterHorizontal,
	}

	for _, row := range grid.Rows {
		rows = append(rows, renderRow(row, config))
	}

	return strings.Join(rows, strings.Repeat("\n", 1+grid.GutterVertical))

}