From cfe581e2ab579ea6111efe8bee7ad1776dbefd5d Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Tue, 30 Jul 2019 10:55:47 +1000 Subject: [PATCH] fix term --- vlib/term/colors.v | 56 ++++++++++++++++++++---------------------- vlib/term/colors_nix.v | 9 +++++++ 2 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 vlib/term/colors_nix.v diff --git a/vlib/term/colors.v b/vlib/term/colors.v index 9a99f6b570..8ccf81edbf 100644 --- a/vlib/term/colors.v +++ b/vlib/term/colors.v @@ -7,109 +7,105 @@ module term import os fn _format(msg, open, close string) string { - return '\x1b[' + open + 'm' + msg + '\x1b[' + close + 'm' -} - -pub fn format(msg, open, close string) string { - return _format(msg, open, close) + return '\x1b[' + open + 'm' + msg + '\x1b[' + close + 'm' } pub fn bg_black(msg string) string { - return format(msg, '40', '49') + return format(msg, '40', '49') } pub fn bg_blue(msg string) string { - return format(msg, '44', '49') + return format(msg, '44', '49') } pub fn bg_cyan(msg string) string { - return format(msg, '46', '49') + return format(msg, '46', '49') } pub fn bg_green(msg string) string { - return format(msg, '42', '49') + return format(msg, '42', '49') } pub fn bg_magenta(msg string) string { - return format(msg, '45', '49') + return format(msg, '45', '49') } pub fn bg_red(msg string) string { - return format(msg, '41', '49') + return format(msg, '41', '49') } pub fn bg_white(msg string) string { - return format(msg, '47', '49') + return format(msg, '47', '49') } pub fn bg_yellow(msg string) string { - return format(msg, '43', '49') + return format(msg, '43', '49') } pub fn black(msg string) string { - return format(msg, '30', '39') + return format(msg, '30', '39') } pub fn blue(msg string) string { - return format(msg, '34', '39') + return format(msg, '34', '39') } pub fn bold(msg string) string { - return format(msg, '1', '22') + return format(msg, '1', '22') } pub fn cyan(msg string) string { - return format(msg, '36', '39') + return format(msg, '36', '39') } pub fn dim(msg string) string { - return format(msg, '2', '22') + return format(msg, '2', '22') } pub fn green(msg string) string { - return format(msg, '32', '39') + return format(msg, '32', '39') } pub fn gray(msg string) string { - return format(msg, '90', '39') + return format(msg, '90', '39') } pub fn hidden(msg string) string { - return format(msg, '8', '28') + return format(msg, '8', '28') } pub fn italic(msg string) string { - return format(msg, '3', '23') + return format(msg, '3', '23') } pub fn inverse(msg string) string { - return format(msg, '7', '27') + return format(msg, '7', '27') } pub fn magenta(msg string) string { - return format(msg, '35', '39') + return format(msg, '35', '39') } pub fn reset(msg string) string { - return format(msg, '0', '0') + return format(msg, '0', '0') } pub fn red(msg string) string { - return format(msg, '31', '39') + return format(msg, '31', '39') } pub fn strikethrough(msg string) string { - return format(msg, '9', '29') + return format(msg, '9', '29') } pub fn underline(msg string) string { - return format(msg, '4', '24') + return format(msg, '4', '24') } pub fn white(msg string) string { - return format(msg, '37', '39') + return format(msg, '37', '39') } pub fn yellow(msg string) string { - return format(msg, '33', '39') + return format(msg, '33', '39') } diff --git a/vlib/term/colors_nix.v b/vlib/term/colors_nix.v new file mode 100644 index 0000000000..30e6bafb2a --- /dev/null +++ b/vlib/term/colors_nix.v @@ -0,0 +1,9 @@ +// 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. + +module term + +pub fn format(msg, open, close string) string { + return _format(msg, open, close) +}