diff options
author | Rostislav Pehlivanov <atomnuker@gmail.com> | 2015-07-21 20:53:23 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-10-09 20:40:31 +0200 |
commit | 918774b5aa321a146754006314c6f8eed8ecd8ec (patch) | |
tree | 92037410fc7efae69cdb3c1df230299e7bdc872f | |
parent | 89c854dc0952fbcb7cf810b8699710257d3a193d (diff) | |
download | mpv-918774b5aa321a146754006314c6f8eed8ecd8ec.tar.bz2 mpv-918774b5aa321a146754006314c6f8eed8ecd8ec.tar.xz |
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).
-rw-r--r-- | player/lua/stats.lua | 20 |
1 files changed, 16 insertions, 4 deletions
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 |