From 898a4cd8a84ae9f2f28b1163ae315c55a0e08c82 Mon Sep 17 00:00:00 2001 From: Christoph Heinrich Date: Mon, 20 Jun 2022 00:08:37 +0200 Subject: [PATCH] console: refactor text styles for log levels The text styles are now in a table. The color definitions of the theme where the colors were taken from are now included in a comment for future reference. The colors have been converted to BGR as is required by ASS. --- player/lua/console.lua | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/player/lua/console.lua b/player/lua/console.lua index 025fbece23..7811ff8f16 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -55,6 +55,21 @@ end -- Apply user-set options options.read_options(opts) +local styles = { + -- Colors are stolen from base16 Eighties by Chris Kempson + -- and converted to BGR as is required by ASS. + -- 2d2d2d 393939 515151 697374 + -- 939fa0 c8d0d3 dfe6e8 ecf0f2 + -- 7a77f2 5791f9 66ccff 99cc99 + -- cccc66 cc9966 cc99cc 537bd2 + + debug = '{\\1c&Ha09f93&}', + verbose = '{\\1c&H99cc99&}', + warn = '{\\1c&H66ccff&}', + error = '{\\1c&H7a77f2&}', + fatal = '{\\1c&H5791f9&\\b1}', +} + local repl_active = false local insert_mode = false local pending_update = false @@ -329,7 +344,6 @@ function help_command(param) table.sort(cmdlist, function(c1, c2) return c1.name < c2.name end) - local error_style = '{\\1c&H7a77f2&}' local output = '' if param == '' then output = 'Available commands:\n' @@ -350,7 +364,7 @@ function help_command(param) end end if not cmd then - log_add(error_style, 'No command matches "' .. param .. '"!') + log_add(styles.error, 'No command matches "' .. param .. '"!') return end output = output .. 'Command "' .. cmd.name .. '"\n' @@ -836,19 +850,18 @@ mp.register_event('log-message', function(e) -- OSD display itself. if e.level == 'trace' then return end - -- Use color for debug/v/warn/error/fatal messages. Colors are stolen from - -- base16 Eighties by Chris Kempson. + -- Use color for debug/v/warn/error/fatal messages. local style = '' if e.level == 'debug' then - style = '{\\1c&Ha09f93&}' + style = styles.debug elseif e.level == 'v' then - style = '{\\1c&H99cc99&}' + style = styles.verbose elseif e.level == 'warn' then - style = '{\\1c&H66ccff&}' + style = styles.warn elseif e.level == 'error' then - style = '{\\1c&H7a77f2&}' + style = styles.error elseif e.level == 'fatal' then - style = '{\\1c&H5791f9&\\b1}' + style = styles.fatal end log_add(style, '[' .. e.prefix .. '] ' .. e.text)