From 7115aa8f8b0d23318813b8c4ebae3e4b293feeaa Mon Sep 17 00:00:00 2001 From: JINNOUCHI Yasushi Date: Mon, 22 Feb 2021 20:43:51 +0900 Subject: [PATCH] feat: customize symbols for the diagnostics component (#112) --- README.md | 3 ++- doc/lualine.txt | 17 +++++++++++++++- lua/lualine/components/diagnostics.lua | 28 +++++++++++--------------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4a7106f..abb670c 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ All of these options can also be specifically set to all supported components, f ##### Available global options Option | Default | Behaviour | Supported components :------: | :------: | :----------: | :-----: -icons_enabled | true | Displays icons on components You should have powerline supported fonts to see icons properly. | branch, fileformat, filetype, location +icons_enabled | true | Displays icons on components You should have nerd-fonts supported fonts to see icons properly. | branch, fileformat, filetype, location, diagnostics padding | 1 | Adds padding to the left and right of components | all left_padding | 1 | Adds padding to the left of components | all right_padding | 1 | Adds padding to the right of components | all @@ -229,6 +229,7 @@ sections | `{'error', 'warn', 'info'}` | displays diagnostics of defined severit color_error | `DiffDelete` foreground color | changes diagnostic's error section foreground color | color in `#rrggbb` format color_warn | `DiffText` foreground color | changes diagnostic's warn section foreground color | color in `#rrggbb` format color_info | `Normal` foreground color | changes diagnostic's info section foreground color | color in `#rrggbb` format +symbols | `{error = ' ', warn = ' ', info = ' '}` or `{error = 'E:', warn = 'W:', info = 'I:'}` | changes diagnostic's info section foreground color | table containing one or more symbols for levels | * `filename` component options diff --git a/doc/lualine.txt b/doc/lualine.txt index 42ab87b..9fe8aae 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -217,7 +217,7 @@ Default options act as default for all components icons_enabled (Default: true) Displays icons on components - You should have powerline supported fonts to see + You should have nerd-fonts supported fonts to see icons properly. Suported by branch, fileformat, filetype, location @@ -296,6 +296,21 @@ List of options are given below. changes diagnostic's info section foreground color color in #rrggbb format + • symbols + (icons_enabled: true -> {error = ' ', warn = ' ', info = ' '}) + (icons_enabled: false -> {error = 'E:', warn = 'W:', info = 'I:'}) + changes diagnostic's symbol characters. You can set one or more symbols + for each level. + > + { + 'diagnostics', + symbols = { + -- set the error symbol and use defaults for warn and info. + error = '!!', + }, + } +< + • filename~ • file_status (true) Whether to display filemodified status in filename diff --git a/lua/lualine/components/diagnostics.lua b/lua/lualine/components/diagnostics.lua index d7f30d2..4ba188f 100644 --- a/lua/lualine/components/diagnostics.lua +++ b/lua/lualine/components/diagnostics.lua @@ -43,20 +43,16 @@ local function get_diagnostics(sources) end local function diagnostics(options) - local symbols - if options.icons_enabled then - symbols = { - error = ' ', -- xf659 - warn = ' ', -- xf529 - info = ' ', -- xf7fc - } - else - symbols = { - error = 'E:', - warn = 'W:', - info = 'I:' - } - end + local default_symbols = options.icons_enabled and { + error = ' ', -- xf659 + warn = ' ', -- xf529 + info = ' ', -- xf7fc + } or { + error = 'E:', + warn = 'W:', + info = 'I:' + } + options.symbols = vim.tbl_extend('force', default_symbols, options.symbols or {}) if options.sources == nil then print('no sources for diagnostics configured') return '' @@ -109,13 +105,13 @@ local function diagnostics(options) end for _, section in ipairs(options.sections) do if data[section] ~= nil and data[section] > 0 then - table.insert(result, colors[section]..symbols[section]..data[section]) + table.insert(result, colors[section]..options.symbols[section]..data[section]) end end else for _, section in ipairs(options.sections) do if data[section] ~= nil and data[section] > 0 then - table.insert(result,symbols[section]..data[section]) + table.insert(result,options.symbols[section]..data[section]) end end end