From 355aacba177b5e0a9303946efc82150554131358 Mon Sep 17 00:00:00 2001 From: Olivier Roques Date: Tue, 22 Dec 2020 18:50:04 +0100 Subject: [PATCH] Add new components --- lua/hardline.lua | 5 +++++ lua/hardline/file.lua | 1 + lua/hardline/filetype.lua | 15 +++++++++++++++ lua/hardline/git.lua | 5 ++++- lua/hardline/line.lua | 24 ++++++++++++++++++++++++ lua/hardline/lsp.lua | 8 ++++++++ lua/hardline/whitespace.lua | 8 ++++++++ 7 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 lua/hardline/filetype.lua create mode 100644 lua/hardline/line.lua create mode 100644 lua/hardline/lsp.lua create mode 100644 lua/hardline/whitespace.lua diff --git a/lua/hardline.lua b/lua/hardline.lua index 96be2a7..8ce9538 100644 --- a/lua/hardline.lua +++ b/lua/hardline.lua @@ -27,6 +27,11 @@ M.sections = { require('hardline.mode'), ' ', require('hardline.git'), ' ', require('hardline.file'), ' ', + '%=', + -- require('hardline.lsp'), + -- require('hardline.whitespace'), + require('hardline.filetype'), ' ', + require('hardline.line'), } -------------------- HELPERS ------------------------------- diff --git a/lua/hardline/file.lua b/lua/hardline/file.lua index 6caa21c..12dfbb0 100644 --- a/lua/hardline/file.lua +++ b/lua/hardline/file.lua @@ -11,6 +11,7 @@ end function M.get_component() return table.concat({ + [[%<]], [[%{luaeval('require("hardline.file").get_name()')}]], M.get_mode(), }) diff --git a/lua/hardline/filetype.lua b/lua/hardline/filetype.lua new file mode 100644 index 0000000..8c663e8 --- /dev/null +++ b/lua/hardline/filetype.lua @@ -0,0 +1,15 @@ +local vim = vim +local bo = vim.bo +local M = {} + +function M.get_filetype() + return bo.filetype +end + +function M.get_component() + return table.concat({ + [[%{luaeval('require("hardline.filetype").get_filetype()')}]], + }) +end + +return M diff --git a/lua/hardline/git.lua b/lua/hardline/git.lua index bdeeec1..2e3afb5 100644 --- a/lua/hardline/git.lua +++ b/lua/hardline/git.lua @@ -15,7 +15,10 @@ function M.get_hunks() end function M.get_branch() - return '' + if not g.loaded_gitgutter then + return '' + end + return string.format(' %s', fn.FugitiveHead()) end function M.get_component() diff --git a/lua/hardline/line.lua b/lua/hardline/line.lua new file mode 100644 index 0000000..547e4c2 --- /dev/null +++ b/lua/hardline/line.lua @@ -0,0 +1,24 @@ +local cmd, fn, vim = vim.cmd, vim.fn, vim +local M = {} + +function M.get_line() + return string.format('%03d/%03d', fn.line('.'), fn.line('$')) +end + +function M.get_column() + return string.format('%03d/%03d', fn.col('.'), fn.col('$') - 1) +end + +function M.get_percent() + return '%03p%%' +end + +function M.get_component() + return table.concat({ + [[%{luaeval('require("hardline.line").get_line()')}]], ':', + [[%{luaeval('require("hardline.line").get_column()')}]], ' ', + M.get_percent(), + }) +end + +return M diff --git a/lua/hardline/lsp.lua b/lua/hardline/lsp.lua new file mode 100644 index 0000000..1aea55b --- /dev/null +++ b/lua/hardline/lsp.lua @@ -0,0 +1,8 @@ +local fn, vim = vim.fn, vim +local M = {} + +function M.get_component() + return table.concat({}) +end + +return M diff --git a/lua/hardline/whitespace.lua b/lua/hardline/whitespace.lua new file mode 100644 index 0000000..1aea55b --- /dev/null +++ b/lua/hardline/whitespace.lua @@ -0,0 +1,8 @@ +local fn, vim = vim.fn, vim +local M = {} + +function M.get_component() + return table.concat({}) +end + +return M