refactor nvim: 判定GUI Terminal 模組化

This commit is contained in:
Yuan Chiu 2025-05-06 21:20:20 +08:00
parent 2ff59608f5
commit cee037e8dd
3 changed files with 19 additions and 28 deletions

View File

@ -3,20 +3,7 @@ return {
"3rd/image.nvim", "3rd/image.nvim",
build = false, -- so that it doesn't build the rock https://github.com/3rd/image.nvim/issues/91#issuecomment-2453430239 build = false, -- so that it doesn't build the rock https://github.com/3rd/image.nvim/issues/91#issuecomment-2453430239
-- cond = not vim.g.neovide and not vim.fn.has("goneovim") == 1 and not vim.fn.has("gui_running") == 1, -- cond = not vim.g.neovide and not vim.fn.has("goneovim") == 1 and not vim.fn.has("gui_running") == 1,
cond = function() cond = require("tools.gui").is_enable_sixel(),
-- 如果是在 GUI如 NeoVide、Goneovim則不啟用插件
if vim.g.neovide or vim.fn.has("goneovim") == 1 or vim.fn.has("gui_running") == 1 then
return false
end
-- 獲取 TERM 環境變數
local term = vim.fn.getenv("TERM")
-- 檢查是否是常見的文字終端
local is_terminal = term and (term:match("xterm") or term:match("screen") or term:match("tmux") or term:match("linux"))
-- 如果是文字終端,則啟用插件
return is_terminal ~= nil
end,
lazy = false, lazy = false,
opts = { opts = {
backend = "ueberzug", backend = "ueberzug",

View File

@ -1,20 +1,7 @@
return { return {
-- { "psliwka/vim-smoothie" }, -- { "psliwka/vim-smoothie" },
{ "karb94/neoscroll.nvim", { "karb94/neoscroll.nvim",
cond = function() cond = require("tools.gui").is_enable_sixel(),
-- 如果是在 GUI如 NeoVide、Goneovim則不啟用插件
if vim.g.neovide or vim.fn.has("goneovim") == 1 or vim.fn.has("gui_running") == 1 then
return false
end
-- 獲取 TERM 環境變數
local term = vim.fn.getenv("TERM")
-- 檢查是否是常見的文字終端
local is_terminal = term and (term:match("xterm") or term:match("screen") or term:match("tmux") or term:match("linux"))
-- 如果是文字終端,則啟用插件
return is_terminal ~= nil
end,
opts = { opts = {
mappings = { -- Keys to be mapped to their corresponding default scrolling animation mappings = { -- Keys to be mapped to their corresponding default scrolling animation
'<C-u>', '<C-d>', '<C-u>', '<C-d>',

View File

@ -16,4 +16,21 @@ function M.is_graphical()
return term_program or display or wayland and true or false return term_program or display or wayland and true or false
end end
--- 當前終端機環境是否在圖形環境裡面並不使用專用GUI APP(NeoVide)
--- @return boolean is_enable_sixel
function M.is_enable_sixel()
-- 如果是在 GUI如 NeoVide、Goneovim則不啟用插件
if vim.g.neovide or vim.fn.has("goneovim") == 1 or vim.fn.has("gui_running") == 1 then
return false
end
-- 獲取 TERM 環境變數
local term = vim.fn.getenv("TERM")
-- 檢查是否是常見的文字終端
local is_terminal = term and (term:match("xterm") or term:match("screen") or term:match("tmux") or term:match("linux"))
-- 如果是文字終端,則啟用插件
return is_terminal ~= nil
end
return M return M