Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message if curl is not installed #58

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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