use std::collections::HashSet;
use std::time::Instant;
use crate::layout::{Direction, Layout, Rect, SepHit};
use crate::workspace;
pub(crate) enum InputMode {
Normal,
Prefix { entered_at: Instant },
ScrollMode,
QuitConfirm,
ResizeMode,
PaneSelect,
HelpOverlay,
}
#[derive(Clone)]
pub(crate) struct TextSelection {
pub pane_id: usize,
pub start_row: u16,
pub start_col: u16,
pub end_row: u16,
pub end_col: u16,
}
impl TextSelection {
pub(crate) fn normalized(&self) -> (u16, u16, u16, u16) {
if self.start_row < self.end_row
|| (self.start_row == self.end_row && self.start_col <= self.end_col)
{
(self.start_row, self.start_col, self.end_row, self.end_col)
} else {
(self.end_row, self.end_col, self.start_row, self.start_col)
}
}
}
pub(crate) struct DragState {
pub path: Vec<bool>,
pub direction: Direction,
pub area: Rect,
}
impl DragState {
pub(crate) fn from_hit(hit: SepHit) -> Self {
Self {
path: hit.path,
direction: hit.direction,
area: hit.area,
}
}
pub(crate) fn calc_ratio(&self, mx: u16, my: u16) -> f32 {
match self.direction {
Direction::Horizontal => {
let usable = self.area.w.saturating_sub(1) as f32;
if usable <= 0.0 {
return 0.5;
}
((mx as f32 - self.area.x as f32) / usable).clamp(0.1, 0.9)
}
Direction::Vertical => {
let usable = self.area.h.saturating_sub(1) as f32;
if usable <= 0.0 {
return 0.5;
}
((my as f32 - self.area.y as f32) / usable).clamp(0.1, 0.9)
}
}
}
}
#[derive(Default)]
pub(crate) struct RenderUpdate {
pub dirty_panes: HashSet<usize>,
pub full_redraw: bool,
pub border_dirty: bool,
}
impl RenderUpdate {
pub fn mark_all(&mut self, layout: &Layout) {
self.full_redraw = true;
self.dirty_panes.extend(layout.pane_ids());
}
pub fn merge(&mut self, other: &mut Self) {
self.dirty_panes.extend(other.dirty_panes.drain());
self.full_redraw |= other.full_redraw;
self.border_dirty |= other.border_dirty;
}
pub fn needs_render(&self) -> bool {
self.full_redraw || !self.dirty_panes.is_empty()
}
}
pub(crate) struct SnapshotExtra {
pub all_tabs: Vec<workspace::TabSnapshot>,
pub active_tab_idx: usize,
pub scrollback: usize,
}