From cb197fb6063c8c2e06a362954d62911cca53c068 Mon Sep 17 00:00:00 2001 From: Hanchin Hsieh Date: Thu, 29 Aug 2024 12:00:19 +0800 Subject: [PATCH] feat(clipboard): support windows (#345) Signed-off-by: Hanchin Hsieh --- README.md | 2 ++ lua/avante/clipboard.lua | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f3d5148..ea55523 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ Install `avante.nvim` using [lazy.nvim](https://github.com/folke/lazy.nvim): drag_and_drop = { insert_mode = true, }, + -- required for Windows users + use_absolute_path = true, }, }, }, diff --git a/lua/avante/clipboard.lua b/lua/avante/clipboard.lua index 4ee649b..9b85ab3 100644 --- a/lua/avante/clipboard.lua +++ b/lua/avante/clipboard.lua @@ -61,13 +61,14 @@ M.get_base64_content = function(filepath) local output if os_mapping == "darwin" or os_mapping == "linux" then output = Utils.shell_run(("cat %s | base64 | tr -d '\n'"):format(filepath)) - if output.code == 0 then - return output.stdout - else - error("Failed to convert image to base64") - end else - Utils.warn("Windows is not supported yet", { title = "Avante" }) + output = + Utils.shell_run(("([Convert]::ToBase64String([IO.File]::ReadAllBytes('%s')) -replace '`r`n')"):format(filepath)) + end + if output.code == 0 then + return output.stdout + else + error("Failed to convert image to base64") end end