Skip to content

Commit

Permalink
refactor: move are_we_wezterm() function to mux.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Feb 17, 2024
1 parent 33c8507 commit 159c482
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lua/smart-splits/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local types = require('smart-splits.types')
local AtEdgeBehavior = types.AtEdgeBehavior
local Multiplexer = types.Multiplexer
local utils = require('smart-splits.utils')
local mux_utils = require('smart-splits.mux.utils')

---@class SmartResizeModeHooks
---@field on_enter fun()|nil
Expand Down Expand Up @@ -82,7 +83,7 @@ function M.set_default_multiplexer()

-- if running in a GUI instead of terminal TUI, disable mux
-- because you aren't in any terminal, you're in a Neovim GUI
if utils.are_we_gui() then
if mux_utils.are_we_gui() then
config.multiplexer_integration = false
return nil
end
Expand Down
34 changes: 34 additions & 0 deletions lua/smart-splits/mux/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local M = {}

---Check if Neovim is running in Wezterm TUI
---@return boolean
function M.are_we_wezterm()
if M.are_we_gui() then
return false
end
local term = vim.trim((vim.env.TERM_PROGRAM or ''):lower())
local wezterm_pane = vim.trim(vim.env.WEZTERM_PANE or '')
return term == 'wezterm' or wezterm_pane ~= ''
end

function M.are_we_tmux()
if M.are_we_gui() then
return false
end

local term = vim.trim((vim.env.TERM_PROGRAM or ''):lower())
return term == 'tmux'
end

---Check if Neovim is running in a GUI (rather than TUI)
---@return boolean
function M.are_we_gui()
-- if running in a GUI instead of terminal TUI, disable mux
-- because you aren't in any terminal, you're in a Neovim GUI
local current_ui = vim.tbl_filter(function(ui)
return ui.chan == 1
end, vim.api.nvim_list_uis())[1]
return current_ui ~= nil and not current_ui.stdin_tty and not current_ui.stdout_tty
end

return M
22 changes: 0 additions & 22 deletions lua/smart-splits/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,4 @@ function M.is_floating_window(win_id)
return win_cfg and (win_cfg.relative ~= '' or not win_cfg.relative)
end

---Check if Neovim is running in Wezterm TUI
---@return boolean
function M.are_we_wezterm()
if M.are_we_gui() then
return false
end
local term = vim.trim((vim.env.TERM_PROGRAM or ''):lower())
local wezterm_pane = vim.trim(vim.env.WEZTERM_PANE or '')
return term == 'wezterm' or wezterm_pane ~= ''
end

---Check if Neovim is running in a GUI (rather than TUI)
---@return boolean
function M.are_we_gui()
-- if running in a GUI instead of terminal TUI, disable mux
-- because you aren't in any terminal, you're in a Neovim GUI
local current_ui = vim.tbl_filter(function(ui)
return ui.chan == 1
end, vim.api.nvim_list_uis())[1]
return current_ui ~= nil and not current_ui.stdin_tty and not current_ui.stdout_tty
end

return M
2 changes: 1 addition & 1 deletion plugin/smart-splits.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function s:format_var(val)
return printf("\033]1337;SetUserVar=IS_NVIM=%s\007", s:encode_b64(a:val, 0))
endfunction

let s:are_we_wezterm = luaeval("require('smart-splits.utils').are_we_wezterm()")
let s:are_we_wezterm = luaeval("require('smart-splits.mux.utils').are_we_wezterm()")

if s:are_we_wezterm
call s:write(s:format_var("true"))
Expand Down

0 comments on commit 159c482

Please sign in to comment.