feat: add datetime component (#973)
This commit is contained in:
parent
0695853055
commit
c680fb4c25
14
README.md
14
README.md
|
@ -635,6 +635,20 @@ sections = {
|
|||
}
|
||||
```
|
||||
|
||||
#### datetime component options
|
||||
|
||||
```lua
|
||||
sections = {
|
||||
lualine_a = {
|
||||
{
|
||||
'datetime',
|
||||
-- options: default, us, uk, iso, or your own format string ("%H:%M", etc..)
|
||||
style = 'default'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### tabs component options
|
||||
|
||||
```lua
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
-- Copyright (c) 2023 Willothy
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local lualine_require = require('lualine_require')
|
||||
local M = lualine_require.require('lualine.component'):extend()
|
||||
|
||||
local default_options = {
|
||||
-- default, us, uk, iso, or format (ex. "%d/%m/%Y ...")
|
||||
style = 'default',
|
||||
}
|
||||
|
||||
function M:init(options)
|
||||
M.super.init(self, options)
|
||||
self.options = vim.tbl_deep_extend('keep', self.options or {}, default_options)
|
||||
end
|
||||
|
||||
function M:update_status()
|
||||
local fmt = self.options.style
|
||||
if self.options.style == 'default' then
|
||||
fmt = '%A, %B %d | %H:%M'
|
||||
elseif self.options.style == 'us' then
|
||||
fmt = '%m/%d/%Y'
|
||||
elseif self.options.style == 'uk' then
|
||||
fmt = '%d/%m/%Y'
|
||||
elseif self.options.style == 'iso' then
|
||||
fmt = '%Y-%m-%d'
|
||||
end
|
||||
|
||||
return os.date(fmt)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Reference in New Issue