Skip to content

Commit

Permalink
Show error message if curl is not installed (#58)
Browse files Browse the repository at this point in the history
* handled launch process failed error

* stated curl as dependency in README

* fixed intentional misspelt curl
  • Loading branch information
chomosuke authored Oct 16, 2024
1 parent 0081e07 commit 0f43ed7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ https://github.com/chomosuke/typst-preview.nvim/assets/38484873/9f8ecf0f-aa1c-4e

## 📦 Installation

#### Dependencies
- curl

**Lazy.nvim:**

```lua
Expand Down
24 changes: 18 additions & 6 deletions lua/typst-preview/fetch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ local function download_bin(bin, callback)
local stdin = nil
local stdout = assert(vim.uv.new_pipe())
local stderr = assert(vim.uv.new_pipe())
-- TODO add wget support
vim.uv.spawn('curl', {
args = { '-L', url, '--create-dirs', '--output', path, '--progress-bar' },
stdio = { stdin, stdout, stderr },
}, function(code, _)

local function after_curl(code)
if code ~= 0 then
utils.notify(
'Downloading ' .. name .. ' binary failed, exit code: ' .. code
Expand All @@ -143,7 +140,22 @@ local function download_bin(bin, callback)
callback()
end
end
end)
end

-- TODO add wget support
local handle, err = vim.uv.spawn('curl', {
args = { '-L', url, '--create-dirs', '--output', path, '--progress-bar' },
stdio = { stdin, stdout, stderr },
}, after_curl)

if handle == nil then
utils.notify(
'Launching curl failed: '
.. err
.. '\nMake sure curl is installed on the system.'
)
end

local function read_progress(err, data)
if err then
error(err)
Expand Down

0 comments on commit 0f43ed7

Please sign in to comment.