From 5a8efb35dc589c6bf24379c7fd2f5708f4d0c5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Harnes?= Date: Wed, 13 Mar 2024 10:28:48 +0100 Subject: [PATCH] fix: disable health message on startup (#50) --- lua/img-clip/init.lua | 6 ------ lua/img-clip/paste.lua | 6 ++++++ tests/paste_spec.lua | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lua/img-clip/init.lua b/lua/img-clip/init.lua index 5acc0d4..9871b54 100644 --- a/lua/img-clip/init.lua +++ b/lua/img-clip/init.lua @@ -1,17 +1,11 @@ -local clipboard = require("img-clip.clipboard") local config = require("img-clip.config") local paste = require("img-clip.paste") -local util = require("img-clip.util") local M = {} ---@param opts? table M.setup = function(opts) config.setup(opts) - - if not clipboard.get_clip_cmd() then - util.error("Could not get clipboard command. See :checkhealth img-clip.") - end end ---@param opts? table diff --git a/lua/img-clip/paste.lua b/lua/img-clip/paste.lua index a05a72a..1bfadfd 100644 --- a/lua/img-clip/paste.lua +++ b/lua/img-clip/paste.lua @@ -24,6 +24,12 @@ M.paste_image = function(opts, input) return false end + -- ensure clipboard command is valid + if not clipboard.get_clip_cmd() then + util.error("Could not get clipboard command. See :checkhealth img-clip.") + return false + end + -- if no input is provided, check clipboard content if clipboard.content_is_image() then return M.paste_image_from_clipboard(opts) diff --git a/tests/paste_spec.lua b/tests/paste_spec.lua index a73d14c..7d0b273 100644 --- a/tests/paste_spec.lua +++ b/tests/paste_spec.lua @@ -1,6 +1,7 @@ local clipboard = require("img-clip.clipboard") local paste = require("img-clip.paste") local config = require("img-clip.config") +local util = require("img-clip.util") local spy = require("luassert.spy") describe("paste", function() @@ -9,6 +10,15 @@ describe("paste", function() config.get_config = function() return config.opts end + os.getenv = function(env) + return env == "DISPLAY" + end + util.has = function() + return false + end + util.executable = function(cmd) + return cmd == "xclip" + end end) describe("paste_image", function()