diff --git a/src/constants.v b/src/constants.v index 5694723..989afe9 100644 --- a/src/constants.v +++ b/src/constants.v @@ -4,26 +4,26 @@ import term pub const ( // Styles - reset = Style(StyleImpl.reset) - bold = Style(StyleImpl.bold) - dim = Style(StyleImpl.dim) - italic = Style(StyleImpl.italic) - underline = Style(StyleImpl.underline) - slow_blink = Style(StyleImpl.slow_blink) - rapid_blink = Style(StyleImpl.rapid_blink) - inverse = Style(StyleImpl.inverse) - hidden = Style(StyleImpl.hidden) - strikethrough = Style(StyleImpl.strikethrough) + reset = Style(StyleImpl{term.reset}) + bold = Style(StyleImpl{term.bold}) + dim = Style(StyleImpl{term.dim}) + italic = Style(StyleImpl{term.italic}) + underline = Style(StyleImpl{term.underline}) + slow_blink = Style(StyleImpl{term.slow_blink}) + rapid_blink = Style(StyleImpl{term.rapid_blink}) + inverse = Style(StyleImpl{term.inverse}) + hidden = Style(StyleImpl{term.hidden}) + strikethrough = Style(StyleImpl{term.strikethrough}) // Colors - black = Color(BasicColor{term.black, term.bg_black}) - bright_black = Color(BasicColor{term.bright_black, term.bright_bg_black}) - red = Color(BasicColor{term.red, term.bg_red}) - bright_red = Color(BasicColor{term.bright_red, term.bright_bg_red}) - green = Color(BasicColor{term.green, term.bg_green}) - bright_green = Color(BasicColor{term.bright_green, term.bright_bg_green}) - yellow = Color(BasicColor{term.yellow, term.bg_yellow}) - bright_yellow = Color(BasicColor{term.bright_yellow, term.bright_bg_yellow}) - blue = Color(BasicColor{term.blue, term.bg_blue}) + black = Color(BasicColor{term.black, term.bg_black}) + bright_black = Color(BasicColor{term.bright_black, term.bright_bg_black}) + red = Color(BasicColor{term.red, term.bg_red}) + bright_red = Color(BasicColor{term.bright_red, term.bright_bg_red}) + green = Color(BasicColor{term.green, term.bg_green}) + bright_green = Color(BasicColor{term.bright_green, term.bright_bg_green}) + yellow = Color(BasicColor{term.yellow, term.bg_yellow}) + bright_yellow = Color(BasicColor{term.bright_yellow, term.bright_bg_yellow}) + blue = Color(BasicColor{term.blue, term.bg_blue}) bright_blue = Color(BasicColor{term.bright_blue, term.bright_bg_blue}) magenta = Color(BasicColor{term.magenta, term.bg_magenta}) bright_magenta = Color(BasicColor{term.bright_magenta, term.bright_bg_magenta}) diff --git a/src/style.v b/src/style.v index c0144f1..6c3c49d 100644 --- a/src/style.v +++ b/src/style.v @@ -1,7 +1,5 @@ module color -import term - // Style is an interface for a style. pub interface Style { render(string) string // Renders the string with the given style. @@ -17,36 +15,14 @@ pub fn (s Style) println(str string) { println(s.render(str)) } -enum StyleImpl { - reset - bold - dim - italic - underline - slow_blink - rapid_blink - inverse - hidden - strikethrough +struct StyleImpl { + render_fn fn (string) string } fn (s StyleImpl) render(str string) string { return if no_color { str } else { - func := match s { - .reset { term.reset } - .bold { term.bold } - .dim { term.dim } - .italic { term.italic } - .underline { term.underline } - .slow_blink { term.slow_blink } - .rapid_blink { term.rapid_blink } - .inverse { term.inverse } - .hidden { term.hidden } - .strikethrough { term.strikethrough } - } - - func(str) + s.render_fn(str) } }