Skip to content

Commit

Permalink
add url opening
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Apr 26, 2024
1 parent 6d0a98c commit c44bf21
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ memchr = "2.5.0"
notify = "6.0.0"
num-traits = "0.2.15"
once_cell = "1.17.1"
opener = "0.7.0"
rayon = "1.7.0"
ropey = "1.5.1"
serde = "1.0.152"
Expand All @@ -48,8 +49,8 @@ tracing = "0.1.40"
tracing-log = "0.2.0"
tracing-subscriber = "0.3.18"
trash = "4.0.0"
tree-sitter = "0.20.10"
tree_magic_mini = "3.0.3"
tree-sitter = "0.20.10"
tui = { package = "ratatui", version = "0.26.0" }
unicode-general-category = "0.6.0"
unicode-segmentation = "1.10.0"
Expand Down
3 changes: 2 additions & 1 deletion crates/ferrite-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ lexical-sort = { workspace = true }
memchr = { workspace = true }
notify = { workspace = true }
once_cell = { workspace = true }
opener = { workspace = true }
rayon = { workspace = true }
ropey = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand All @@ -37,8 +38,8 @@ subprocess = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
trash = { workspace = true }
tree-sitter = { workspace = true }
tree_magic_mini = { workspace = true, features = ["with-gpl-data"] }
tree-sitter = { workspace = true }
unicode-segmentation = { workspace = true }
unicode-width = { workspace = true }

Expand Down
8 changes: 8 additions & 0 deletions crates/ferrite-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ impl Engine {
self.palette.reset();
match cmd_parser::parse_cmd(&content) {
Ok(cmd) => match cmd {
Command::Url => {
if let Some(buffer) = self.get_current_buffer() {
let selection = buffer.get_selection();
if let Err(err) = opener::open(selection) {
self.palette.set_error(err);
}
}
}
Command::Pwd => match env::current_dir() {
Ok(path) => self.palette.set_msg(path.to_string_lossy()),
Err(err) => self.palette.set_error(err),
Expand Down
1 change: 1 addition & 0 deletions crates/ferrite-core/src/palette/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum Command {
Logger,
ForceQuit,
Quit,
Url,
Goto(i64),
Indent(Option<String>),
Theme(Option<String>),
Expand Down
2 changes: 2 additions & 0 deletions crates/ferrite-core/src/palette/cmd_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn parse_cmd(input: &str) -> Result<Command, CommandParseError> {
("format-selection", [..]) => Command::FormatSelection,
("revert-buffer", [..]) => Command::RevertBuffer,
("delete", [..]) => Command::Delete,
("url", [..]) => Command::Url,
("split", [direction, ..]) => {
Command::Split(Direction::from_str(direction.take().unwrap().unwrap_string().as_str()).unwrap())
},
Expand Down Expand Up @@ -128,6 +129,7 @@ static COMMANDS: Lazy<Vec<CommandTemplate>> = Lazy::new(|| {
CommandTemplate::new("format", None, true),
CommandTemplate::new("format-selection", None, true),
CommandTemplate::new("delete", None, true),
CommandTemplate::new("url", None, true),
CommandTemplate::new("revert-buffer", None, true).add_alias("rb"),
CommandTemplate::new("pipe", Some(("arg", CommandTemplateArg::Path)), false),
CommandTemplate::new("shell", Some(("arg", CommandTemplateArg::Path)), false).add_alias("sh"),
Expand Down

0 comments on commit c44bf21

Please sign in to comment.