tabby.nvim icon indicating copy to clipboard operation
tabby.nvim copied to clipboard

File icon

Open EpsilonKu opened this issue 3 years ago • 6 comments

How can I config to show file icon on tabs.

EpsilonKu avatar Jan 03 '22 17:01 EpsilonKu

For now, you can use nvim-web-devicons to add file icon.

  • install nvim-web-devicons and start it.
  • require'nvim-web-devicons'.setup {}
  • require'nvim-web-devicons'.get_icon(filename, extension, options)

and you should get filename and extension from tabid. Overall, the code will looks like:

local focus_win = vim.api.nvim_tabpage_get_win(tabid)
local filename = require("tabby.filename").tail(focus_win)
local extension =   local fname = vim.fn.fnamemodify(name, ':e')
local icon = require'nvim-web-devicons'.get_icon(filename, extension)

nanozuki avatar Jan 06 '22 04:01 nanozuki

A little survey: Is it helpful to add a helper function to get the file icon in tabby.nvim?

nanozuki avatar Jan 06 '22 04:01 nanozuki

Yeah, will be good.

EpsilonKu avatar Jan 11 '22 06:01 EpsilonKu

Even more important is the buf modified sign. What do u thing about this:

local function win_label(winid, top)
  local icon = top and '' or ''
  local fname = require("tabby.filename").tail(winid)
  local extension = vim.fn.fnamemodify(fname, ':e')
  local fileIcon = require'nvim-web-devicons'.get_icon(filename, extension)
  local buid = vim.api.nvim_win_get_buf(winid)
  local is_modified = vim.api.nvim_buf_get_option(buid, 'modified')
  local modifiedIcon = is_modified and '' or ''
  return string.format(' %s  %s %s %s', icon, fileIcon, filename.unique(winid), modifiedIcon)
end

Maddin-619 avatar Jan 17 '22 19:01 Maddin-619

I think this is workable. I plan to improve the configuration experience, use less code to configure these things. I will update in this issue if that is completed.

nanozuki avatar Jan 18 '22 12:01 nanozuki

Let me share my way.

local function buffer_render (bufid, is_current)
	local buftype = vim.bo[bufid].buftype
	local modified = vim.bo[bufid].modified
	local modified_icon = modified and '' or ' '
	local path = vim.fn.bufname(bufid);
	local extension = vim.fn.fnamemodify(path, ":e")
	local filename = vim.fn.fnamemodify(path, ":t")
	local fileicon = require'nvim-web-devicons'.get_icon (filename, extension, { default = true})
	local buf_name = ' ' .. fileicon .. ' ' .. filename ..' ' .. modified_icon .. ' '
	local buf_color = is_current and active_tab_hl or inactive_tab_hl
	return {
		type = 'text',
		text = {
			string.format(' %s ', buf_name) ,
				hl = buf_color,
			}
	}
end
local components = function()
	local cur_bufid = vim.api.nvim_get_current_buf()
	for _, bufid in ipairs(vim.api.nvim_list_bufs()) do
		if vim.api.nvim_buf_is_valid(bufid) and vim.bo[bufid].buflisted then
			local is_current = false;
			if bufid == cur_bufid then
				is_current = true
			end
			local buf_render = buffer_render (bufid,is_current)
			table.insert(coms, buf_render)
			table.insert(coms,
				{
					type = 'text',
					text = {
						' ',
						hl = 'TabLineFill'
					}
				}
			)
		end
	end
        --- etc
end

EpsilonKu avatar Jan 20 '22 15:01 EpsilonKu

I rewrite the config API in case to easily add helper functions. For example in setup, you can add a file icon by win object:

line.wins_in_tab(line.api.get_current_tab()).foreach(function(win)
  return {
    line.sep('', theme.win, theme.fill),
    win.is_current() and '' or '',
    win.file_icon(),
    win.buf_name(),
    line.sep('', theme.win, theme.fill),
    hl = theme.win,
    margin = ' ',
  }
end),

Detail: https://github.com/nanozuki/tabby.nvim#win

nanozuki avatar Sep 28 '22 02:09 nanozuki