tamton-aquib / staline.nvim

A modern lightweight statusline and bufferline plugin for neovim in lua.
MIT License
380 stars 17 forks source link

Using Vim strings (vim.bo.ft), netrw state, color on start, custom buffer-specific configs and Windows tililng problem #58

Closed ghost closed 8 months ago

ghost commented 9 months ago

There is this string vim.bo.filetype image image

I want a section with this string.. So I edited the premade pebble config... however it just shows an empty string (right side) image

Full config

return function()
    require("staline").setup({
        sections = {
            left = {
                " ", "right_sep", "-mode", "left_sep", " ",
                "right_sep", "-file_name", "left_sep", " ",
                "right_sep", "-branch", "left_sep", " ",
            },
            mid  = { "lsp" },
            right =  {
                "right_sep", "- ", vim.bo.filetype:upper(), "- ", "left_sep", " ",
                "right_sep", "-line_column", "left_sep", " ",
            }
        },
        defaults = {
            fg = "#181a1f",
            left_separator = "",
            right_separator = "",
            true_colors = true,
            line_column = "%l:%c ~ %p%% ",
        },
        mode_colors = {
            n  = "#98c379",
            i  = "#d19a66",
            ic = "#181a23",
            c  = "#61afef",
            v  = "#c678dd",
            V  = "#9a6dd1",
            s  = "#123456",
            S  = "#000000",
            t  = "#ffffff",
            r  = "#971034",
            R  = "#546576"
        },
        mode_icons = {
            n = "Normal",
            i = "Insert",
            c = "Command",
            v = "Visual",
            no = "󰋜 ",
            niI = "󰋜 ",
            niR = "󰋜 ",
            niV = "󰋜 ",
            nov = "󰋜 ",
            noV = "󰋜 ",
            ic = "󰏫 ",
            ix = "󰏫 ",
            s = "󰏫 ",
            S = "󰏫 ",
            V = "󰈈 ",
            r = "󰛔 ",
            t = " " ,
            R = " ",
        }
    });
end
tamton-aquib commented 9 months ago

Heyyo @AXVIII3, Have you tried wrapping it inside a function?

Something like:

-- ...
            right =  {
                "right_sep", "- ", function() return vim.bo.ft:upper() end, "- ", "left_sep", " ",
                "right_sep", "-line_column", "left_sep", " ",
            }
-- ...
ghost commented 9 months ago

@tamton-aquib Hey! I hadn't though of that.... Sorry I probably should have experimented more before filing this issue... Also how you I invert the colour of this text?

image

tamton-aquib commented 9 months ago

the - inside the function isnt implemented. But we could return a table like {"HighlighName", "string"}.

In this case, we could do something like:

--- Since "StalineFill" is the highlight for filling bg

function() return { "StalineFill", vim.bo.filetype:upper() } end
ghost commented 9 months ago

@tamton-aquib Heyy... that worked great... thanks for your help.... and this was quick too! Great plugin btw! I found you via the reddit post you made years ago... Still find it amazing that you made this when you were only 12days (if I'm not wrong) into vim

Also one last question I'd like to bother you with.. sometimes the plugin reverts to the base nvim status line when using Netrw... while sometimes it doesnt.. See video... Also I noticed that you had seperate configs for nvimtree, dashboard and packer... so is it possible to create different configs for different buffertypes?

Untitled video - Made with Clipchamp

tamton-aquib commented 9 months ago

I found you via the reddit post you made years ago.

That might not be me 😅 . This plugin was made maybe 4 years ago.

sometimes the plugin reverts to the base nvim status line when using Netrw

That is strange. I dont use netrw much since i'm still on nvim-tree, but I'll check.

is it possible to create different configs for different buffertypes

Buffer specific lines can be configured via special_table opt in setup.

For example:

require("staline").setup({
    special_table = {
        -- Where "netrw" key is the filetype. 
        netrw = { 'NetRW', ' ' },
    },
}
ghost commented 9 months ago

That might not be me 😅 . This plugin was made maybe 4 years ago.

Oops... Sorry.. I used to use Lualine which was tremendously slow... So I have been researching many status lines today... so I mixed up some... this is a very good plugin nonetheless... love the customizability it provides

Buffer specific lines can be configured via special_table opt in setup.

So these special tables are similar to the sections table but for specific file types?

tamton-aquib commented 9 months ago

So these special tables are similar to the sections table but for specific file types?

Hmm nope, its just a table with 2 values. The text and the icon for the specific filetype key. (I designed this 3-4 years ago so it isnt that good 😅 )

ghost commented 9 months ago

Hmm nope, its just a table with 2 values. The text and the icon for the specific filetype key. (I designed this 3-4 years ago so it isnt that good 😅 )

Yeah I figured that one out pretty soon..... And absolutely not... this is an amazing plugins... better than anything I (or most) could write

Also one final thing.. I swear I'll stop bothering you after this This isnt important and is a rare weird edge case... but with pages like help and netrw... the status lines exhibit some weird behaviours which do not really need to be fixed...

Sometimes they duplicate for all buffers image

And somethimes does this image image

tamton-aquib commented 9 months ago

Heyyo @AXVIII3,

I think that behaviour is because of me not taking into account the laststatus option. I started assuming everyone moved to laststatus=3(aka global statusline).

I'll check it this/next week.

ghost commented 9 months ago

@tamton-aquib Alright! Thanks a lot for your help

I think that behaviour is because of me not taking into account the laststatus option. I started assuming everyone moved to laststatus=3(aka global statusline).

I see... I actually like the concept of laststatus = 3.... I'm switching to that

I'll check it this/next week.

Sure sure.. no worries... take your time 👍🏻

Cheers :)

tamton-aquib commented 8 months ago

So hey @AXVIII3,

Im closing this issue for now. Feel free to re-open if there are any more issues 👍🏻

ghost commented 8 months ago

@tamton-aquib Yeah sure... dont have any breaking problems.... any luck with NetRw though?

tamton-aquib commented 8 months ago

Ah yes sorry, I did fix it but forgot to push.

tamton-aquib commented 8 months ago

I have pushed a fix, can you check? @AXVIII3 (No hurry btw)

ghost commented 8 months ago

It works great with NetRw now! No need to be sorry... I'm the one who dragged you into fixing a niche issue 😅

ghost commented 8 months ago

Also I was contemplating even mentioning this issue as its very minor. But the status line doesnt appear immediately after vim is opened... it appears after a file is opened.... it also seems to appear on some buffer functions such as while changing folders or opening NetRw but the colors dont work in those cases...

I am mentioning just the sake of it existing... not an issue per se

ghost commented 8 months ago

Thanks a ton though!! :)

ghost commented 8 months ago

@tamton-aquib I had some free time, so I decided to look into the code for a bit In staline.nvim you have this function to "create" the status line

M.get_statusline = function(status)
    if conf.special_table[vim.bo.ft] ~= nil then
        local special = conf.special_table[vim.bo.ft]
        return "%#Staline#%=" .. special[2] .. special[1] .. "%="
    end

    M.sections = {}

    local mode = vim.api.nvim_get_mode()['mode']
    local fgColor = status and conf.mode_colors[mode] or t.inactive_color
    local bgColor = status and t.bg or t.inactive_bgcolor
    local modeIcon = conf.mode_icons[mode] or "󰋜 "

    local f_name = t.full_path and '%F' or '%t'
    -- TODO: original color of icon
    local f_icon = util.get_file_icon(vim.fn.expand('%:t'), vim.fn.expand('%:e'))
    local edited = vim.bo.mod and t.mod_symbol or ""
    -- TODO: need to support b, or mb?
    local size = ("%.1f"):format(vim.fn.getfsize(vim.api.nvim_buf_get_name(0))/1024)

    call_highlights(fgColor, bgColor)

  .
  .
  .
  .
  .
    end

The if statement in the first few lines blocks the execution of the call_highlights() function which comes later if the buffer is something like the dashboard or netrw. So I pushed that function above the if statement. This seemed to fix my issue. But I am not sure if any other issues would be created. What do you think about this?

M.get_statusline = function(status)
    local mode = vim.api.nvim_get_mode()['mode']
    local fgColor = status and conf.mode_colors[mode] or t.inactive_color
    local bgColor = status and t.bg or t.inactive_bgcolor

    call_highlights(fgColor, bgColor)

    if conf.special_table[vim.bo.ft] ~= nil then
        local special = conf.special_table[vim.bo.ft]
        return "%#Staline#%=" .. special[2] .. special[1] .. "%="
    end

    M.sections = {}

    local modeIcon = conf.mode_icons[mode] or "󰋜 "

    local f_name = t.full_path and '%F' or '%t'
    -- TODO: original color of icon
    local f_icon = util.get_file_icon(vim.fn.expand('%:t'), vim.fn.expand('%:e'))
    local edited = vim.bo.mod and t.mod_symbol or ""
    -- TODO: need to support b, or mb?
    local size = ("%.1f"):format(vim.fn.getfsize(vim.api.nvim_buf_get_name(0))/1024)

    call_highlights(fgColor, bgColor)
end
ghost commented 8 months ago

Reopened just to gain your attention 😉 WIll close soon

tamton-aquib commented 8 months ago

Hi @AXVIII3,

Could you open a new issue for this? 😅 Since the original issue and this new issue seems to be different, it would be better to track in a new issue.

ghost commented 8 months ago

Sure!