-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ben Lubas <56943754+benlubas@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
281 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
-- loads the wezterm.nvim plugin and exposes methods to the python remote plugin | ||
local ok, wezterm = pcall(require, "wezterm") | ||
if not ok then | ||
vim.api.nvim_err_writeln("[Molten] `wezterm.nvim` not found") | ||
return | ||
end | ||
|
||
local wezterm_api = {} | ||
|
||
wezterm_api.get_pane_id = function() | ||
local current_pane_id = wezterm.get_current_pane() | ||
return current_pane_id | ||
end | ||
|
||
--- Validate the split direction | ||
--- type function | ||
--- @param direction string the direction to validate | ||
--- @return string validated direction if valid | ||
local validate_split_dir = function(direction) | ||
local accepted_dirs = { "top", "bottom", "left", "right" } | ||
--if direction not in accepted_dirs, return "bottom" else return direction | ||
if not vim.tbl_contains(accepted_dirs, direction) then | ||
vim.notify( | ||
"[Molten] 'molten_split_dir' must be one of 'top', 'bottom', 'left', or 'right', defaulting to 'right'" | ||
) | ||
return "right" | ||
end | ||
return direction | ||
end | ||
|
||
--- Validate the split size | ||
--- type function | ||
--- @param size number the size to validate | ||
--- @return number validated size if valid | ||
local validate_split_size = function(size) | ||
if size == nil or size < 0 or size > 100 then | ||
vim.notify( | ||
"[Molten] 'molten_split_size' must be a number between 0 and 100, defaulting to a 40% split." | ||
) | ||
return 40 | ||
end | ||
return size | ||
end | ||
|
||
-- Split the current pane and return the new pane id | ||
--- type function | ||
--- @param initial_pane_id number, the pane id to split | ||
--- @param direction string, direction to split the pane | ||
--- @param size number, size of the new pane | ||
--- @return number image_pane_id the new pane id | ||
wezterm_api.wezterm_molten_init = function(initial_pane_id, direction, size) | ||
direction = "--" .. validate_split_dir(direction) | ||
size = validate_split_size(size) | ||
|
||
wezterm.exec_sync({ "cli", "split-pane", direction, "--percent", tostring(size) }) | ||
wezterm.exec_sync({ "cli", "activate-pane", "--pane-id", tostring(initial_pane_id) }) | ||
local _, image_pane_id = wezterm.exec_sync({ "cli", "get-pane-direction", "Prev" }) | ||
return image_pane_id | ||
end | ||
|
||
-- Send an image to the image pane (terminal split) | ||
--- type function | ||
--- @param path string, path to the image | ||
--- @param image_pane_id number, the pane id of the image pane | ||
--- @param initial_pane_id number, the pane id of the initial pane | ||
--- @return nil | ||
wezterm_api.send_image = function(path, image_pane_id, initial_pane_id) | ||
local placeholder = "wezterm imgcat --tmux-passthru detect %s \r" | ||
local image = string.format(placeholder, path) | ||
wezterm.exec_sync({ "cli", "activate-pane", "--pane-id", image_pane_id }) | ||
wezterm.exec_sync({ | ||
"cli", | ||
"send-text", | ||
"--pane-id", | ||
image_pane_id, | ||
"--no-paste", | ||
image, | ||
}) | ||
wezterm.exec_sync({ "cli", "activate-pane", "--pane-id", initial_pane_id }) | ||
end | ||
|
||
-- Close the image pane | ||
--- type function | ||
--- @param image_pane_id number, the pane id of the image pane | ||
--- @return nil | ||
wezterm_api.close_image_pane = function(image_pane_id) | ||
wezterm.exec_sync({ | ||
"cli", | ||
"send-text", | ||
"--pane-id", | ||
image_pane_id, | ||
"--no-paste", | ||
"wezterm cli kill-pane --pane-id " .. image_pane_id .. "\r", | ||
}) | ||
end | ||
|
||
return { wezterm_api = wezterm_api } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ line-length = 100 | |
|
||
[tool.pyright] | ||
extraPaths = ["rplugin/python3"] | ||
|
||
[tool.ruff] | ||
line-length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.