Skip to content

Commit

Permalink
♻ Refactor: Remove check width when use laststatus=3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen-Hoang-Nam committed Jul 17, 2022
1 parent 794d981 commit 372c297
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Disable Cmp in comment
- Set cmdheight to 0
- Set rest keymap to buffer
- Set laststatus to 3

### Fixed

Expand Down
1 change: 0 additions & 1 deletion lua/languages/sql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ return {
capabilities = lsp.capabilities,
on_attach = function(client, bufnr)
require("sqls").on_attach(client, bufnr)
require("nvim-navic").attach(client, bufnr)
end,

root_dir = function()
Expand Down
57 changes: 27 additions & 30 deletions lua/statusline/init.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
local api = vim.api
local fn = vim.fn

local setting_statusline = require("settings").statusline

local M = {}

local hide_left = { "help", "http", "sql" }
local hide_left_by_filetype = { "help", "http", "sql" }
local hide_left_by_filename = { "[no name].sql" }

local left = function()
local line = ""

if not vim.tbl_contains(hide_left, vim.bo.filetype) then
if
not vim.tbl_contains(hide_left_by_filetype, vim.bo.filetype)
or not vim.tbl_contains(hide_left_by_filename, require("utils.core").get_file_name(api.nvim_buf_get_name(0)))
then
if setting_statusline.git_branch_enabled then
line = line .. "" .. require("git_utils").branch("") .. " "
end
Expand Down Expand Up @@ -42,29 +45,27 @@ local right = function()
line = line .. "Ln %l, Col %c"
end

if fn.winwidth(0) > 80 then
-- Show indent type and number of spaces
if setting_statusline.tab_enabled then
local tab_type = api.nvim_eval("&et") == 1 and "Spaces: " or "Tab Size: "
local tab = api.nvim_eval("&tabstop")
-- Show indent type and number of spaces
if setting_statusline.tab_enabled then
local tab_type = api.nvim_eval("&et") == 1 and "Spaces: " or "Tab Size: "
local tab = api.nvim_eval("&tabstop")

line = line .. " " .. tab_type .. tab
end
line = line .. " " .. tab_type .. tab
end

-- Show type of line break
if setting_statusline.line_break_enabled then
line = line .. " " .. require("statusline.linebreak").line()
end
-- Show type of line break
if setting_statusline.line_break_enabled then
line = line .. " " .. require("statusline.linebreak").line()
end

-- Show format of file
if setting_statusline.file_format_enabled then
line = line .. " " .. vim.bo.filetype:gsub("^%l", string.upper)
end
-- Show format of file
if setting_statusline.file_format_enabled then
line = line .. " " .. vim.bo.filetype:gsub("^%l", string.upper)
end

-- Show formatters and linters
if setting_statusline.efm_enabled then
line = line .. [[%{luaeval('require("format").formatter_status()')}]]
end
-- Show formatters and linters
if setting_statusline.efm_enabled then
line = line .. [[%{luaeval('require("format").formatter_status()')}]]
end

-- Emoji at the end of status line
Expand All @@ -79,15 +80,11 @@ end

local async_load = vim.loop.new_async(vim.schedule_wrap(function()
local line
if fn.winwidth(0) > 30 then
line = "%#StatuslineBackground# "
line = line .. left()
line = "%#StatuslineBackground# "
line = line .. left()

line = line .. "%#StatuslineBackground#%="
line = line .. right()
else
line = "%#StatuslineEmptyBackground#"
end
line = line .. "%#StatuslineBackground#%="
line = line .. right()

vim.wo.statusline = line
end))
Expand Down
5 changes: 5 additions & 0 deletions lua/utils/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function M.tablelength(T)
return count
end

-- Credit https://stackoverflow.com/questions/48402876/getting-current-file-name-in-lua
function M.get_file_name(path)
return path:match("^.+/(.+)$")
end

function M.file_extension(filename)
local t = {}
for str in string.gmatch(filename, "([^%.]+)") do
Expand Down

0 comments on commit 372c297

Please sign in to comment.