pull/351/head
Gilad Woloch 3 years ago committed by Arijit Basu
parent 3f0e479f56
commit c399236fd3

@ -1388,7 +1388,9 @@ impl App {
}
pub fn focused_node(&self) -> Option<&Node> {
self.directory_buffer.as_ref().and_then(|d| d.focused_node())
self.directory_buffer
.as_ref()
.and_then(|d| d.focused_node())
}
pub fn focused_node_str(&self) -> String {
@ -1551,9 +1553,7 @@ impl App {
} else if key.is_number() {
kb.on_number.clone().map(|a| a.messages.clone())
} else if key.is_special_character() {
kb.on_special_character
.clone()
.map(|a| a.messages.clone())
kb.on_special_character.clone().map(|a| a.messages.clone())
} else {
None
}
@ -1670,7 +1670,11 @@ impl App {
}
fn focus_previous_by_relative_index_from_input(self) -> Result<Self> {
if let Some(index) = self.input_buffer.as_ref().and_then(|i| i.parse::<usize>().ok()) {
if let Some(index) = self
.input_buffer
.as_ref()
.and_then(|i| i.parse::<usize>().ok())
{
self.focus_previous_by_relative_index(index)
} else {
Ok(self)
@ -1704,7 +1708,11 @@ impl App {
}
fn focus_next_by_relative_index_from_input(self) -> Result<Self> {
if let Some(index) = self.input_buffer.as_ref().and_then(|i| i.parse::<usize>().ok()) {
if let Some(index) = self
.input_buffer
.as_ref()
.and_then(|i| i.parse::<usize>().ok())
{
self.focus_next_by_relative_index(index)
} else {
Ok(self)
@ -1861,7 +1869,11 @@ impl App {
}
fn focus_by_index_from_input(self) -> Result<Self> {
if let Some(index) = self.input_buffer.as_ref().and_then(|i| i.parse::<usize>().ok()) {
if let Some(index) = self
.input_buffer
.as_ref()
.and_then(|i| i.parse::<usize>().ok())
{
self.focus_by_index(index)
} else {
Ok(self)
@ -1961,9 +1973,7 @@ impl App {
fn switch_mode_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
if let Some(mode) = self.config.modes.clone().get(mode) {
self = self.push_mode();
self.mode = mode
.to_owned()
.sanitized(self.config.general.read_only);
self.mode = mode.to_owned().sanitized(self.config.general.read_only);
Ok(self)
} else {
self.log_error(format!("Mode not found: {}", mode))
@ -1981,9 +1991,7 @@ impl App {
fn switch_mode_builtin_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
if let Some(mode) = self.config.modes.clone().builtin.get(mode) {
self = self.push_mode();
self.mode = mode
.to_owned()
.sanitized(self.config.general.read_only);
self.mode = mode.to_owned().sanitized(self.config.general.read_only);
Ok(self)
} else {
self.log_error(format!("Builtin mode not found: {}", mode))
@ -2001,9 +2009,7 @@ impl App {
fn switch_mode_custom_keeping_input_buffer(mut self, mode: &str) -> Result<Self> {
if let Some(mode) = self.config.modes.clone().custom.get(mode) {
self = self.push_mode();
self.mode = mode
.to_owned()
.sanitized(self.config.general.read_only);
self.mode = mode.to_owned().sanitized(self.config.general.read_only);
Ok(self)
} else {
self.log_error(format!("Custom mode not found: {}", mode))
@ -2417,7 +2423,8 @@ impl App {
}
pub fn directory_nodes_str(&self) -> String {
self.directory_buffer.as_ref()
self.directory_buffer
.as_ref()
.map(|d| {
d.nodes
.iter()

@ -36,7 +36,8 @@ fn call_lua(
_silent: bool,
) -> Result<Option<Vec<app::ExternalMsg>>> {
let _focus_index = app
.directory_buffer.as_ref()
.directory_buffer
.as_ref()
.map(|d| d.focus)
.unwrap_or_default()
.to_string();
@ -48,7 +49,8 @@ fn call_lua(
fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatus> {
let focus_index = app
.directory_buffer.as_ref()
.directory_buffer
.as_ref()
.map(|d| d.focus)
.unwrap_or_default()
.to_string();
@ -62,7 +64,10 @@ fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatu
Command::new(cmd.command.clone())
.env("XPLR_APP_VERSION", app.version.clone())
.env("XPLR_PID", &app.pid.to_string())
.env("XPLR_INPUT_BUFFER", app.input_buffer.clone().unwrap_or_default())
.env(
"XPLR_INPUT_BUFFER",
app.input_buffer.clone().unwrap_or_default(),
)
.env("XPLR_FOCUS_PATH", app.focused_node_str())
.env("XPLR_FOCUS_INDEX", focus_index)
.env("XPLR_SESSION_PATH", &app.session_path)
@ -71,8 +76,14 @@ fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatu
.env("XPLR_PIPE_HISTORY_OUT", &app.pipe.history_out)
.env("XPLR_MODE", app.mode_str())
.env("XPLR_PIPE_RESULT_OUT", &app.pipe.result_out)
.env( "XPLR_PIPE_GLOBAL_HELP_MENU_OUT", &app.pipe.global_help_menu_out)
.env("XPLR_PIPE_DIRECTORY_NODES_OUT", &app.pipe.directory_nodes_out)
.env(
"XPLR_PIPE_GLOBAL_HELP_MENU_OUT",
&app.pipe.global_help_menu_out,
)
.env(
"XPLR_PIPE_DIRECTORY_NODES_OUT",
&app.pipe.directory_nodes_out,
)
.env("XPLR_PIPE_LOGS_OUT", &app.pipe.logs_out)
.stdin(stdin)
.stdout(stdout)
@ -174,7 +185,8 @@ impl Runner {
// let mut stdout = stdout.lock();
execute!(stdout, term::EnterAlternateScreen)?;
let mut fifo: Option<fs::File> = if let Some(path) = app.config.general.start_fifo.as_ref() {
let mut fifo: Option<fs::File> = if let Some(path) = app.config.general.start_fifo.as_ref()
{
// TODO remove duplicate segment
match start_fifo(&path, &app.focused_node_str()) {
Ok(file) => Some(file),

@ -448,16 +448,14 @@ fn draw_table<B: Backend>(
lua: &Lua,
) {
let panel_config = &app.config.general.panel_ui;
let config = panel_config
.default
.to_owned()
.extend(&panel_config.table);
let config = panel_config.default.to_owned().extend(&panel_config.table);
let app_config = app.config.to_owned();
let header_height = app_config.general.table.header.height.unwrap_or(1);
let height: usize = (layout_size.height.max(header_height + 2) - (header_height + 2)).into();
let rows = app
.directory_buffer.as_ref()
.directory_buffer
.as_ref()
.map(|dir| {
dir.nodes
.iter()
@ -516,8 +514,7 @@ fn draw_table<B: Backend>(
node_type = node_type.extend(conf);
}
if let Some(conf) = app_config.node_types.special.get(&node.relative_path)
{
if let Some(conf) = app_config.node_types.special.get(&node.relative_path) {
node_type = node_type.extend(conf);
}
@ -617,19 +614,14 @@ fn draw_table<B: Backend>(
.widths(&table_constraints)
.style(app_config.general.table.style.to_owned().into())
.highlight_style(app_config.general.focus_ui.style.to_owned().into())
.column_spacing(
app_config
.general
.table
.col_spacing
.unwrap_or_default(),
)
.column_spacing(app_config.general.table.col_spacing.unwrap_or_default())
.block(block(
config,
format!(
" {} ({}) ",
app.pwd,
app.directory_buffer.as_ref()
app.directory_buffer
.as_ref()
.map(|d| d.total)
.unwrap_or_default()
),
@ -649,15 +641,7 @@ fn draw_table<B: Backend>(
.collect::<Vec<Cell>>(),
)
.height(header_height)
.style(
app_config
.general
.table
.header
.style
.to_owned()
.into(),
),
.style(app_config.general.table.header.style.to_owned().into()),
);
f.render_widget(table, layout_size);
@ -722,11 +706,7 @@ fn draw_help_menu<B: Backend>(
let help_menu = Table::new(help_menu_rows)
.block(block(
config,
format!(
" Help [{}{}] ",
&app.mode.name,
read_only_indicator(app)
),
format!(" Help [{}{}] ", &app.mode.name, read_only_indicator(app)),
))
.widths(&[
TuiConstraint::Percentage(20),
@ -771,11 +751,7 @@ fn draw_input_buffer<B: Backend>(
]))
.block(block(
config,
format!(
" Input [{}{}] ",
app.mode.name,
read_only_indicator(app)
),
format!(" Input [{}{}] ", app.mode.name, read_only_indicator(app)),
));
f.render_widget(input_buf, layout_size);
}
@ -892,11 +868,7 @@ fn draw_logs<B: Backend>(
app::LogLevel::Warning => ListItem::new(format!(
"{} | {} | {}",
&time,
&logs_config
.warning
.format
.to_owned()
.unwrap_or_default(),
&logs_config.warning.format.to_owned().unwrap_or_default(),
l.message
))
.style(logs_config.warning.style.to_owned().into()),
@ -904,11 +876,7 @@ fn draw_logs<B: Backend>(
app::LogLevel::Success => ListItem::new(format!(
"{} | {} | {}",
&time,
&logs_config
.success
.format
.to_owned()
.unwrap_or_default(),
&logs_config.success.format.to_owned().unwrap_or_default(),
l.message
))
.style(logs_config.success.style.to_owned().into()),

Loading…
Cancel
Save