Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Feb 14, 2024 · 21 comments

Comments

@ghost
Copy link

ghost commented Feb 14, 2024

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
Copy link
Owner

tamton-aquib commented Feb 14, 2024

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
Copy link
Author

ghost commented Feb 14, 2024

@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
Copy link
Owner

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
Copy link
Author

ghost commented Feb 14, 2024

@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

@ghost ghost changed the title Vim strings dont seem to work Using Vim strings (vim.bo.ft), netrw state and custom buffer-specific configs Feb 14, 2024
@tamton-aquib
Copy link
Owner

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
Copy link
Author

ghost commented Feb 14, 2024

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
Copy link
Owner

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
Copy link
Author

ghost commented Feb 14, 2024

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

@ghost ghost changed the title Using Vim strings (vim.bo.ft), netrw state and custom buffer-specific configs Using Vim strings (vim.bo.ft), netrw state, custom buffer-specific configs and Windows tililng problem Feb 14, 2024
@tamton-aquib
Copy link
Owner

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
Copy link
Author

ghost commented Feb 15, 2024

@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
Copy link
Owner

So hey @AXVIII3,

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

@ghost
Copy link
Author

ghost commented Feb 28, 2024

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

@tamton-aquib
Copy link
Owner

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

@tamton-aquib
Copy link
Owner

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

@ghost
Copy link
Author

ghost commented Feb 28, 2024

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

@ghost ghost closed this as completed Feb 28, 2024
@ghost
Copy link
Author

ghost commented Feb 28, 2024

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
Copy link
Author

ghost commented Feb 28, 2024

Thanks a ton though!! :)

@ghost
Copy link
Author

ghost commented Mar 8, 2024

@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 ghost reopened this Mar 8, 2024
@ghost
Copy link
Author

ghost commented Mar 8, 2024

Reopened just to gain your attention 😉 WIll close soon

@ghost ghost changed the title Using Vim strings (vim.bo.ft), netrw state, custom buffer-specific configs and Windows tililng problem Using Vim strings (vim.bo.ft), netrw state, color on start, custom buffer-specific configs and Windows tililng problem Mar 8, 2024
@tamton-aquib
Copy link
Owner

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
Copy link
Author

ghost commented Mar 8, 2024

Sure!

@ghost ghost closed this as completed Mar 8, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant