Skip to content

Commit

Permalink
Merge pull request #187 from curlpipe/0.7.5
Browse files Browse the repository at this point in the history
0.7.5
  • Loading branch information
curlpipe authored Dec 16, 2024
2 parents 8a2b313 + 932ad14 commit fdddabb
Show file tree
Hide file tree
Showing 16 changed files with 766 additions and 149 deletions.
75 changes: 70 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [

[package]
name = "ox"
version = "0.7.4"
version = "0.7.5"
edition = "2021"
authors = ["Curlpipe <11898833+curlpipe@users.noreply.github.com>"]
description = "A simple but flexible text editor."
Expand Down Expand Up @@ -41,3 +41,7 @@ mlua = { version = "0.10", features = ["lua54", "vendored"] }
error_set = "0.7"
shellexpand = "3.1.0"
synoptic = "2.2.9"
ptyprocess = "0.4.1"
regex = "1.11.1"
mio = { version = "1.0.3", features = ["os-ext"] }
nix = { version = "0.29.0", features = ["fs"] }
27 changes: 23 additions & 4 deletions config/.oxrc
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,29 @@ commands = {
local file = arguments[2]
local result = false
if arguments[1] == "left" then
result = editor:open_split_left(file)
if arguments[2] == "terminal" or arguments[2] == "term" then
result = editor:open_terminal_left(table.concat(arguments, " ", 3))
else
result = editor:open_split_left(file)
end
elseif arguments[1] == "right" then
result = editor:open_split_right(file)
if arguments[2] == "terminal" or arguments[2] == "term" then
result = editor:open_terminal_right(table.concat(arguments, " ", 3))
else
result = editor:open_split_right(file)
end
elseif arguments[1] == "up" then
result = editor:open_split_up(file)
if arguments[2] == "terminal" or arguments[2] == "term" then
result = editor:open_terminal_up(table.concat(arguments, " ", 3))
else
result = editor:open_split_up(file)
end
elseif arguments[1] == "down" then
result = editor:open_split_down(file)
if arguments[2] == "terminal" or arguments[2] == "term" then
result = editor:open_terminal_down(table.concat(arguments, " ", 3))
else
result = editor:open_split_down(file)
end
elseif arguments[1] == "grow" then
result = true
local amount = tonumber(arguments[3]) or 0.15
Expand Down Expand Up @@ -443,6 +459,9 @@ line_numbers.padding_right = 1
terminal.mouse_enabled = true
terminal.scroll_amount = 4

-- Configure Terminal Behaviour --
terminal.shell = "bash"

-- Configure File Tree --
file_tree.width = 30
file_tree.move_focus_to_file = true
Expand Down
81 changes: 79 additions & 2 deletions src/config/editor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Defines the Editor API for plug-ins to use
use crate::cli::VERSION;
use crate::editor::{Editor, FileContainer, FileLayout};
use crate::pty::Pty;
use crate::ui::Feedback;
use crate::{config, fatal_error, PLUGIN_BOOTSTRAP, PLUGIN_MANAGER, PLUGIN_NETWORKING, PLUGIN_RUN};
use kaolinite::utils::{get_absolute_path, get_cwd, get_file_ext, get_file_name};
Expand Down Expand Up @@ -594,6 +595,7 @@ impl LuaUserData for Editor {
editor.ptr = editor
.files
.open_up(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(true)
} else {
Expand All @@ -605,6 +607,7 @@ impl LuaUserData for Editor {
editor.ptr = editor
.files
.open_down(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(true)
} else {
Expand All @@ -616,6 +619,7 @@ impl LuaUserData for Editor {
editor.ptr = editor
.files
.open_left(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(true)
} else {
Expand All @@ -627,6 +631,7 @@ impl LuaUserData for Editor {
editor.ptr = editor
.files
.open_right(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(true)
} else {
Expand Down Expand Up @@ -657,11 +662,13 @@ impl LuaUserData for Editor {
);
methods.add_method_mut("focus_split_up", |_, editor, ()| {
editor.ptr = FileLayout::move_up(editor.ptr.clone(), &editor.render_cache.span);
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(())
});
methods.add_method_mut("focus_split_down", |_, editor, ()| {
editor.ptr = FileLayout::move_down(editor.ptr.clone(), &editor.render_cache.span);
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(())
});
Expand All @@ -672,16 +679,21 @@ impl LuaUserData for Editor {
Some(FileLayout::FileTree)
);
if in_file_tree {
// We just entered into a file tree, cache where we were (minus the file tree itself)
// We are about to enter a file tree, cache where we were (minus the file tree itself)
editor.old_ptr = editor.ptr.clone();
editor.old_ptr.pop();
} else {
editor.old_ptr = new_ptr.clone();
}
if editor.file_tree_is_open() && !editor.old_ptr.is_empty() {
editor.old_ptr.remove(0);
}
editor.ptr = new_ptr;
editor.update_cwd();
Ok(())
});
methods.add_method_mut("focus_split_right", |_, editor, ()| {
editor.ptr = FileLayout::move_right(editor.ptr.clone(), &editor.render_cache.span);
editor.cache_old_ptr(&editor.ptr.clone());
editor.update_cwd();
Ok(())
});
Expand Down Expand Up @@ -770,6 +782,71 @@ impl LuaUserData for Editor {
editor.toggle_file_tree();
Ok(())
});
// Terminal
methods.add_method_mut("open_terminal_up", |_, editor, cmd: Option<String>| {
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
if let Some(cmd) = cmd {
term.lock()
.unwrap()
.silent_run_command(&format!("{cmd}\n"))?;
}
editor.ptr = editor
.files
.open_up(editor.ptr.clone(), FileLayout::Terminal(term));
editor.cache_old_ptr(&editor.ptr.clone());
Ok(true)
} else {
Ok(false)
}
});
methods.add_method_mut("open_terminal_down", |_, editor, cmd: Option<String>| {
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
if let Some(cmd) = cmd {
term.lock()
.unwrap()
.silent_run_command(&format!("{cmd}\n"))?;
}
editor.ptr = editor
.files
.open_down(editor.ptr.clone(), FileLayout::Terminal(term));
editor.cache_old_ptr(&editor.ptr.clone());
Ok(true)
} else {
Ok(false)
}
});
methods.add_method_mut("open_terminal_left", |_, editor, cmd: Option<String>| {
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
if let Some(cmd) = cmd {
term.lock()
.unwrap()
.silent_run_command(&format!("{cmd}\n"))?;
}
editor.ptr = editor
.files
.open_left(editor.ptr.clone(), FileLayout::Terminal(term));
editor.cache_old_ptr(&editor.ptr.clone());
Ok(true)
} else {
Ok(false)
}
});
methods.add_method_mut("open_terminal_right", |_, editor, cmd: Option<String>| {
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
if let Some(cmd) = cmd {
term.lock()
.unwrap()
.silent_run_command(&format!("{cmd}\n"))?;
}
editor.ptr = editor
.files
.open_right(editor.ptr.clone(), FileLayout::Terminal(term));
editor.cache_old_ptr(&editor.ptr.clone());
Ok(true)
} else {
Ok(false)
}
});
// Miscellaneous
methods.add_method_mut("open_command_line", |_, editor, ()| {
match editor.prompt("Command") {
Expand Down
Loading

0 comments on commit fdddabb

Please sign in to comment.