Struct broot::app::AppContext
source · pub struct AppContext {Show 20 fields
pub initial_root: PathBuf,
pub initial_tree_options: TreeOptions,
pub config_paths: Vec<PathBuf>,
pub launch_args: Args,
pub verb_store: VerbStore,
pub special_paths: Vec<SpecialPath>,
pub search_modes: SearchModeMap,
pub show_selection_mark: bool,
pub ext_colors: ExtColorMap,
pub syntax_theme: Option<SyntaxTheme>,
pub standard_status: StandardStatus,
pub true_colors: bool,
pub icons: Option<Box<dyn IconPlugin + Send + Sync>>,
pub modal: bool,
pub capture_mouse: bool,
pub max_panels_count: usize,
pub quit_on_last_cancel: bool,
pub file_sum_threads_count: usize,
pub max_staged_count: usize,
pub content_search_max_file_size: usize,
}
Expand description
The container that can be passed around to provide the configuration things for the whole life of the App
Fields§
§initial_root: PathBuf
The initial tree root
initial_tree_options: TreeOptions
Initial tree options
config_paths: Vec<PathBuf>
where’s the config file we’re using This vec can’t be empty
launch_args: Args
all the arguments specified at launch
verb_store: VerbStore
the verbs in use (builtins and configured ones)
special_paths: Vec<SpecialPath>
the paths for which there’s a special behavior to follow (comes from conf)
search_modes: SearchModeMap
the map between search prefixes and the search mode to apply
show_selection_mark: bool
whether to show a triangle left to selected lines
ext_colors: ExtColorMap
mapping from file extension to colors (comes from conf)
syntax_theme: Option<SyntaxTheme>
the syntect theme to use for text files previewing
standard_status: StandardStatus
precomputed status to display in standard cases (ie when no verb is involved)
true_colors: bool
whether we can use 24 bits colors for previewed images
icons: Option<Box<dyn IconPlugin + Send + Sync>>
map extensions to icons, icon set chosen based on config Send, Sync safely because once created, everything is immutable
modal: bool
modal (aka “vim) mode enabled
capture_mouse: bool
Whether to support mouse interactions
max_panels_count: usize
max number of panels (including preview) that can be open. Guaranteed to be at least 2.
quit_on_last_cancel: bool
whether to quit broot when the user hits “escape” and there’s nothing to cancel
file_sum_threads_count: usize
number of threads used by file_sum (count, size, date) computation
max_staged_count: usize
number of files which may be staged in one staging operation
content_search_max_file_size: usize
max file size when searching file content
Implementations§
source§impl AppContext
impl AppContext
sourcepub fn from(
launch_args: Args,
verb_store: VerbStore,
config: &Conf
) -> Result<Self, ProgramError>
pub fn from(
launch_args: Args,
verb_store: VerbStore,
config: &Conf
) -> Result<Self, ProgramError>
Examples found in repository?
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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
pub fn run() -> Result<Option<Launchable>, ProgramError> {
// parse the launch arguments we got from cli
let args = Args::parse();
let mut must_quit = false;
if let Some(dir) = &args.write_default_conf {
write_default_conf_in(dir)?;
must_quit = true;
}
// read the install related arguments
let install_args = InstallLaunchArgs::from(&args)?;
// execute installation things required by launch args
if let Some(state) = install_args.set_install_state {
write_state(state)?;
must_quit = true;
}
if let Some(shell) = &install_args.print_shell_function {
ShellInstall::print(shell)?;
must_quit = true;
}
if must_quit {
return Ok(None);
}
// read the list of specific config files
let specific_conf: Option<Vec<PathBuf>> = args.conf
.as_ref()
.map(|s| s.split(';').map(PathBuf::from).collect());
// if we don't run on a specific config file, we check the
// configuration
if specific_conf.is_none() && install_args.install != Some(false) {
let mut shell_install = ShellInstall::new(install_args.install == Some(true));
shell_install.check()?;
if shell_install.should_quit {
return Ok(None);
}
}
// read the configuration file(s): either the standard one
// or the ones required by the launch args
let mut config = match &specific_conf {
Some(conf_paths) => {
let mut conf = Conf::default();
for path in conf_paths {
conf.read_file(path.to_path_buf())?;
}
conf
}
_ => time!(Conf::from_default_location())?,
};
debug!("config: {:#?}", &config);
// verb store is completed from the config file(s)
let verb_store = VerbStore::new(&mut config)?;
let mut context = AppContext::from(args, verb_store, &config)?;
#[cfg(unix)]
if let Some(server_name) = &context.launch_args.send {
use crate::{
command::Sequence,
net::{Client, Message},
};
let client = Client::new(server_name);
if let Some(seq) = &context.launch_args.cmd {
let message = Message::Sequence(Sequence::new_local(seq.to_string()));
client.send(&message)?;
} else if !context.launch_args.get_root {
let message = Message::Command(
format!(":focus {}", context.initial_root.to_string_lossy())
);
client.send(&message)?;
};
if context.launch_args.get_root {
client.send(&Message::GetRoot)?;
}
return Ok(None);
}
let mut w = display::writer();
let app = App::new(&context)?;
w.queue(EnterAlternateScreen)?;
w.queue(cursor::Hide)?;
if context.capture_mouse {
w.queue(EnableMouseCapture)?;
}
let r = app.run(&mut w, &mut context, &config);
if context.capture_mouse {
w.queue(DisableMouseCapture)?;
}
w.queue(cursor::Show)?;
w.queue(LeaveAlternateScreen)?;
w.flush()?;
r
}