mirror of
https://github.com/RGBCube/color.v
synced 2025-07-30 17:37:45 +00:00
Simplify BasicColor
This commit is contained in:
parent
5cced43da9
commit
f6421f6aaa
2 changed files with 29 additions and 96 deletions
75
src/color.v
75
src/color.v
|
@ -55,75 +55,8 @@ fn (c TrueColor) render_bg(str string) string {
|
|||
}
|
||||
}
|
||||
|
||||
enum BasicColor {
|
||||
black
|
||||
bright_black
|
||||
red
|
||||
bright_red
|
||||
green
|
||||
bright_green
|
||||
yellow
|
||||
bright_yellow
|
||||
blue
|
||||
bright_blue
|
||||
magenta
|
||||
bright_magenta
|
||||
cyan
|
||||
bright_cyan
|
||||
white
|
||||
bright_white
|
||||
}
|
||||
|
||||
fn (c BasicColor) render(str string) string {
|
||||
return if no_color {
|
||||
str
|
||||
} else {
|
||||
func := match c {
|
||||
.black { term.black }
|
||||
.red { term.red }
|
||||
.green { term.green }
|
||||
.yellow { term.yellow }
|
||||
.blue { term.blue }
|
||||
.magenta { term.magenta }
|
||||
.cyan { term.cyan }
|
||||
.white { term.white }
|
||||
.bright_black { term.bright_black }
|
||||
.bright_red { term.bright_red }
|
||||
.bright_green { term.bright_green }
|
||||
.bright_yellow { term.bright_yellow }
|
||||
.bright_blue { term.bright_blue }
|
||||
.bright_magenta { term.bright_magenta }
|
||||
.bright_cyan { term.bright_cyan }
|
||||
.bright_white { term.bright_white }
|
||||
}
|
||||
|
||||
func(str)
|
||||
}
|
||||
}
|
||||
|
||||
fn (c BasicColor) render_bg(str string) string {
|
||||
return if no_color {
|
||||
str
|
||||
} else {
|
||||
func := match c {
|
||||
.black { term.bg_black }
|
||||
.red { term.bg_red }
|
||||
.green { term.bg_green }
|
||||
.yellow { term.bg_yellow }
|
||||
.blue { term.bg_blue }
|
||||
.magenta { term.bg_magenta }
|
||||
.cyan { term.bg_cyan }
|
||||
.white { term.bg_white }
|
||||
.bright_black { term.bright_bg_black }
|
||||
.bright_red { term.bright_bg_red }
|
||||
.bright_green { term.bright_bg_green }
|
||||
.bright_yellow { term.bright_bg_yellow }
|
||||
.bright_blue { term.bright_bg_blue }
|
||||
.bright_magenta { term.bright_bg_magenta }
|
||||
.bright_cyan { term.bright_bg_cyan }
|
||||
.bright_white { term.bright_bg_white }
|
||||
}
|
||||
|
||||
func(str)
|
||||
}
|
||||
struct BasicColor {
|
||||
pub:
|
||||
render fn (string) string
|
||||
render_bg fn (string) string
|
||||
}
|
||||
|
|
|
@ -5,32 +5,32 @@ 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)
|
||||
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)
|
||||
// Colors
|
||||
black = Color(BasicColor.black)
|
||||
bright_black = Color(BasicColor.bright_black)
|
||||
red = Color(BasicColor.red)
|
||||
bright_red = Color(BasicColor.bright_red)
|
||||
green = Color(BasicColor.green)
|
||||
bright_green = Color(BasicColor.bright_green)
|
||||
yellow = Color(BasicColor.yellow)
|
||||
bright_yellow = Color(BasicColor.bright_yellow)
|
||||
blue = Color(BasicColor.blue)
|
||||
bright_blue = Color(BasicColor.bright_blue)
|
||||
magenta = Color(BasicColor.magenta)
|
||||
bright_magenta = Color(BasicColor.bright_magenta)
|
||||
cyan = Color(BasicColor.cyan)
|
||||
bright_cyan = Color(BasicColor.bright_cyan)
|
||||
white = Color(BasicColor.white)
|
||||
bright_white = Color(BasicColor.bright_white)
|
||||
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})
|
||||
cyan = Color(BasicColor{term.cyan, term.bg_cyan})
|
||||
bright_cyan = Color(BasicColor{term.bright_cyan, term.bright_bg_cyan})
|
||||
white = Color(BasicColor{term.white, term.bg_white})
|
||||
bright_white = Color(BasicColor{term.bright_white, term.bright_bg_white})
|
||||
)
|
||||
|
||||
const no_color = !term.can_show_color_on_stdout()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue