diff options
author | Canop <cano.petrole@gmail.com> | 2022-03-29 13:37:51 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-03-29 13:37:51 +0200 |
commit | 178a8c5942df0442ab80e5f305cf237110503123 (patch) | |
tree | 3b368268cb126733254ded847d29fabac0053e8c /src | |
parent | a697c79919301313a6942808363f5a9483c3b1d7 (diff) |
Don't quit on small terminals
Fix #511
Diffstat (limited to 'src')
-rw-r--r-- | src/app/app.rs | 45 | ||||
-rw-r--r-- | src/app/panel_state.rs | 2 | ||||
-rw-r--r-- | src/display/areas.rs | 34 | ||||
-rw-r--r-- | src/errors.rs | 1 | ||||
-rw-r--r-- | src/filesystems/filesystems_state.rs | 4 | ||||
-rw-r--r-- | src/verb/verb.rs | 2 |
6 files changed, 40 insertions, 48 deletions
diff --git a/src/app/app.rs b/src/app/app.rs index d7d1839..bd5cf68 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -88,7 +88,7 @@ impl App { )? .expect("Failed to create BrowserState"), ), - Areas::create(&mut Vec::new(), 0, screen, false)?, + Areas::create(&mut Vec::new(), 0, screen, false), con, ); let (tx_seqs, rx_seqs) = unbounded::<Sequence>(); @@ -168,8 +168,7 @@ impl App { self.panels.as_mut_slice(), self.screen, self.preview_panel.is_some(), - ) - .expect("removing a panel should be easy"); + ); self.active_panel_idx = self .panels .iter() @@ -560,33 +559,29 @@ impl App { self.active_panel_idx }; let with_preview = purpose.is_preview() || self.preview_panel.is_some(); - match Areas::create( + let areas = Areas::create( self.panels.as_mut_slice(), insertion_idx, self.screen, with_preview, - ) { - Ok(areas) => { - let panel_id = self.created_panels_count.into(); - match state.get_type() { - PanelStateType::Preview => { - self.preview_panel = Some(panel_id); - } - PanelStateType::Stage => { - self.stage_panel = Some(panel_id); - } - _ => { - self.active_panel_idx = insertion_idx; - } - } - let mut panel = Panel::new(panel_id, state, areas, con); - panel.purpose = purpose; - self.created_panels_count += 1; - self.panels.insert(insertion_idx, panel); - Ok(()) + ); + let panel_id = self.created_panels_count.into(); + match state.get_type() { + PanelStateType::Preview => { + self.preview_panel = Some(panel_id); + } + PanelStateType::Stage => { + self.stage_panel = Some(panel_id); + } + _ => { + self.active_panel_idx = insertion_idx; } - Err(e) => Err(e.to_string()) } + let mut panel = Panel::new(panel_id, state, areas, con); + panel.purpose = purpose; + self.created_panels_count += 1; + self.panels.insert(insertion_idx, panel); + Ok(()) } /// do the pending tasks, if any, and refresh the screen accordingly @@ -731,7 +726,7 @@ impl App { self.panels.as_mut_slice(), self.screen, self.preview_panel.is_some(), - )?; + ); for panel in &mut self.panels { panel.mut_state().refresh(self.screen, con); } diff --git a/src/app/panel_state.rs b/src/app/panel_state.rs index 83a0138..f1f2375 100644 --- a/src/app/panel_state.rs +++ b/src/app/panel_state.rs @@ -796,7 +796,7 @@ pub fn get_arg<T: Copy + FromStr>( ) -> T { verb_invocation .and_then(|vi| vi.args.as_ref()) - .or_else(|| internal_exec.arg.as_ref()) + .or(internal_exec.arg.as_ref()) .and_then(|s| s.parse::<T>().ok()) .unwrap_or(default) } diff --git a/src/display/areas.rs b/src/display/areas.rs index b974184..d05131e 100644 --- a/src/display/areas.rs +++ b/src/display/areas.rs @@ -5,7 +5,6 @@ use { }, crate::{ app::Panel, - errors::ProgramError, }, termimad::Area, }; @@ -23,8 +22,9 @@ pub struct Areas { pub nb_pos: usize, // number of displayed panels } -const MINIMAL_PANEL_HEIGHT: u16 = 10; -const MINIMAL_PANEL_WIDTH: u16 = 20; +const MINIMAL_PANEL_HEIGHT: u16 = 4; +const MINIMAL_PANEL_WIDTH: u16 = 4; +const MINIMAL_SCREEN_WIDTH: u16 = 8; enum Slot<'a> { Panel(usize), @@ -39,7 +39,7 @@ impl Areas { mut insertion_idx: usize, screen: Screen, with_preview: bool, // slightly larger last panel - ) -> Result<Self, ProgramError> { + ) -> Self { if insertion_idx > present_panels.len() { insertion_idx = present_panels.len(); } @@ -59,15 +59,15 @@ impl Areas { for i in insertion_idx..present_panels.len() { slots.push(Slot::Panel(i)); } - Self::compute_areas(present_panels, &mut slots, screen, with_preview)?; - Ok(areas) + Self::compute_areas(present_panels, &mut slots, screen, with_preview); + areas } pub fn resize_all( panels: &mut [Panel], screen: Screen, with_preview: bool, // slightly larger last panel - ) -> Result<(), ProgramError> { + ) { let mut slots = Vec::new(); for i in 0..panels.len() { slots.push(Slot::Panel(i)); @@ -80,34 +80,33 @@ impl Areas { slots: &mut Vec<Slot>, screen: Screen, with_preview: bool, // slightly larger last panel - ) -> Result<(), ProgramError> { - if screen.height < MINIMAL_PANEL_HEIGHT { - return Err(ProgramError::TerminalTooSmallError); - } + ) { + let screen_height = screen.height.max(MINIMAL_PANEL_HEIGHT); + let screen_width = screen.width.max(MINIMAL_SCREEN_WIDTH); let n = slots.len() as u16; let mut panel_width = if with_preview { - 3 * screen.width / (3 * n + 1) + 3 * screen_width / (3 * n + 1) } else { - screen.width / n + screen_width / n }; if panel_width < MINIMAL_PANEL_WIDTH { - return Err(ProgramError::TerminalTooSmallError); + panel_width = panel_width.max(MINIMAL_PANEL_WIDTH); } let mut x = 0; let nb_pos = slots.len(); #[allow(clippy::needless_range_loop)] for slot_idx in 0..nb_pos { if slot_idx == nb_pos - 1 { - panel_width = screen.width - x; + panel_width = screen_width - x; } let areas: &mut Areas = match &mut slots[slot_idx] { Slot::Panel(panel_idx) => &mut panels[*panel_idx].areas, Slot::New(areas) => areas, }; - let y = screen.height - 2; + let y = screen_height - 2; areas.state = Area::new(x, 0, panel_width, y); areas.status = if WIDE_STATUS { - Area::new(0, y, screen.width, 1) + Area::new(0, y, screen_width, 1) } else { Area::new(x, y, panel_width, 1) }; @@ -128,7 +127,6 @@ impl Areas { areas.nb_pos = nb_pos; x += panel_width; } - Ok(()) } pub fn is_first(&self) -> bool { diff --git a/src/errors.rs b/src/errors.rs index 78e2124..33a65e2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -20,7 +20,6 @@ custom_error! {pub ProgramError LaunchError {program: String, source: io::Error} = "Unable to launch {program}: {source}", UnknowShell {shell: String} = "Unknown shell: {shell}", InternalError {details: String} = "Internal error: {details}", // should not happen - TerminalTooSmallError = "Terminal too small", // unable to open panel or app InvalidGlobError {pattern: String} = "Invalid glob: {pattern}", Unrecognized {token: String} = "Unrecognized: {token}", NetError {source: NetError} = "{}", diff --git a/src/filesystems/filesystems_state.rs b/src/filesystems/filesystems_state.rs index 903e909..67e8715 100644 --- a/src/filesystems/filesystems_state.rs +++ b/src/filesystems/filesystems_state.rs @@ -360,8 +360,8 @@ impl PanelState for FilesystemState { let mut cw = CropWriter::new(w, width - 1); // -1 for scrollbar let txt_style = if selected { &styles.selected_line } else { &styles.default }; if let Some(mount) = mounts.get(idx) { - let match_style = if selected { &selected_match_style } else { &match_style }; - let border_style = if selected { &selected_border_style } else { &border_style }; + let match_style = if selected { &selected_match_style } else { match_style }; + let border_style = if selected { &selected_border_style } else { border_style }; if con.show_selection_mark { cw.queue_char(txt_style, if selected { '▶' } else { ' ' })?; } diff --git a/src/verb/verb.rs b/src/verb/verb.rs index 701f3d9..d94c293 100644 --- a/src/verb/verb.rs +++ b/src/verb/verb.rs @@ -222,7 +222,7 @@ impl Verb { if let VerbExecution::Internal(internal_exec) = &self.execution { if internal_exec.internal == Internal::focus { if let Some(sel) = sel_info.one_sel() { - let arg = invocation.args.as_ref().or_else(|| internal_exec.arg.as_ref()); + let arg = invocation.args.as_ref().or(internal_exec.arg.as_ref()); let pb; let arg_path = if let Some(arg) = arg { pb = path::path_from(sel.path, PathAnchor::Unspecified, arg); |