From 5ece2b7178ff236574c7e88078b42150f724ff70 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Fri, 1 Feb 2019 22:16:02 -0800 Subject: [PATCH] Improve/add comments --- grid.go | 3 ++- style.go | 12 +++++++++--- text_parser.go | 6 +++++- theme.go | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/grid.go b/grid.go index 8f9eb1a..b3a6af2 100644 --- a/grid.go +++ b/grid.go @@ -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 diff --git a/style.go b/style.go index d9bab8e..3f8bb27 100644 --- a/style.go +++ b/style.go @@ -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 diff --git a/text_parser.go b/text_parser.go index bce6411..dc01424 100644 --- a/text_parser.go +++ b/text_parser.go @@ -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:,mod:,bg:). +// Ordering does not matter. All fields are optional. func ParseText(s string, defaultStyle Style) []Cell { cells := []Cell{} runes := []rune(s) diff --git a/theme.go b/theme.go index ef2ad7a..c9a5094 100644 --- a/theme.go +++ b/theme.go @@ -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),