ui.console #
Chalk
A terminal string colorizer for the V language.
Chalk offers functions:- console.color_fg(text string, color string)
- To change the foreground color.
console.color_bg(text string, color string)
- To change the background color.console.style(text string, style string)
- To change the text style.
Example:
import console
##println('I am really ' + console.color_fg('happy', 'green'))
##println('I am really ' + console.color_fg(console.style('ANGRY', 'bold'), 'red'))
Available colors:- black
- red
- green
- yellow
- blue
- magenta
- cyan
- default
- light_gray
- dark_gray
- light_red
- light_green
- light_yellow
- light_blue
- light_magenta
- light_cyan
- white
Available styles:- bold
- dim
- underline
- blink
- reverse
- hidden
Constants #
const reset ='${prefix}0${suffix}'
fn clear #
fn clear()
fn color_bg #
fn color_bg(c BackgroundColor) string
will give ansi codes to change background color . don't forget to call reset to change back to normal
enum BackgroundColor {
black = 40
red = 41
green = 42
yellow = 43
blue = 44
magenta = 45
cyan = 46
default_color = 49 // 'default' is a reserved keyword in V
light_gray = 47
dark_gray = 100
light_red = 101
light_green = 102
light_yellow = 103
light_blue = 104
light_magenta = 105
light_cyan = 106
white = 107
}
fn color_fg #
fn color_fg(c ForegroundColor) string
will give ansi codes to change foreground color . don't forget to call reset to change back to normal
enum ForegroundColor {
black = 30
red = 31
green = 32
yellow = 33
blue = 34
magenta = 35
cyan = 36
default_color = 39 // 'default' is a reserved keyword in V
light_gray = 37
dark_gray = 90
light_red = 91
light_green = 92
light_yellow = 93
light_blue = 94
light_magenta = 95
light_cyan = 96
white = 97
}
fn cprint #
fn cprint(args PrintArgs)
print with colors, reset...
foreground ForegroundColor
background BackgroundColor
text string
style Style
reset_before bool = true
reset_after bool = true
fn cprintln #
fn cprintln(args_ PrintArgs)
fn expand #
fn expand(txt_ string, l int, with string) string
expand text till length l, with string which is normally ' '
fn lf #
fn lf()
line feed
fn new #
fn new() UIConsole
fn print_array #
fn print_array(arr [][]string, delimiter string, sort bool)
print 2 dimensional array, delimeter is between columns
fn print_debug #
fn print_debug(i IPrintable)
fn print_debug_title #
fn print_debug_title(title string, txt string)
fn print_green #
fn print_green(txt string)
fn print_header #
fn print_header(txt string)
fn print_item #
fn print_item(txt string)
fn print_lf #
fn print_lf(nr int)
fn print_stderr #
fn print_stderr(txt string)
fn print_stdout #
fn print_stdout(txt string)
fn reset #
fn reset() string
fn silent_get #
fn silent_get() bool
fn silent_set #
fn silent_set()
fn silent_unset #
fn silent_unset()
fn style #
fn style(c Style) string
will give ansi codes to change style . don't forget to call reset to change back to normal
enum Style {
normal = 99
bold = 1
dim = 2
underline = 4
blink = 5
reverse = 7
hidden = 8
}
fn trim #
fn trim(c_ string) string
interface IPrintable #
interface IPrintable {}
enum BackgroundColor #
enum BackgroundColor {
default_color = 49 // 'default' is a reserved keyword in V
black = 40
red = 41
green = 42
yellow = 43
blue = 44
magenta = 45
cyan = 46
light_gray = 47
dark_gray = 100
light_red = 101
light_green = 102
light_yellow = 103
light_blue = 104
light_magenta = 105
light_cyan = 106
white = 107
}
enum ForegroundColor #
enum ForegroundColor {
default_color = 39 // 'default' is a reserved keyword in V
white = 97
black = 30
red = 31
green = 32
yellow = 33
blue = 34
magenta = 35
cyan = 36
light_gray = 37
dark_gray = 90
light_red = 91
light_green = 92
light_yellow = 93
light_blue = 94
light_magenta = 95
light_cyan = 96
}
enum Style #
enum Style {
normal = 99
bold = 1
dim = 2
underline = 4
blink = 5
reverse = 7
hidden = 8
}
struct PrintArgs #
struct PrintArgs {
pub mut:
foreground ForegroundColor
background BackgroundColor
text string
style Style
reset_before bool = true
reset_after bool = true
}
struct UIConsole #
struct UIConsole {
pub mut:
x_max int = 80
y_max int = 60
prev_lf bool
prev_title bool
prev_item bool
}
fn (UIConsole) ask_date #
fn (mut c UIConsole) ask_date(args QuestionArgs) !string
fn (UIConsole) ask_dropdown #
fn (mut c UIConsole) ask_dropdown(args DropDownArgs) !string
will return the string as given as response description string items []string warning string clear bool = true
fn (UIConsole) ask_dropdown_int #
fn (mut c UIConsole) ask_dropdown_int(args_ DropDownArgs) !int
return the dropdown as an int description string items []string warning string clear bool = true
fn (UIConsole) ask_dropdown_multiple #
fn (mut c UIConsole) ask_dropdown_multiple(args_ DropDownArgs) ![]string
result can be multiple, aloso can select all description string items []string warning string clear bool = true
fn (UIConsole) ask_question #
fn (mut c UIConsole) ask_question(args QuestionArgs) !string
args:- description string
- question string
- warning: string (if it goes wrong, which message to use)
- reset bool = true
- regex: to check what result need to be part of
- minlen: min nr of chars
fn (UIConsole) ask_time #
fn (mut c UIConsole) ask_time(args QuestionArgs) !string
fn (UIConsole) ask_yesno #
fn (mut c UIConsole) ask_yesno(args YesNoArgs) !bool
yes is true, no is false args:- description string
- question string
- warning string
- clear bool = true
fn (UIConsole) reset #
fn (mut c UIConsole) reset()
fn (UIConsole) status #
fn (mut c UIConsole) status() string
- README
- Constants
- fn clear
- fn color_bg
- fn color_fg
- fn cprint
- fn cprintln
- fn expand
- fn lf
- fn new
- fn print_array
- fn print_debug
- fn print_debug_title
- fn print_green
- fn print_header
- fn print_item
- fn print_lf
- fn print_stderr
- fn print_stdout
- fn reset
- fn silent_get
- fn silent_set
- fn silent_unset
- fn style
- fn trim
- interface IPrintable
- enum BackgroundColor
- enum ForegroundColor
- enum Style
- struct PrintArgs
- struct UIConsole