From cee037e8dd1e2c233585a4cf53c706179fecc99f Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Tue, 6 May 2025 21:20:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20nvim:=20=E5=88=A4=E5=AE=9AGUI=20Term?= =?UTF-8?q?inal=20=E6=A8=A1=E7=B5=84=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exact_plugins/exact_components/image.lua | 15 +-------------- .../exact_lua/exact_plugins/exact_ui/scroll.lua | 15 +-------------- dot_config/nvim/exact_lua/exact_tools/gui.lua | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_components/image.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_components/image.lua index 16d8088..5b603ee 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_components/image.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_components/image.lua @@ -3,20 +3,7 @@ return { "3rd/image.nvim", 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 = function() - -- 如果是在 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, + cond = require("tools.gui").is_enable_sixel(), lazy = false, opts = { backend = "ueberzug", diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_ui/scroll.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_ui/scroll.lua index 9f35b25..21c5b77 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_ui/scroll.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_ui/scroll.lua @@ -1,20 +1,7 @@ return { -- { "psliwka/vim-smoothie" }, { "karb94/neoscroll.nvim", - cond = function() - -- 如果是在 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, + cond = require("tools.gui").is_enable_sixel(), opts = { mappings = { -- Keys to be mapped to their corresponding default scrolling animation '', '', diff --git a/dot_config/nvim/exact_lua/exact_tools/gui.lua b/dot_config/nvim/exact_lua/exact_tools/gui.lua index 6328b9f..1054739 100644 --- a/dot_config/nvim/exact_lua/exact_tools/gui.lua +++ b/dot_config/nvim/exact_lua/exact_tools/gui.lua @@ -16,4 +16,21 @@ function M.is_graphical() return term_program or display or wayland and true or false 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