Improve/add comments

This commit is contained in:
Caleb Bassi 2019-02-01 22:16:02 -08:00
parent 71648dedc1
commit 5ece2b7178
4 changed files with 18 additions and 5 deletions

View File

@ -16,7 +16,8 @@ type Grid struct {
Items []*GridItem
}
// GridItem represents either a Row or Column in a grid and holds sizing information and other GridItems or widgets
// GridItem represents either a Row or Column in a grid.
// Holds sizing information and either an []GridItems or a widget.
type GridItem struct {
Type gridItemType
XRatio float64

View File

@ -1,11 +1,15 @@
package termui
// Color is an integer from -1 to 255
// -1 = ColorClear
// 0-255 = Xterm colors
type Color int
// ColorClear clears the Fg or Bg color of a Style
const ColorClear Color = -1
// Basic terminal colors
const (
ColorClear Color = -1
ColorBlack Color = 0
ColorRed Color = 1
ColorGreen Color = 2
@ -19,26 +23,28 @@ const (
type Modifier uint
const (
// ModifierClear clears any modifiers
ModifierClear Modifier = 0
ModifierBold Modifier = 1 << 9
ModifierUnderline Modifier = 1 << 10
ModifierReverse Modifier = 1 << 11
)
// Style represents the look of the text of one terminal cell
// Style represents the style of one terminal cell
type Style struct {
Fg Color
Bg Color
Modifier Modifier
}
// StyleClear represents a default Style, with no colors or modifiers
var StyleClear = Style{
Fg: ColorClear,
Bg: ColorClear,
Modifier: ModifierClear,
}
// NewStyle takes 1 to 3 arguments.
// NewStyle takes 1 to 3 arguments
// 1st argument = Fg
// 2nd argument = optional Bg
// 3rd argument = optional Modifier

View File

@ -49,7 +49,7 @@ var modifierMap = map[string]Modifier{
"reverse": ModifierReverse,
}
// AddColorMap allows users to add/override the string to Coloribute mapping
// AddColorMap allows users to add/override the string to Color mapping
func AddColorMap(str string, color Color) {
colorMap[str] = color
}
@ -74,6 +74,10 @@ func readStyle(runes []rune, defaultStyle Style) Style {
return style
}
// ParseText parses a string for embedded Styles and returns []Cell with the correct styling.
// Uses defaultStyle for any text without an embedded style.
// Syntax is of the form [text](fg:<color>,mod:<attribute>,bg:<color>).
// Ordering does not matter. All fields are optional.
func ParseText(s string, defaultStyle Style) []Cell {
cells := []Cell{}
runes := []rune(s)

View File

@ -94,6 +94,8 @@ type TableTheme struct {
Text Style
}
// Theme holds the default Styles and Colors for all widgets.
// You can set default widget Styles by modifying the Theme before creating the widgets.
var Theme = RootTheme{
Default: NewStyle(ColorWhite),