Skip to content

Commit fdddabb

Browse files
authored
Merge pull request #187 from curlpipe/0.7.5
0.7.5
2 parents 8a2b313 + 932ad14 commit fdddabb

File tree

16 files changed

+766
-149
lines changed

16 files changed

+766
-149
lines changed

Cargo.lock

Lines changed: 70 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66

77
[package]
88
name = "ox"
9-
version = "0.7.4"
9+
version = "0.7.5"
1010
edition = "2021"
1111
authors = ["Curlpipe <[email protected]>"]
1212
description = "A simple but flexible text editor."
@@ -41,3 +41,7 @@ mlua = { version = "0.10", features = ["lua54", "vendored"] }
4141
error_set = "0.7"
4242
shellexpand = "3.1.0"
4343
synoptic = "2.2.9"
44+
ptyprocess = "0.4.1"
45+
regex = "1.11.1"
46+
mio = { version = "1.0.3", features = ["os-ext"] }
47+
nix = { version = "0.29.0", features = ["fs"] }

config/.oxrc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,29 @@ commands = {
329329
local file = arguments[2]
330330
local result = false
331331
if arguments[1] == "left" then
332-
result = editor:open_split_left(file)
332+
if arguments[2] == "terminal" or arguments[2] == "term" then
333+
result = editor:open_terminal_left(table.concat(arguments, " ", 3))
334+
else
335+
result = editor:open_split_left(file)
336+
end
333337
elseif arguments[1] == "right" then
334-
result = editor:open_split_right(file)
338+
if arguments[2] == "terminal" or arguments[2] == "term" then
339+
result = editor:open_terminal_right(table.concat(arguments, " ", 3))
340+
else
341+
result = editor:open_split_right(file)
342+
end
335343
elseif arguments[1] == "up" then
336-
result = editor:open_split_up(file)
344+
if arguments[2] == "terminal" or arguments[2] == "term" then
345+
result = editor:open_terminal_up(table.concat(arguments, " ", 3))
346+
else
347+
result = editor:open_split_up(file)
348+
end
337349
elseif arguments[1] == "down" then
338-
result = editor:open_split_down(file)
350+
if arguments[2] == "terminal" or arguments[2] == "term" then
351+
result = editor:open_terminal_down(table.concat(arguments, " ", 3))
352+
else
353+
result = editor:open_split_down(file)
354+
end
339355
elseif arguments[1] == "grow" then
340356
result = true
341357
local amount = tonumber(arguments[3]) or 0.15
@@ -443,6 +459,9 @@ line_numbers.padding_right = 1
443459
terminal.mouse_enabled = true
444460
terminal.scroll_amount = 4
445461

462+
-- Configure Terminal Behaviour --
463+
terminal.shell = "bash"
464+
446465
-- Configure File Tree --
447466
file_tree.width = 30
448467
file_tree.move_focus_to_file = true

src/config/editor.rs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Defines the Editor API for plug-ins to use
22
use crate::cli::VERSION;
33
use crate::editor::{Editor, FileContainer, FileLayout};
4+
use crate::pty::Pty;
45
use crate::ui::Feedback;
56
use crate::{config, fatal_error, PLUGIN_BOOTSTRAP, PLUGIN_MANAGER, PLUGIN_NETWORKING, PLUGIN_RUN};
67
use kaolinite::utils::{get_absolute_path, get_cwd, get_file_ext, get_file_name};
@@ -594,6 +595,7 @@ impl LuaUserData for Editor {
594595
editor.ptr = editor
595596
.files
596597
.open_up(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
598+
editor.cache_old_ptr(&editor.ptr.clone());
597599
editor.update_cwd();
598600
Ok(true)
599601
} else {
@@ -605,6 +607,7 @@ impl LuaUserData for Editor {
605607
editor.ptr = editor
606608
.files
607609
.open_down(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
610+
editor.cache_old_ptr(&editor.ptr.clone());
608611
editor.update_cwd();
609612
Ok(true)
610613
} else {
@@ -616,6 +619,7 @@ impl LuaUserData for Editor {
616619
editor.ptr = editor
617620
.files
618621
.open_left(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
622+
editor.cache_old_ptr(&editor.ptr.clone());
619623
editor.update_cwd();
620624
Ok(true)
621625
} else {
@@ -627,6 +631,7 @@ impl LuaUserData for Editor {
627631
editor.ptr = editor
628632
.files
629633
.open_right(editor.ptr.clone(), FileLayout::Atom(vec![fc], 0));
634+
editor.cache_old_ptr(&editor.ptr.clone());
630635
editor.update_cwd();
631636
Ok(true)
632637
} else {
@@ -657,11 +662,13 @@ impl LuaUserData for Editor {
657662
);
658663
methods.add_method_mut("focus_split_up", |_, editor, ()| {
659664
editor.ptr = FileLayout::move_up(editor.ptr.clone(), &editor.render_cache.span);
665+
editor.cache_old_ptr(&editor.ptr.clone());
660666
editor.update_cwd();
661667
Ok(())
662668
});
663669
methods.add_method_mut("focus_split_down", |_, editor, ()| {
664670
editor.ptr = FileLayout::move_down(editor.ptr.clone(), &editor.render_cache.span);
671+
editor.cache_old_ptr(&editor.ptr.clone());
665672
editor.update_cwd();
666673
Ok(())
667674
});
@@ -672,16 +679,21 @@ impl LuaUserData for Editor {
672679
Some(FileLayout::FileTree)
673680
);
674681
if in_file_tree {
675-
// We just entered into a file tree, cache where we were (minus the file tree itself)
682+
// We are about to enter a file tree, cache where we were (minus the file tree itself)
676683
editor.old_ptr = editor.ptr.clone();
677-
editor.old_ptr.pop();
684+
} else {
685+
editor.old_ptr = new_ptr.clone();
686+
}
687+
if editor.file_tree_is_open() && !editor.old_ptr.is_empty() {
688+
editor.old_ptr.remove(0);
678689
}
679690
editor.ptr = new_ptr;
680691
editor.update_cwd();
681692
Ok(())
682693
});
683694
methods.add_method_mut("focus_split_right", |_, editor, ()| {
684695
editor.ptr = FileLayout::move_right(editor.ptr.clone(), &editor.render_cache.span);
696+
editor.cache_old_ptr(&editor.ptr.clone());
685697
editor.update_cwd();
686698
Ok(())
687699
});
@@ -770,6 +782,71 @@ impl LuaUserData for Editor {
770782
editor.toggle_file_tree();
771783
Ok(())
772784
});
785+
// Terminal
786+
methods.add_method_mut("open_terminal_up", |_, editor, cmd: Option<String>| {
787+
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
788+
if let Some(cmd) = cmd {
789+
term.lock()
790+
.unwrap()
791+
.silent_run_command(&format!("{cmd}\n"))?;
792+
}
793+
editor.ptr = editor
794+
.files
795+
.open_up(editor.ptr.clone(), FileLayout::Terminal(term));
796+
editor.cache_old_ptr(&editor.ptr.clone());
797+
Ok(true)
798+
} else {
799+
Ok(false)
800+
}
801+
});
802+
methods.add_method_mut("open_terminal_down", |_, editor, cmd: Option<String>| {
803+
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
804+
if let Some(cmd) = cmd {
805+
term.lock()
806+
.unwrap()
807+
.silent_run_command(&format!("{cmd}\n"))?;
808+
}
809+
editor.ptr = editor
810+
.files
811+
.open_down(editor.ptr.clone(), FileLayout::Terminal(term));
812+
editor.cache_old_ptr(&editor.ptr.clone());
813+
Ok(true)
814+
} else {
815+
Ok(false)
816+
}
817+
});
818+
methods.add_method_mut("open_terminal_left", |_, editor, cmd: Option<String>| {
819+
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
820+
if let Some(cmd) = cmd {
821+
term.lock()
822+
.unwrap()
823+
.silent_run_command(&format!("{cmd}\n"))?;
824+
}
825+
editor.ptr = editor
826+
.files
827+
.open_left(editor.ptr.clone(), FileLayout::Terminal(term));
828+
editor.cache_old_ptr(&editor.ptr.clone());
829+
Ok(true)
830+
} else {
831+
Ok(false)
832+
}
833+
});
834+
methods.add_method_mut("open_terminal_right", |_, editor, cmd: Option<String>| {
835+
if let Ok(term) = Pty::new(config!(editor.config, terminal).shell) {
836+
if let Some(cmd) = cmd {
837+
term.lock()
838+
.unwrap()
839+
.silent_run_command(&format!("{cmd}\n"))?;
840+
}
841+
editor.ptr = editor
842+
.files
843+
.open_right(editor.ptr.clone(), FileLayout::Terminal(term));
844+
editor.cache_old_ptr(&editor.ptr.clone());
845+
Ok(true)
846+
} else {
847+
Ok(false)
848+
}
849+
});
773850
// Miscellaneous
774851
methods.add_method_mut("open_command_line", |_, editor, ()| {
775852
match editor.prompt("Command") {

0 commit comments

Comments
 (0)