1
Fork 0
mirror of https://github.com/RGBCube/color.v synced 2025-08-01 10:27:45 +00:00
This commit is contained in:
RGBCube 2022-12-01 12:36:28 +03:00
parent e821cb4f5c
commit d4b9c8e406
3 changed files with 13 additions and 3 deletions

View file

@ -4,15 +4,18 @@ import term
// Interface // Interface
// Color is a Style extension that also supports rendering in the background.
pub interface Color { pub interface Color {
Style Style
render_bg(string) string render_bg(string) string
} }
// print_bg prints the given string with the color in the background.
pub fn (c Color) print_bg(msg string) { pub fn (c Color) print_bg(msg string) {
print(c.render_bg(msg)) print(c.render_bg(msg))
} }
// println_bg prints the given string with the color in the background with an added newline.
pub fn (c Color) println_bg(msg string) { pub fn (c Color) println_bg(msg string) {
println(c.render_bg(msg)) println(c.render_bg(msg))
} }

View file

@ -2,6 +2,7 @@ module color
// Interface // Interface
// Brush is the complex Style type that can hold multiple colors and styles.
pub interface Brush { pub interface Brush {
Style Style
mut: mut:
@ -12,16 +13,19 @@ mut:
[params] [params]
pub struct BrushParams { pub struct BrushParams {
fg ?Color fg ?Color
bg ?Color bg ?Color
styles []Style styles []Style
disabled bool
} }
// new_brush creates a new Brush with the given parameters.
pub fn new_brush(p BrushParams) !Brush { pub fn new_brush(p BrushParams) !Brush {
return BrushImpl{ return BrushImpl{
fg: p.fg fg: p.fg
bg: p.bg bg: p.bg
styles: p.styles styles: p.styles
disabled: disabled
} }
} }

View file

@ -4,14 +4,17 @@ import term
// Interface // Interface
// Style is an interface for a style.
pub interface Style { pub interface Style {
render(string) string render(string) string
} }
// print prints the given string with the given style.
pub fn (s Style) print(msg string) { pub fn (s Style) print(msg string) {
print(s.render(msg)) print(s.render(msg))
} }
// println prints the given string with the given style with an added newline.
pub fn (s Style) println(msg string) { pub fn (s Style) println(msg string) {
println(s.render(msg)) println(s.render(msg))
} }