use std::sync::mpsc;
use std::time::Instant;
use crossterm::event::Event;
use crate::layout::{Direction, Rect, SepHit};
use crate::protocol;
use super::writer::OutboundMsg;
#[allow(dead_code)]
pub(crate) enum InputMode {
Normal,
Prefix {
entered_at: Instant,
},
CopyMode(crate::copy_mode::CopyModeState),
QuitConfirm,
CloseConfirm,
CloseTabConfirm,
ResizeMode,
PaneSelect,
HelpOverlay,
RenameTab {
buffer: String,
},
CommandPalette {
buffer: String,
},
}
pub(crate) enum TabAction {
None,
NewTab,
NextTab,
PrevTab,
GoToTab(usize),
CloseTab,
Rename(String),
KillSession,
}
#[derive(Clone)]
pub(crate) struct TextSelection {
pub(crate) pane_id: usize,
pub(crate) start_row: u16,
pub(crate) start_col: u16,
pub(crate) end_row: u16,
pub(crate) 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(crate) path: Vec<bool>,
pub(crate) direction: Direction,
pub(crate) 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)
}
}
}
}
pub(crate) enum ClientMsg {
Event(Event),
Resize(u16, u16),
Detach,
Disconnected,
Kill,
Panicked(String),
}
pub(crate) struct ConnectedClient {
pub(crate) id: u64,
pub(crate) outbound_tx: mpsc::SyncSender<OutboundMsg>,
pub(crate) writer_handle: Option<std::thread::JoinHandle<()>>,
pub(crate) event_rx: mpsc::Receiver<ClientMsg>,
pub(crate) mode: protocol::AttachMode,
#[allow(dead_code)]
pub(crate) caps: u32,
pub(crate) tw: u16,
pub(crate) th: u16,
}
impl Drop for ConnectedClient {
fn drop(&mut self) {
let _ = self.outbound_tx.try_send(OutboundMsg::Shutdown);
if let Some(handle) = self.writer_handle.take() {
let _ = handle.join();
}
}
}