From 5a15827d7aaac261f0ad304babfa26d8ff90127e Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Mon, 26 Jun 2023 20:12:20 +0300 Subject: [PATCH] merge macos and gnu clipboard implementations --- platform.lua | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/platform.lua b/platform.lua index 5d5bd27..291d286 100644 --- a/platform.lua +++ b/platform.lua @@ -45,22 +45,19 @@ this.clipboard = (function() self.copy = function(text) return h.subprocess({ self.clip_exe, '-command', 'Set-Clipboard -Value ' .. text }) end - elseif this.platform == this.Platform.macos then - self.clip_exe = "pbcopy" - self.copy = function(text) - local handle = io.popen("LANG=en_US.UTF-8 pbcopy", 'w') - if handle then - handle:write(text) - local suc, exit, code = handle:close() - return { status = code } - else - return { status = 1 } - end - end else - self.clip_exe = h.is_wayland() and "wl-copy" or "xclip" + if this.platform == this.Platform.macos then + self.clip_exe = "pbcopy" + self.clip_cmd = "LANG=en_US.UTF-8 pbcopy" + elseif h.is_wayland() then + self.clip_exe = "wl-copy" + self.clip_cmd = "wl-copy" + else + self.clip_exe = "xclip" + self.clip_cmd = "xclip -i -selection clipboard" + end self.copy = function(text) - local handle = io.popen(h.is_wayland() and "wl-copy" or "xclip -i -selection clipboard", 'w') + local handle = io.popen(self.clip_cmd, 'w') if handle then handle:write(text) local suc, exit, code = handle:close()