mirror of
https://github.com/RGBCube/color.v
synced 2025-07-31 09:57:47 +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 {
|
struct BasicColor {
|
||||||
black
|
pub:
|
||||||
bright_black
|
render fn (string) string
|
||||||
red
|
render_bg fn (string) string
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,32 +5,32 @@ import term
|
||||||
pub const (
|
pub const (
|
||||||
// Styles
|
// Styles
|
||||||
reset = Style(StyleImpl.reset)
|
reset = Style(StyleImpl.reset)
|
||||||
bold = Style(StyleImpl.bold)
|
bold = Style(StyleImpl.bold)
|
||||||
dim = Style(StyleImpl.dim)
|
dim = Style(StyleImpl.dim)
|
||||||
italic = Style(StyleImpl.italic)
|
italic = Style(StyleImpl.italic)
|
||||||
underline = Style(StyleImpl.underline)
|
underline = Style(StyleImpl.underline)
|
||||||
slow_blink = Style(StyleImpl.slow_blink)
|
slow_blink = Style(StyleImpl.slow_blink)
|
||||||
rapid_blink = Style(StyleImpl.rapid_blink)
|
rapid_blink = Style(StyleImpl.rapid_blink)
|
||||||
inverse = Style(StyleImpl.inverse)
|
inverse = Style(StyleImpl.inverse)
|
||||||
hidden = Style(StyleImpl.hidden)
|
hidden = Style(StyleImpl.hidden)
|
||||||
strikethrough = Style(StyleImpl.strikethrough)
|
strikethrough = Style(StyleImpl.strikethrough)
|
||||||
// Colors
|
// Colors
|
||||||
black = Color(BasicColor.black)
|
black = Color(BasicColor{term.black, term.bg_black})
|
||||||
bright_black = Color(BasicColor.bright_black)
|
bright_black = Color(BasicColor{term.bright_black, term.bright_bg_black})
|
||||||
red = Color(BasicColor.red)
|
red = Color(BasicColor{term.red, term.bg_red})
|
||||||
bright_red = Color(BasicColor.bright_red)
|
bright_red = Color(BasicColor{term.bright_red, term.bright_bg_red})
|
||||||
green = Color(BasicColor.green)
|
green = Color(BasicColor{term.green, term.bg_green})
|
||||||
bright_green = Color(BasicColor.bright_green)
|
bright_green = Color(BasicColor{term.bright_green, term.bright_bg_green})
|
||||||
yellow = Color(BasicColor.yellow)
|
yellow = Color(BasicColor{term.yellow, term.bg_yellow})
|
||||||
bright_yellow = Color(BasicColor.bright_yellow)
|
bright_yellow = Color(BasicColor{term.bright_yellow, term.bright_bg_yellow})
|
||||||
blue = Color(BasicColor.blue)
|
blue = Color(BasicColor{term.blue, term.bg_blue})
|
||||||
bright_blue = Color(BasicColor.bright_blue)
|
bright_blue = Color(BasicColor{term.bright_blue, term.bright_bg_blue})
|
||||||
magenta = Color(BasicColor.magenta)
|
magenta = Color(BasicColor{term.magenta, term.bg_magenta})
|
||||||
bright_magenta = Color(BasicColor.bright_magenta)
|
bright_magenta = Color(BasicColor{term.bright_magenta, term.bright_bg_magenta})
|
||||||
cyan = Color(BasicColor.cyan)
|
cyan = Color(BasicColor{term.cyan, term.bg_cyan})
|
||||||
bright_cyan = Color(BasicColor.bright_cyan)
|
bright_cyan = Color(BasicColor{term.bright_cyan, term.bright_bg_cyan})
|
||||||
white = Color(BasicColor.white)
|
white = Color(BasicColor{term.white, term.bg_white})
|
||||||
bright_white = Color(BasicColor.bright_white)
|
bright_white = Color(BasicColor{term.bright_white, term.bright_bg_white})
|
||||||
)
|
)
|
||||||
|
|
||||||
const no_color = !term.can_show_color_on_stdout()
|
const no_color = !term.can_show_color_on_stdout()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue