2019-06-24 18:50:36 +02:00
|
|
|
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2019-07-01 17:09:22 +02:00
|
|
|
module term
|
2019-06-24 18:50:36 +02:00
|
|
|
|
2019-07-04 17:39:35 +02:00
|
|
|
import os
|
|
|
|
|
2019-07-29 04:44:21 +02:00
|
|
|
fn _format(msg, open, close string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return '\x1b[' + open + 'm' + msg + '\x1b[' + close + 'm'
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
fn _format_rgb(r, g, b int, msg, open, close string) string {
|
|
|
|
return '\x1b[' + open + ';2;' + r.str() + ';' + g.str() + ';' + b.str() + 'm' + msg + '\x1b[' + close + 'm'
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn rgb(r, g, b int, msg string) string {
|
|
|
|
return format_rgb(r, g, b, msg, '38', '39')
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bg_rgb(r, g, b int, msg string) string {
|
|
|
|
return format_rgb(r, g, b, msg, '48', '49')
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn hex(hex int, msg string) string {
|
|
|
|
return format_rgb(
|
|
|
|
hex >> 16,
|
|
|
|
hex >> 8 & 0xFF,
|
|
|
|
hex & 0xFF,
|
|
|
|
msg, '38', '39')
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bg_hex(hex int, msg string) string {
|
|
|
|
return format_rgb(
|
|
|
|
hex >> 16,
|
|
|
|
hex >> 8 & 0xFF,
|
|
|
|
hex & 0xFF,
|
|
|
|
msg, '48', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_black(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '40', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_black(msg string) string {
|
|
|
|
return format(msg, '100', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_blue(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '44', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_blue(msg string) string {
|
|
|
|
return format(msg, '104', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_cyan(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '46', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_cyan(msg string) string {
|
|
|
|
return format(msg, '106', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_green(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '42', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_green(msg string) string {
|
|
|
|
return format(msg, '102', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_magenta(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '45', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_magenta(msg string) string {
|
|
|
|
return format(msg, '105', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_red(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '41', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_red(msg string) string {
|
|
|
|
return format(msg, '101', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_white(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '47', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_white(msg string) string {
|
|
|
|
return format(msg, '107', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bg_yellow(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '43', '49')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_bg_yellow(msg string) string {
|
|
|
|
return format(msg, '103', '49')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn black(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '30', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_black(msg string) string {
|
|
|
|
return format(msg, '90', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn blue(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '34', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_blue(msg string) string {
|
|
|
|
return format(msg, '94', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn bold(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '1', '22')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn cyan(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '36', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_cyan(msg string) string {
|
|
|
|
return format(msg, '96', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn dim(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '2', '22')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn green(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '32', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_green(msg string) string {
|
|
|
|
return format(msg, '92', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn gray(msg string) string {
|
2019-07-31 19:22:38 +02:00
|
|
|
return bright_black(msg)
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn hidden(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '8', '28')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn italic(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '3', '23')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn inverse(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '7', '27')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn magenta(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '35', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_magenta(msg string) string {
|
|
|
|
return format(msg, '95', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn reset(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '0', '0')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn red(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '31', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_red(msg string) string {
|
|
|
|
return format(msg, '91', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn strikethrough(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '9', '29')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn underline(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '4', '24')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn white(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '37', '39')
|
2019-06-24 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:22:38 +02:00
|
|
|
pub fn bright_white(msg string) string {
|
|
|
|
return format(msg, '97', '39')
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:14:38 +02:00
|
|
|
pub fn yellow(msg string) string {
|
2019-07-30 02:55:47 +02:00
|
|
|
return format(msg, '33', '39')
|
2019-07-16 17:59:07 +02:00
|
|
|
}
|
2019-07-31 19:22:38 +02:00
|
|
|
|
|
|
|
pub fn bright_yellow(msg string) string {
|
|
|
|
return format(msg, '93', '39')
|
|
|
|
}
|