From e6cc09c2e95cc361babb64c113cc3e9355ea1130 Mon Sep 17 00:00:00 2001 From: Tim Bedard Date: Tue, 20 Apr 2021 11:25:25 -0500 Subject: [PATCH] feat(filename): add support for custom filename symbols (modified, readonly) (#185) * feat(filename): add support for custom filename symbols (modified, readonly) * update docs --- README.md | 3 ++- doc/lualine.txt | 3 +++ lua/lualine/components/filename.lua | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0db0ee..be48181 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,7 @@ Option | Default | Behaviour file_status | true | Displays file status (readonly status, modified status) full_path | false | Displays relative path if set to `true`, absolute path if set to `false` shorten | true | if `full_path` is true and `shorten` is `false` it shortens absolute path `aaa/bbb/ccc/file` to `a/b/c/file` +symbols | `{modified = '[+]', readonly = '[-]'}` | changes status symbols | table containing one or more symbols | * `diff` component options @@ -311,7 +312,7 @@ colored | true | displays diff status in color if set to `true` | color_added | `DiffAdd` foreground color | changes diff's added section foreground color | color in `#rrggbb` format color_modified | `DiffChange` foreground color | changes diff's changed section foreground color | color in `#rrggbb` format color_removed | `DiffDelete` foreground color | changes diff's removed section foreground color | color in `#rrggbb` format -symbols | `{added = '+', modified = '~', removed = '-'}` | changes diff's symbols | table containing on or more symbols | +symbols | `{added = '+', modified = '~', removed = '-'}` | changes diff's symbols | table containing one or more symbols | Component specific options can only be set with component configs. diff --git a/doc/lualine.txt b/doc/lualine.txt index 81a626f..0771629 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -409,6 +409,9 @@ In addition, some components have unique options. if `full_path` is `true` and `shorten` is `false` it shortens absolute path `aaa/bbb/ccc/file` to `a/b/c/file` + • symbols (`{modified = '[+]', readonly = '[-]'}`) + changes status symbols + • fileformat~ • icons_enabled (true) Whether to displays icon before component. Colors diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index 19a3bef..2e96e20 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -4,6 +4,9 @@ local FileName = require('lualine.component'):new() FileName.new = function(self, options, child) local new_instance = self._parent:new(options, child or FileName) + local default_symbols = {modified = '[+]', readonly = '[-]'} + new_instance.options.symbols = + vim.tbl_extend('force', default_symbols, new_instance.options.symbols or {}) -- setting defaults if new_instance.options.file_status == nil then @@ -35,9 +38,9 @@ FileName.update_status = function(self) if self.options.file_status then if vim.bo.modified then - data = data .. '[+]' + data = data .. self.options.symbols.modified elseif vim.bo.modifiable == false or vim.bo.readonly == true then - data = data .. '[-]' + data = data .. self.options.symbols.readonly end end return data