From 918774b5aa321a146754006314c6f8eed8ecd8ec Mon Sep 17 00:00:00 2001 From: Rostislav Pehlivanov Date: Tue, 21 Jul 2015 20:53:23 +0100 Subject: stats: print bold text in terminals This simply prints ASCII codes to display any text marked as bold in the terminal. Supported by every sane terminal since 1986. For those insane, there's a check. The check has been copied from the ansicolors.lua script floating around and it checks if the directory path uses "\" instead of "/", and in case it does, it checks whether ANSICON env variable has been set (which is used to indicate the Windows terminal supports ACII escape sequences). --- player/lua/stats.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'player') diff --git a/player/lua/stats.lua b/player/lua/stats.lua index b463e69cf9..af859ba069 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -45,8 +45,8 @@ local o = { no_ass_nl = "\n", no_ass_prop_indent = "\t", no_ass_kv_sep = " ", - no_ass_b1 = "", - no_ass_b0 = "", + no_ass_b1 = "\027[1m", + no_ass_b0 = "\027[0m", } options.read_options(o) @@ -64,8 +64,13 @@ function main() o.nl = o.no_ass_nl o.prop_indent = o.no_ass_prop_indent o.kv_sep = o.no_ass_kv_sep - o.b1 = o.no_ass_b1 - o.b0 = o.no_ass_b0 + if not has_ansi() then + o.b1 = "" + o.b0 = "" + else + o.b1 = o.no_ass_b1 + o.b0 = o.no_ass_b0 + end end add_header(stats) @@ -242,6 +247,13 @@ function has_audio() return r and r ~= "no" and r ~= "" end +function has_ansi() + local is_windows = type(package) == 'table' and type(package.config) == 'string' and package.config:sub(1,1) == '\\' + if is_windows then + return os.getenv("ANSICON") + end + return true +end function b(t) return o.b1 .. t .. o.b0 -- cgit v1.2.3