mirror of
https://github.com/RGBCube/color.v
synced 2025-08-01 10:27:45 +00:00
Make StyleImpl more performant and better
This commit is contained in:
parent
87ab517bea
commit
7ab21e05d3
2 changed files with 22 additions and 46 deletions
|
@ -4,26 +4,26 @@ import term
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
// Styles
|
// Styles
|
||||||
reset = Style(StyleImpl.reset)
|
reset = Style(StyleImpl{term.reset})
|
||||||
bold = Style(StyleImpl.bold)
|
bold = Style(StyleImpl{term.bold})
|
||||||
dim = Style(StyleImpl.dim)
|
dim = Style(StyleImpl{term.dim})
|
||||||
italic = Style(StyleImpl.italic)
|
italic = Style(StyleImpl{term.italic})
|
||||||
underline = Style(StyleImpl.underline)
|
underline = Style(StyleImpl{term.underline})
|
||||||
slow_blink = Style(StyleImpl.slow_blink)
|
slow_blink = Style(StyleImpl{term.slow_blink})
|
||||||
rapid_blink = Style(StyleImpl.rapid_blink)
|
rapid_blink = Style(StyleImpl{term.rapid_blink})
|
||||||
inverse = Style(StyleImpl.inverse)
|
inverse = Style(StyleImpl{term.inverse})
|
||||||
hidden = Style(StyleImpl.hidden)
|
hidden = Style(StyleImpl{term.hidden})
|
||||||
strikethrough = Style(StyleImpl.strikethrough)
|
strikethrough = Style(StyleImpl{term.strikethrough})
|
||||||
// Colors
|
// Colors
|
||||||
black = Color(BasicColor{term.black, term.bg_black})
|
black = Color(BasicColor{term.black, term.bg_black})
|
||||||
bright_black = Color(BasicColor{term.bright_black, term.bright_bg_black})
|
bright_black = Color(BasicColor{term.bright_black, term.bright_bg_black})
|
||||||
red = Color(BasicColor{term.red, term.bg_red})
|
red = Color(BasicColor{term.red, term.bg_red})
|
||||||
bright_red = Color(BasicColor{term.bright_red, term.bright_bg_red})
|
bright_red = Color(BasicColor{term.bright_red, term.bright_bg_red})
|
||||||
green = Color(BasicColor{term.green, term.bg_green})
|
green = Color(BasicColor{term.green, term.bg_green})
|
||||||
bright_green = Color(BasicColor{term.bright_green, term.bright_bg_green})
|
bright_green = Color(BasicColor{term.bright_green, term.bright_bg_green})
|
||||||
yellow = Color(BasicColor{term.yellow, term.bg_yellow})
|
yellow = Color(BasicColor{term.yellow, term.bg_yellow})
|
||||||
bright_yellow = Color(BasicColor{term.bright_yellow, term.bright_bg_yellow})
|
bright_yellow = Color(BasicColor{term.bright_yellow, term.bright_bg_yellow})
|
||||||
blue = Color(BasicColor{term.blue, term.bg_blue})
|
blue = Color(BasicColor{term.blue, term.bg_blue})
|
||||||
bright_blue = Color(BasicColor{term.bright_blue, term.bright_bg_blue})
|
bright_blue = Color(BasicColor{term.bright_blue, term.bright_bg_blue})
|
||||||
magenta = Color(BasicColor{term.magenta, term.bg_magenta})
|
magenta = Color(BasicColor{term.magenta, term.bg_magenta})
|
||||||
bright_magenta = Color(BasicColor{term.bright_magenta, term.bright_bg_magenta})
|
bright_magenta = Color(BasicColor{term.bright_magenta, term.bright_bg_magenta})
|
||||||
|
|
30
src/style.v
30
src/style.v
|
@ -1,7 +1,5 @@
|
||||||
module color
|
module color
|
||||||
|
|
||||||
import term
|
|
||||||
|
|
||||||
// Style is an interface for a style.
|
// Style is an interface for a style.
|
||||||
pub interface Style {
|
pub interface Style {
|
||||||
render(string) string // Renders the string with the given 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))
|
println(s.render(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
enum StyleImpl {
|
struct StyleImpl {
|
||||||
reset
|
render_fn fn (string) string
|
||||||
bold
|
|
||||||
dim
|
|
||||||
italic
|
|
||||||
underline
|
|
||||||
slow_blink
|
|
||||||
rapid_blink
|
|
||||||
inverse
|
|
||||||
hidden
|
|
||||||
strikethrough
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (s StyleImpl) render(str string) string {
|
fn (s StyleImpl) render(str string) string {
|
||||||
return if no_color {
|
return if no_color {
|
||||||
str
|
str
|
||||||
} else {
|
} else {
|
||||||
func := match s {
|
s.render_fn(str)
|
||||||
.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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue