lockbox

password manager
Log | Files | Refs | README | LICENSE

commit a541992fcbdf9f8b9293d8b1db02b8d7b0a146e2
parent af1b350bac0db5f0bb5533a4b19e85474c4538aa
Author: Sean Enck <sean@ttypty.com>
Date:   Sat, 16 Jul 2022 10:50:30 -0400

color restructure

Diffstat:
Dinternal/colors/colors.go | 46----------------------------------------------
Ainternal/colors/core.go | 11+++++++++++
Ainternal/colors/terminal.go | 42++++++++++++++++++++++++++++++++++++++++++
Rinternal/colors/colors_test.go -> internal/colors/terminal_test.go | 0
4 files changed, 53 insertions(+), 46 deletions(-)

diff --git a/internal/colors/colors.go b/internal/colors/colors.go @@ -1,46 +0,0 @@ -package colors - -import ( - "errors" - "github.com/enckse/lockbox/internal/inputs" -) - -const ( - termBeginRed = "\033[1;31m" - termEndRed = "\033[0m" - // Red will get red terminal coloring. - Red = iota -) - -type ( - // Color are terminal colors for dumb terminal coloring. - Color int - // Terminal represents terminal coloring information. - Terminal struct { - Start string - End string - } -) - -// NewTerminal will retrieve start/end terminal coloration indicators. -func NewTerminal(color Color) (Terminal, error) { - if color != Red { - return Terminal{}, errors.New("bad color") - } - interactive, err := inputs.IsInteractive() - if err != nil { - return Terminal{}, err - } - colors := interactive - if colors { - isColored, err := inputs.IsColorEnabled() - if err != nil { - return Terminal{}, err - } - colors = !isColored - } - if colors { - return Terminal{Start: termBeginRed, End: termEndRed}, nil - } - return Terminal{}, nil -} diff --git a/internal/colors/core.go b/internal/colors/core.go @@ -0,0 +1,11 @@ +package colors + +const ( + // Red will get red terminal coloring. + Red = iota +) + +type ( + // Color are terminal colors for dumb terminal coloring. + Color int +) diff --git a/internal/colors/terminal.go b/internal/colors/terminal.go @@ -0,0 +1,42 @@ +package colors + +import ( + "errors" + "github.com/enckse/lockbox/internal/inputs" +) + +const ( + termBeginRed = "\033[1;31m" + termEndRed = "\033[0m" +) + +type ( + // Terminal represents terminal coloring information. + Terminal struct { + Start string + End string + } +) + +// NewTerminal will retrieve start/end terminal coloration indicators. +func NewTerminal(color Color) (Terminal, error) { + if color != Red { + return Terminal{}, errors.New("bad color") + } + interactive, err := inputs.IsInteractive() + if err != nil { + return Terminal{}, err + } + colors := interactive + if colors { + isColored, err := inputs.IsColorEnabled() + if err != nil { + return Terminal{}, err + } + colors = !isColored + } + if colors { + return Terminal{Start: termBeginRed, End: termEndRed}, nil + } + return Terminal{}, nil +} diff --git a/internal/colors/colors_test.go b/internal/colors/terminal_test.go