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

features/add-float-titles #412

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lua/toggleterm/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ end
---@type Terminal[]
local terminals = {}

---@class FloatOpts
---@field border string | string[]
---@field title string | fun(count: integer, term: Terminal): string
---@field width integer
---@field height integer
---@field row integer
---@field col integer
---@field relative boolean
---@field winblend integer

--- @class TermCreateArgs
--- @field cmd string
--- @field direction? string the layout style for the terminal
--- @field id number?
--- @field highlights table<string, table<string, string>>?
--- @field dir string? the directory for the terminal
--- @field count number? the count that triggers that specific terminal
--- @field count integer? the count that triggers that specific terminal
--- @field display_name string?
--- @field hidden boolean? whether or not to include this terminal in the terminals list
--- @field close_on_exit boolean? whether or not to close the terminal window when the process exits
Expand All @@ -77,7 +87,7 @@ local terminals = {}
--- @field hidden boolean whether or not to include this terminal in the terminals list
--- @field close_on_exit boolean? whether or not to close the terminal window when the process exits
--- @field auto_scroll boolean? whether or not to scroll down on terminal output
--- @field float_opts table<string, any>?
--- @field float_opts FloatOpts?
--- @field display_name string?
--- @field env table<string, string> environmental variables passed to jobstart()
--- @field clear_env boolean use clean job environment, passed to jobstart()
Expand Down Expand Up @@ -267,7 +277,11 @@ function Terminal:persist_mode()
self.__state.mode = m
end

---@package
function Terminal:float_title()
local count = #M.get_all(true)
return fmt(" toggleterm (%d/%d) ", self.id, count + 1)
end

function Terminal:_display_name() return self.display_name or vim.split(self.name, ";")[1] end

function Terminal:close()
Expand Down
8 changes: 5 additions & 3 deletions lua/toggleterm/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ local hl_end = "%*"
---@param id number
---@return string
function M.winbar(id)
local terms = require("toggleterm.terminal").get_all()
local terminals = require("toggleterm.terminal").get_all()
local str = " "
for _, t in pairs(terms) do
for _, t in pairs(terminals) do
local h = id == t.id and "WinBarActive" or "WinBarInactive"
str = str
.. fmt("%%%d@v:lua.___toggleterm_winbar_click@", t.id)
Expand Down Expand Up @@ -286,7 +286,7 @@ function M._get_float_config(term, opening)
row = vim.F.if_nil(M._resolve_size(opts.row, term), row)
col = vim.F.if_nil(M._resolve_size(opts.col, term), col)

return {
local win_opts = {
row = row,
col = col,
relative = opts.relative or "editor",
Expand All @@ -295,6 +295,8 @@ function M._get_float_config(term, opening)
height = height,
border = opening and border or nil,
}
if utils.is_nightly() then win_opts.title = term:float_title() end
return win_opts
end

--- @param size number
Expand Down
2 changes: 1 addition & 1 deletion lua/toggleterm/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local levels = vim.log.levels

function M.is_nightly()
local v = vim.version()
return v.minor >= 8
return v.minor >= 9
end

---@alias error_types 'error' | 'info' | 'warn'
Expand Down