Skip to content

Commit 19abcd9

Browse files
committed
nvim 0.10 updates
1 parent 4524d2b commit 19abcd9

File tree

3 files changed

+37
-104
lines changed

3 files changed

+37
-104
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## Requirements
1212

13-
Neovim 0.8+
13+
Neovim 0.10+
1414

1515
## Installing
1616

lua/carbon-now.lua

+36-38
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
11
-- module represents a lua module for the plugin
2-
local types = require("types")
2+
---@module 'carbon-now'
3+
---@class Carbon
4+
---@field config ConfigSchema
5+
---@field setup SetupFunc
36
local Carbon = {}
47

8+
--- Types
9+
---@alias Themes '3024-night' | 'a11y-dark' | 'blackboard' | 'base-16-dark' | 'base-16-light' | 'cobalt' | 'dracula-pro' | 'duotone' | 'hopscotch' | 'lucario' | 'material' | 'monokai' | 'night-owl' | 'nord' | 'oceanic-next' | 'one-light' | 'one-dark' | 'panda' | 'paraiso' | 'seti' | 'shades-of-purple' | 'solarized-dark' | 'solarized-light' | 'synthwave-84' | 'twilight' | 'terminal' | 'vscode' | 'yeti' | 'zenburn'
10+
11+
---@class WindowOptions
12+
---@field public bg string
13+
---@field public drop_shadow_blur string
14+
---@field public drop_shadow_offset_y string
15+
---@field public font_family string
16+
---@field public font_size string
17+
---@field public line_height string
18+
---@field public line_numbers boolean
19+
---@field public drop_shadow boolean
20+
---@field public theme Themes
21+
---@field public titlebar string
22+
---@field public watermark boolean
23+
---@field public width string
24+
---@field public window_theme 'none' | 'sharp' | 'bw' | 'boxy'
25+
---@field public padding_vertical string
26+
---@field public padding_horizontal string
27+
28+
---@class ConfigSchema
29+
---@field public base_url string
30+
---@field public options WindowOptions
31+
32+
---@alias SetupFunc fun(params: ConfigSchema)
33+
534
-- map some known filetypes to carbon.now.sh supported languages
635
--- list of supported languages: https://github.com/carbon-app/carbon/blob/2cbdcd0cc23d2d2f23736dd3cfbe94134b141191/lib/constants.js#L624-L1048
36+
--- TODO: check possible removal of this in favor of vim.filetype
737
local language_map = {
838
typescriptreact = "typescript",
939
javascriptreact = "javascript",
1040
}
1141

1242
-- default config
13-
---@type cn.ConfigSchema
1443
Carbon.config = {
1544
base_url = "https://carbon.now.sh/",
16-
open_cmd = "xdg-open",
1745
options = {
1846
bg = "gray",
1947
drop_shadow_blur = "68px",
@@ -23,11 +51,11 @@ Carbon.config = {
2351
font_size = "18px",
2452
line_height = "133%",
2553
line_numbers = true,
26-
theme = types.Themes.monokai,
54+
theme = "monokai",
2755
titlebar = "Made with carbon-now.nvim",
2856
watermark = false,
2957
width = "680",
30-
window_theme = types.WindowThemes.sharp,
58+
window_theme = "sharp",
3159
padding_horizontal = "0px",
3260
padding_vertical = "0px",
3361
},
@@ -48,9 +76,9 @@ local function query_param_encode(str)
4876
end
4977

5078
---helper function to encode and concatenate a [k,v] table
51-
---as query parameters. iEx: {a = b, c = d} --> a=b&c=d
79+
---as query parameters. Ex: {a = b, c = d} --> a=b&c=d
5280
---@param values table
53-
---@return string # Concatanation of the enconded query parameters
81+
---@return string # Concatenation of the encoded query parameters
5482
---@nodiscard
5583
local function encode_params(values)
5684
---@type table<string, any>
@@ -96,35 +124,8 @@ local function get_carbon_now_snapshot_uri(code)
96124
return encode_params(params)
97125
end
98126

99-
---@nodiscard
100-
---@return string
101-
--- Returns the launch command. If no launch command is
102-
--- available an exception will be raised.
103-
local function get_open_command()
104-
-- default launcher
105-
if vim.fn.executable(Carbon.config.open_cmd) then
106-
return Carbon.config.open_cmd
107-
end
108-
109-
-- alternative launcher
110-
if vim.fn.executable("open") then
111-
return "open"
112-
end
113-
114-
-- windows fallback
115-
if vim.fn.has("win32") then
116-
return "start"
117-
end
118-
119-
vim.api.nvim_err_writeln("[carbon-now.nvim] Couldn't find a launch command")
120-
return "echo"
121-
end
122-
123127
---@param opts {args: string, line1: integer, line2: integer}
124128
local function create_snapshot(opts)
125-
-- get launch command
126-
local open_cmd = get_open_command()
127-
128129
---@type string, string
129130
local url, query_params
130131

@@ -140,19 +141,16 @@ local function create_snapshot(opts)
140141
end
141142

142143
-- launch the Uri
143-
local cmd = open_cmd .. " " .. "'" .. url .. "'"
144-
vim.fn.system(cmd)
144+
vim.ui.open(url)
145145
end
146146

147147
local function create_commands()
148-
---@param opts table<string, any>
149148
vim.api.nvim_create_user_command("CarbonNow", function(opts)
150149
create_snapshot(opts)
151150
end, { range = "%", nargs = "?" })
152151
end
153152

154153
--- initialization function for the carbon plugin commands
155-
---@param params cn.ConfigSchema?
156154
Carbon.setup = function(params)
157155
Carbon.config = vim.tbl_deep_extend("force", {}, Carbon.config, params or {})
158156
create_commands()

lua/types/init.lua

-65
This file was deleted.

0 commit comments

Comments
 (0)