wip: not sure about updating the input_mode and tab switches for now
This commit is contained in:
parent
59d2da54ca
commit
021c8608c8
6 changed files with 41 additions and 12 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::common::utils::logging::debug_log_to_file;
|
|
||||||
use crate::{common::input::handler::InputMode, tab::Pane};
|
use crate::{common::input::handler::InputMode, tab::Pane};
|
||||||
use ansi_term::Colour::{self, Fixed};
|
use ansi_term::Colour::{self, Fixed};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,7 @@ const MIN_TERMINAL_HEIGHT: usize = 2;
|
||||||
const MIN_TERMINAL_WIDTH: usize = 4;
|
const MIN_TERMINAL_WIDTH: usize = 4;
|
||||||
|
|
||||||
type BorderAndPaneIds = (usize, Vec<PaneId>);
|
type BorderAndPaneIds = (usize, Vec<PaneId>);
|
||||||
fn get_state(app_tx: &SenderWithContext<AppInstruction>) -> InputMode {
|
|
||||||
let (state_tx, state_rx) = channel();
|
|
||||||
|
|
||||||
drop(app_tx.send(AppInstruction::GetState(state_tx)));
|
|
||||||
let state = state_rx.recv().unwrap();
|
|
||||||
state.input_mode
|
|
||||||
}
|
|
||||||
fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, PositionAndSize) {
|
fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, PositionAndSize) {
|
||||||
let width_of_each_half = (rect.columns - 1) / 2;
|
let width_of_each_half = (rect.columns - 1) / 2;
|
||||||
let mut first_rect = *rect;
|
let mut first_rect = *rect;
|
||||||
|
|
@ -72,6 +66,7 @@ pub struct Tab {
|
||||||
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
||||||
pub send_app_instructions: SenderWithContext<AppInstruction>,
|
pub send_app_instructions: SenderWithContext<AppInstruction>,
|
||||||
expansion_boundary: Option<PositionAndSize>,
|
expansion_boundary: Option<PositionAndSize>,
|
||||||
|
pub input_mode: InputMode
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
|
|
@ -80,6 +75,7 @@ pub struct TabData {
|
||||||
pub position: usize,
|
pub position: usize,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub active: bool,
|
pub active: bool,
|
||||||
|
pub input_mode: InputMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication
|
// FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication
|
||||||
|
|
@ -199,6 +195,7 @@ impl Tab {
|
||||||
send_app_instructions: SenderWithContext<AppInstruction>,
|
send_app_instructions: SenderWithContext<AppInstruction>,
|
||||||
max_panes: Option<usize>,
|
max_panes: Option<usize>,
|
||||||
pane_id: Option<PaneId>,
|
pane_id: Option<PaneId>,
|
||||||
|
input_mode: InputMode
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let panes = if let Some(PaneId::Terminal(pid)) = pane_id {
|
let panes = if let Some(PaneId::Terminal(pid)) = pane_id {
|
||||||
let new_terminal = TerminalPane::new(pid, *full_screen_ws);
|
let new_terminal = TerminalPane::new(pid, *full_screen_ws);
|
||||||
|
|
@ -228,6 +225,7 @@ impl Tab {
|
||||||
send_pty_instructions,
|
send_pty_instructions,
|
||||||
send_plugin_instructions,
|
send_plugin_instructions,
|
||||||
expansion_boundary: None,
|
expansion_boundary: None,
|
||||||
|
input_mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -638,7 +636,6 @@ impl Tab {
|
||||||
pub fn toggle_fullscreen_is_active(&mut self) {
|
pub fn toggle_fullscreen_is_active(&mut self) {
|
||||||
self.fullscreen_is_active = !self.fullscreen_is_active;
|
self.fullscreen_is_active = !self.fullscreen_is_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self) {
|
pub fn render(&mut self) {
|
||||||
if self.active_terminal.is_none() {
|
if self.active_terminal.is_none() {
|
||||||
// we might not have an active terminal if we closed the last pane
|
// we might not have an active terminal if we closed the last pane
|
||||||
|
|
@ -651,15 +648,23 @@ impl Tab {
|
||||||
self.full_screen_ws.rows as u16,
|
self.full_screen_ws.rows as u16,
|
||||||
);
|
);
|
||||||
let hide_cursor = "\u{1b}[?25l";
|
let hide_cursor = "\u{1b}[?25l";
|
||||||
let input_mode = get_state(&self.send_app_instructions);
|
//let input_mode = self.get_state(&self.send_app_instructions);
|
||||||
stdout
|
stdout
|
||||||
.write_all(&hide_cursor.as_bytes())
|
.write_all(&hide_cursor.as_bytes())
|
||||||
.expect("cannot write to stdout");
|
.expect("cannot write to stdout");
|
||||||
for (kind, terminal) in self.panes.iter_mut() {
|
for (kind, terminal) in self.panes.iter_mut() {
|
||||||
if !self.panes_to_hide.contains(&terminal.pid()) {
|
if !self.panes_to_hide.contains(&terminal.pid()) {
|
||||||
match self.active_terminal.unwrap() == terminal.pid() {
|
match self.active_terminal.unwrap() == terminal.pid() {
|
||||||
true => boundaries.add_rect(terminal.as_ref(), true, input_mode),
|
true => boundaries.add_rect(
|
||||||
false => boundaries.add_rect(terminal.as_ref(), false, input_mode),
|
terminal.as_ref(),
|
||||||
|
true,
|
||||||
|
self.input_mode
|
||||||
|
),
|
||||||
|
false => boundaries.add_rect(
|
||||||
|
terminal.as_ref(),
|
||||||
|
false,
|
||||||
|
self.input_mode
|
||||||
|
),
|
||||||
}
|
}
|
||||||
if let Some(vte_output) = terminal.render() {
|
if let Some(vte_output) = terminal.render() {
|
||||||
let vte_output = if let PaneId::Terminal(_) = kind {
|
let vte_output = if let PaneId::Terminal(_) = kind {
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,7 @@ pub enum ScreenContext {
|
||||||
CloseTab,
|
CloseTab,
|
||||||
GoToTab,
|
GoToTab,
|
||||||
UpdateTabName,
|
UpdateTabName,
|
||||||
|
ChangeInputMode
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ScreenInstruction> for ScreenContext {
|
impl From<&ScreenInstruction> for ScreenContext {
|
||||||
|
|
@ -238,6 +239,7 @@ impl From<&ScreenInstruction> for ScreenContext {
|
||||||
ScreenInstruction::CloseTab => ScreenContext::CloseTab,
|
ScreenInstruction::CloseTab => ScreenContext::CloseTab,
|
||||||
ScreenInstruction::GoToTab(_) => ScreenContext::GoToTab,
|
ScreenInstruction::GoToTab(_) => ScreenContext::GoToTab,
|
||||||
ScreenInstruction::UpdateTabName(_) => ScreenContext::UpdateTabName,
|
ScreenInstruction::UpdateTabName(_) => ScreenContext::UpdateTabName,
|
||||||
|
ScreenInstruction::ChangeInputMode(_) => ScreenContext::ChangeInputMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,9 @@ impl InputHandler {
|
||||||
update_state(&self.send_app_instructions, |_| AppState {
|
update_state(&self.send_app_instructions, |_| AppState {
|
||||||
input_mode: self.mode,
|
input_mode: self.mode,
|
||||||
});
|
});
|
||||||
|
self.send_screen_instructions
|
||||||
|
.send(ScreenInstruction::ChangeInputMode(self.mode))
|
||||||
|
.unwrap();
|
||||||
self.send_screen_instructions
|
self.send_screen_instructions
|
||||||
.send(ScreenInstruction::Render)
|
.send(ScreenInstruction::Render)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR};
|
||||||
use wasm_vm::{
|
use wasm_vm::{
|
||||||
wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction,
|
wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction,
|
||||||
};
|
};
|
||||||
|
use crate::common::utils::logging::debug_log_to_file;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum ApiCommand {
|
pub enum ApiCommand {
|
||||||
|
|
@ -290,6 +291,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
|
||||||
&full_screen_ws,
|
&full_screen_ws,
|
||||||
os_input,
|
os_input,
|
||||||
max_panes,
|
max_panes,
|
||||||
|
InputMode::Normal
|
||||||
);
|
);
|
||||||
loop {
|
loop {
|
||||||
let (event, mut err_ctx) = screen
|
let (event, mut err_ctx) = screen
|
||||||
|
|
@ -424,6 +426,10 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
|
||||||
ScreenInstruction::UpdateTabName(c) => {
|
ScreenInstruction::UpdateTabName(c) => {
|
||||||
screen.update_active_tab_name(c);
|
screen.update_active_tab_name(c);
|
||||||
}
|
}
|
||||||
|
ScreenInstruction::ChangeInputMode(input_mode) => {
|
||||||
|
debug_log_to_file(format!("{} {:?}", "switched mode to: ".to_string(), input_mode));
|
||||||
|
screen.change_input_mode(input_mode);
|
||||||
|
}
|
||||||
ScreenInstruction::Quit => {
|
ScreenInstruction::Quit => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ use std::os::unix::io::RawFd;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
|
||||||
use super::{AppInstruction, SenderWithContext};
|
use wasmer::wasmparser::WasmFuncType;
|
||||||
|
|
||||||
|
use super::{AppInstruction, SenderWithContext, input::handler::InputMode};
|
||||||
use crate::os_input_output::OsApi;
|
use crate::os_input_output::OsApi;
|
||||||
use crate::panes::PositionAndSize;
|
use crate::panes::PositionAndSize;
|
||||||
use crate::pty_bus::{PtyInstruction, VteEvent};
|
use crate::pty_bus::{PtyInstruction, VteEvent};
|
||||||
|
|
@ -48,6 +50,7 @@ pub enum ScreenInstruction {
|
||||||
CloseTab,
|
CloseTab,
|
||||||
GoToTab(u32),
|
GoToTab(u32),
|
||||||
UpdateTabName(Vec<u8>),
|
UpdateTabName(Vec<u8>),
|
||||||
|
ChangeInputMode(InputMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Screen`] holds multiple [`Tab`]s, each one holding multiple [`panes`](crate::client::panes).
|
/// A [`Screen`] holds multiple [`Tab`]s, each one holding multiple [`panes`](crate::client::panes).
|
||||||
|
|
@ -72,6 +75,7 @@ pub struct Screen {
|
||||||
/// The [`OsApi`] this [`Screen`] uses.
|
/// The [`OsApi`] this [`Screen`] uses.
|
||||||
os_api: Box<dyn OsApi>,
|
os_api: Box<dyn OsApi>,
|
||||||
tabname_buf: String,
|
tabname_buf: String,
|
||||||
|
input_mode: InputMode
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen {
|
impl Screen {
|
||||||
|
|
@ -84,6 +88,7 @@ impl Screen {
|
||||||
full_screen_ws: &PositionAndSize,
|
full_screen_ws: &PositionAndSize,
|
||||||
os_api: Box<dyn OsApi>,
|
os_api: Box<dyn OsApi>,
|
||||||
max_panes: Option<usize>,
|
max_panes: Option<usize>,
|
||||||
|
input_mode: InputMode
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Screen {
|
Screen {
|
||||||
receiver: receive_screen_instructions,
|
receiver: receive_screen_instructions,
|
||||||
|
|
@ -96,6 +101,7 @@ impl Screen {
|
||||||
tabs: BTreeMap::new(),
|
tabs: BTreeMap::new(),
|
||||||
os_api,
|
os_api,
|
||||||
tabname_buf: String::new(),
|
tabname_buf: String::new(),
|
||||||
|
input_mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,6 +121,7 @@ impl Screen {
|
||||||
self.send_app_instructions.clone(),
|
self.send_app_instructions.clone(),
|
||||||
self.max_panes,
|
self.max_panes,
|
||||||
Some(PaneId::Terminal(pane_id)),
|
Some(PaneId::Terminal(pane_id)),
|
||||||
|
self.input_mode
|
||||||
);
|
);
|
||||||
self.active_tab_index = Some(tab_index);
|
self.active_tab_index = Some(tab_index);
|
||||||
self.tabs.insert(tab_index, tab);
|
self.tabs.insert(tab_index, tab);
|
||||||
|
|
@ -259,6 +266,7 @@ impl Screen {
|
||||||
self.send_app_instructions.clone(),
|
self.send_app_instructions.clone(),
|
||||||
self.max_panes,
|
self.max_panes,
|
||||||
None,
|
None,
|
||||||
|
self.input_mode
|
||||||
);
|
);
|
||||||
tab.apply_layout(layout, new_pids);
|
tab.apply_layout(layout, new_pids);
|
||||||
self.active_tab_index = Some(tab_index);
|
self.active_tab_index = Some(tab_index);
|
||||||
|
|
@ -274,6 +282,7 @@ impl Screen {
|
||||||
position: tab.position,
|
position: tab.position,
|
||||||
name: tab.name.clone(),
|
name: tab.name.clone(),
|
||||||
active: active_tab_index == tab.index,
|
active: active_tab_index == tab.index,
|
||||||
|
input_mode: self.input_mode
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.send_plugin_instructions
|
self.send_plugin_instructions
|
||||||
|
|
@ -303,4 +312,9 @@ impl Screen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn change_input_mode(&mut self, input_mode: InputMode) {
|
||||||
|
self.input_mode = input_mode;
|
||||||
|
self.get_active_tab_mut().unwrap().input_mode = self.input_mode;
|
||||||
|
self.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue