Struct broot::verb::InternalExecution
source · Expand description
A verb execution definition based on an internal
Fields§
§internal: Internal
the internal to use
bang: bool
whether to open the resulting state in a new panel instead of the current ones
arg: Option<String>
arguments
(for example "~"
when a verb execution is :!focus ~
)
Implementations§
source§impl InternalExecution
impl InternalExecution
sourcepub fn from_internal(internal: Internal) -> Self
pub fn from_internal(internal: Internal) -> Self
Examples found in repository?
src/app/panel_state.rs (line 767)
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
fn on_command(
&mut self,
w: &mut W,
app_state: &mut AppState,
cc: &CmdContext,
) -> Result<CmdResult, ProgramError> {
self.clear_pending();
let con = &cc.app.con;
let screen = cc.app.screen;
match &cc.cmd {
Command::Click(x, y) => self.on_click(*x, *y, screen, con),
Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
Command::PatternEdit { raw, expr } => {
match InputPattern::new(raw.clone(), expr, con) {
Ok(pattern) => self.on_pattern(pattern, app_state, con),
Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
}
}
Command::VerbTrigger {
index,
input_invocation,
} => self.execute_verb(
w,
&con.verb_store.verbs[*index],
input_invocation.as_ref(),
TriggerType::Other,
app_state,
cc,
),
Command::Internal {
internal,
input_invocation,
} => self.on_internal(
w,
&InternalExecution::from_internal(*internal),
input_invocation.as_ref(),
TriggerType::Other,
app_state,
cc,
),
Command::VerbInvocate(invocation) => {
let sel_info = self.sel_info(app_state);
match con.verb_store.search_sel_info(
&invocation.name,
sel_info,
) {
PrefixSearchResult::Match(_, verb) => {
self.execute_verb(
w,
verb,
Some(invocation),
TriggerType::Input(verb),
app_state,
cc,
)
}
_ => Ok(CmdResult::verb_not_found(&invocation.name)),
}
}
Command::None | Command::VerbEdit(_) => {
// we do nothing here, the real job is done in get_status
Ok(CmdResult::Keep)
}
}
}
sourcepub fn from_internal_bang(internal: Internal, bang: bool) -> Self
pub fn from_internal_bang(internal: Internal, bang: bool) -> Self
sourcepub fn try_from(invocation_str: &str) -> Result<Self, ConfError>
pub fn try_from(invocation_str: &str) -> Result<Self, ConfError>
Examples found in repository?
src/conf/verb_conf.rs (line 98)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
pub fn make_verb(&self, previous_verbs: &[Verb]) -> Result<Verb, ConfError> {
let vc = self;
if vc.leave_broot == Some(false) && vc.from_shell == Some(true) {
return Err(ConfError::InvalidVerbConf {
details: "You can't simultaneously have leave_broot=false and from_shell=true".to_string(),
});
}
let invocation = vc.invocation.clone().filter(|i| !i.is_empty());
let internal = vc.internal.as_ref().filter(|i| !i.is_empty());
let external = vc.external.as_ref().filter(|i| !i.is_empty());
let cmd = vc.cmd.as_ref().filter(|i| !i.is_empty());
let cmd_separator = vc.cmd_separator.as_ref().filter(|i| !i.is_empty());
let execution = vc.execution.as_ref().filter(|i| !i.is_empty());
let make_external_execution = |s| {
let working_dir = match (vc.set_working_dir, &vc.working_dir) {
(Some(false), _) => None,
(_, Some(s)) => Some(s.clone()),
(Some(true), None) => Some("{directory}".to_owned()),
(None, None) => None,
};
ExternalExecution::new(
s,
ExternalExecutionMode::from_conf(vc.from_shell, vc.leave_broot),
)
.with_working_dir(working_dir)
};
let execution = match (execution, internal, external, cmd) {
// old definition with "execution": we guess whether it's an internal or
// an external
(Some(ep), None, None, None) => {
if let Some(internal_pattern) = ep.as_internal_pattern() {
if let Some(previous_verb) = previous_verbs.iter().find(|&v| v.has_name(internal_pattern)) {
previous_verb.execution.clone()
} else {
VerbExecution::Internal(InternalExecution::try_from(internal_pattern)?)
}
} else {
VerbExecution::External(make_external_execution(ep.clone()))
}
}
// "internal": the leading `:` or ` ` is optional
(None, Some(s), None, None) => {
VerbExecution::Internal(if s.starts_with(':') || s.starts_with(' ') {
InternalExecution::try_from(&s[1..])?
} else {
InternalExecution::try_from(s)?
})
}
// "external": it can be about any form
(None, None, Some(ep), None) => {
VerbExecution::External(make_external_execution(ep.clone()))
}
// "cmd": it's a sequence
(None, None, None, Some(s)) => VerbExecution::Sequence(SequenceExecution {
sequence: Sequence::new(s, cmd_separator),
}),
_ => {
return Err(ConfError::InvalidVerbConf {
details: "You must define either internal, external or cmd".to_string(),
});
}
};
let description = vc
.description
.clone()
.map(VerbDescription::from_text)
.unwrap_or_else(|| VerbDescription::from_code(execution.to_string()));
let mut verb = Verb::new(
invocation.as_deref(),
execution,
description,
)?;
// we accept both key and keys. We merge both here
let mut unchecked_keys = vc.keys.clone();
if let Some(key) = &vc.key {
unchecked_keys.push(key.clone());
}
let mut checked_keys = Vec::new();
for key in &unchecked_keys {
let key = crokey::parse(key)?;
if keys::is_reserved(key) {
return Err(ConfError::ReservedKey {
key: keys::KEY_FORMAT.to_string(key)
});
}
checked_keys.push(key);
}
for extension in &self.extensions {
verb.file_extensions.push(extension.clone());
}
if !checked_keys.is_empty() {
verb.add_keys(checked_keys);
}
if let Some(shortcut) = &vc.shortcut {
verb.names.push(shortcut.clone());
}
if vc.auto_exec == Some(false) {
verb.auto_exec = false;
}
if !vc.panels.is_empty() {
verb.panels = vc.panels.clone();
}
verb.selection_condition = match vc.apply_to.as_deref() {
Some("file") => SelectionType::File,
Some("directory") => SelectionType::Directory,
Some("any") => SelectionType::Any,
None => SelectionType::Any,
Some(s) => {
return Err(ConfError::InvalidVerbConf {
details: format!("{:?} isn't a valid value of apply_to", s),
});
}
};
Ok(verb)
}
sourcepub fn needs_selection(&self) -> bool
pub fn needs_selection(&self) -> bool
Examples found in repository?
src/verb/verb.rs (line 102)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
pub fn new(
invocation_str: Option<&str>,
execution: VerbExecution,
description: VerbDescription,
) -> Result<Self, ConfError> {
let invocation_parser = invocation_str.map(InvocationParser::new).transpose()?;
let mut names = Vec::new();
if let Some(ref invocation_parser) = invocation_parser {
names.push(invocation_parser.name().to_string());
}
let (
needs_selection,
needs_another_panel,
) = match &execution {
VerbExecution::Internal(ie) => (
ie.needs_selection(),
false,
),
VerbExecution::External(ee) => (
ee.exec_pattern.has_selection_group(),
ee.exec_pattern.has_other_panel_group(),
),
VerbExecution::Sequence(se) => (
se.sequence.has_selection_group(),
se.sequence.has_other_panel_group(),
)
};
Ok(Self {
names,
keys: Vec::new(),
keys_desc: "".to_string(),
invocation_parser,
execution,
description,
selection_condition: SelectionType::Any,
file_extensions: Vec::new(),
needs_selection,
needs_another_panel,
auto_exec: true,
show_in_doc: true,
panels: Vec::new(),
})
}
Trait Implementations§
source§impl Clone for InternalExecution
impl Clone for InternalExecution
source§fn clone(&self) -> InternalExecution
fn clone(&self) -> InternalExecution
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more