Skip to content

Commit ada3461

Browse files
committed
adding padding_vertical and horizontal opts. Close #9
1 parent 16e8434 commit ada3461

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ The plugin comes with the following default configs:
6060
watermark = false,
6161
width = "680",
6262
window_theme = "sharp",
63+
padding_horizontal = "0px",
64+
padding_vertical = "0px",
6365
},
6466
}
6567
```
@@ -102,4 +104,4 @@ Example: Opening snippet in google-chrome
102104

103105
```lua
104106
require('carbon-now').setup({open_cmd = "google-chrome"})
105-
```
107+
```

lua/carbon-now.lua

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- module represents a lua module for the plugin
22
local types = require("types")
3-
local carbon = {}
3+
local Carbon = {}
44

55
-- map some known filetypes to carbon.now.sh supported languages
66
--- list of supported languages: https://github.com/carbon-app/carbon/blob/2cbdcd0cc23d2d2f23736dd3cfbe94134b141191/lib/constants.js#L624-L1048
@@ -11,7 +11,7 @@ local language_map = {
1111

1212
-- default config
1313
---@type cn.ConfigSchema
14-
carbon.config = {
14+
Carbon.config = {
1515
base_url = "https://carbon.now.sh/",
1616
open_cmd = "xdg-open",
1717
options = {
@@ -28,6 +28,8 @@ carbon.config = {
2828
watermark = false,
2929
width = "680",
3030
window_theme = types.WindowThemes.sharp,
31+
padding_horizontal = "0px",
32+
padding_vertical = "0px",
3133
},
3234
}
3335

@@ -68,7 +70,7 @@ end
6870
---@nodiscard
6971
---validate config param values and create the query params table
7072
local function get_carbon_now_snapshot_uri(code)
71-
local opts = carbon.config.options
73+
local opts = Carbon.config.options
7274
local ft = vim.bo.filetype
7375

7476
-- carbon.now.sh parameters
@@ -87,6 +89,8 @@ local function get_carbon_now_snapshot_uri(code)
8789
wm = opts.watermark,
8890
tb = opts.titlebar,
8991
code = code,
92+
pv = opts.padding_vertical,
93+
ph = opts.padding_horizontal,
9094
}
9195

9296
return encode_params(params)
@@ -98,8 +102,8 @@ end
98102
--- available an exception will be raised.
99103
local function get_open_command()
100104
-- default launcher
101-
if vim.fn.executable(carbon.config.open_cmd) then
102-
return carbon.config.open_cmd
105+
if vim.fn.executable(Carbon.config.open_cmd) then
106+
return Carbon.config.open_cmd
103107
end
104108

105109
-- alternative launcher
@@ -127,12 +131,12 @@ local function create_snapshot(opts)
127131
-- create Uri
128132
if opts.args ~= "" then
129133
query_params = get_carbon_now_snapshot_uri()
130-
url = carbon.config.base_url .. "/" .. opts.args .. "?" .. query_params
134+
url = Carbon.config.base_url .. "/" .. opts.args .. "?" .. query_params
131135
else
132136
local range = vim.api.nvim_buf_get_lines(0, opts.line1 - 1, opts.line2, false)
133137
local code = table.concat(range, "\n", 1, #range)
134138
query_params = get_carbon_now_snapshot_uri(code)
135-
url = carbon.config.base_url .. "?" .. query_params
139+
url = Carbon.config.base_url .. "?" .. query_params
136140
end
137141

138142
-- launch the Uri
@@ -149,9 +153,9 @@ end
149153

150154
--- initialization function for the carbon plugin commands
151155
---@param params cn.ConfigSchema?
152-
carbon.setup = function(params)
153-
carbon.config = vim.tbl_deep_extend("force", {}, carbon.config, params or {})
156+
Carbon.setup = function(params)
157+
Carbon.config = vim.tbl_deep_extend("force", {}, Carbon.config, params or {})
154158
create_commands()
155159
end
156160

157-
return carbon
161+
return Carbon

lua/types/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ cn.Themes = {
5959
---@field public watermark boolean
6060
---@field public width string
6161
---@field public window_theme cn.WindowThemes
62+
---@field public padding_vertical string
63+
---@field public padding_horizontal string
6264

63-
return cn
65+
return cn

0 commit comments

Comments
 (0)