From 0b0233f8081af1f68d100d494dc6c7d1da8f8c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Augusto?= Date: Tue, 26 Oct 2021 18:04:53 -0300 Subject: [PATCH] feat: add symbols option to fileformat (#401) * doc: add symbol to fileformat component specific option --- README.md | 17 +++++++++++++++++ lua/lualine/components/fileformat.lua | 26 ++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 86cfe67..a08f5fc 100644 --- a/README.md +++ b/README.md @@ -483,6 +483,23 @@ sections = { } ``` +#### fileformat component options + +```lua +sections = { + lualine_a = { + { + 'fileformat', + symbols = { + unix = '', -- e712 + dos = '', -- e70f + mac = '', -- e711 + } + } + } +} +``` + #### filename component options ```lua diff --git a/lua/lualine/components/fileformat.lua b/lua/lualine/components/fileformat.lua index 8ca764a..7e5011d 100644 --- a/lua/lualine/components/fileformat.lua +++ b/lua/lualine/components/fileformat.lua @@ -3,18 +3,28 @@ local M = require('lualine.component'):extend() -- stylua: ignore -M.icon = { +local symbols = { unix = '', -- e712 - dos = '', -- e70f - mac = '' -- e711 + dos = '', -- e70f + mac = '', -- e711 } -M.update_status = function(self) - if self.options.icons_enabled and not self.options.icon then - local format = vim.bo.fileformat - return M.icon[format] or format +-- Initializer +function M:init(options) + -- Run super() + M.super.init(self, options) + -- Apply default symbols + self.symbols = vim.tbl_extend('keep', self.options.symbols or {}, symbols) +end + +-- Function that runs everytime statusline is updated +function M:update_status() + local format = vim.bo.fileformat + if self.options.icons_enabled then + return self.symbols[format] or format + else + return format end - return vim.bo.fileformat end return M