aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-03-27 11:56:40 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:48:14 +0530
commit2059d2c6aa6a6626d394ef572755f6ff88e2138c (patch)
tree1bbc82f3ba2f883b0344dc5c483a8bf6cfef793c /src
parentRename notify_server to connect_to_server (diff)
downloadsl0ppij-2059d2c6aa6a6626d394ef572755f6ff88e2138c.tar.gz
sl0ppij-2059d2c6aa6a6626d394ef572755f6ff88e2138c.tar.xz
sl0ppij-2059d2c6aa6a6626d394ef572755f6ff88e2138c.zip
Fix after rebase
Diffstat (limited to 'src')
-rw-r--r--src/client/tab.rs151
-rw-r--r--src/common/errors.rs2
-rw-r--r--src/common/input/handler.rs13
-rw-r--r--src/common/mod.rs55
-rw-r--r--src/common/screen.rs2
-rw-r--r--src/common/wasm_vm.rs1
6 files changed, 85 insertions, 139 deletions
diff --git a/src/client/tab.rs b/src/client/tab.rs
index 60f51004..d5ad77a2 100644
--- a/src/client/tab.rs
+++ b/src/client/tab.rs
@@ -8,9 +8,8 @@ use crate::os_input_output::{ClientOsApi, ServerOsApiInstruction};
use crate::panes::{PaneId, PositionAndSize, TerminalPane};
use crate::pty_bus::{PtyInstruction, VteEvent};
use crate::utils::shared::pad_to_size;
-use crate::wasm_vm::{PluginInputType, PluginInstruction};
+use crate::wasm_vm::PluginInstruction;
use crate::{boundaries::Boundaries, panes::PluginPane};
-use serde::{Deserialize, Serialize};
use std::os::unix::io::RawFd;
use std::time::Instant;
use std::{
@@ -509,54 +508,48 @@ impl Tab {
self.panes.insert(pid, Box::new(new_terminal));
self.active_terminal = Some(pid);
}
- } else {
- // FIXME: This could use a second look
- if let PaneId::Terminal(term_pid) = pid {
- // TODO: check minimum size of active terminal
- let active_pane_id = &self.get_active_pane_id().unwrap();
- let active_pane = self.panes.get_mut(active_pane_id).unwrap();
- if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 {
- self.send_app_instructions
- .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty
- .unwrap();
- return;
- }
- let terminal_ws = PositionAndSize {
- x: active_pane.x(),
- y: active_pane.y(),
- rows: active_pane.rows(),
- columns: active_pane.columns(),
- };
- let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
+ } else if let PaneId::Terminal(term_pid) = pid {
+ // TODO: check minimum size of active terminal
+ let active_pane_id = &self.get_active_pane_id().unwrap();
+ let active_pane = self.panes.get_mut(active_pane_id).unwrap();
+ if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 {
+ self.send_app_instructions
+ .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty
+ .unwrap();
+ return;
+ }
+ let terminal_ws = PositionAndSize {
+ x: active_pane.x(),
+ y: active_pane.y(),
+ rows: active_pane.rows(),
+ columns: active_pane.columns(),
+ };
+ let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
active_pane.change_pos_and_size(&top_winsize);
- let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
+ let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
+ self.send_app_instructions
+ .send(AppInstruction::OsApi(
+ ServerOsApiInstruction::SetTerminalSizeUsingFd(
+ new_terminal.pid,
+ bottom_winsize.columns as u16,
+ bottom_winsize.rows as u16,
+ ),
+ ))
+ .unwrap();
+ self.panes.insert(pid, Box::new(new_terminal));
+
+ if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
self.send_app_instructions
.send(AppInstruction::OsApi(
ServerOsApiInstruction::SetTerminalSizeUsingFd(
- new_terminal.pid,
- bottom_winsize.columns as u16,
- bottom_winsize.rows as u16,
+ *active_terminal_pid,
+ top_winsize.columns as u16,
+ top_winsize.rows as u16,
),
))
.unwrap();
- self.panes.insert(pid, Box::new(new_terminal));
-
- if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
- self.send_app_instructions
- .send(AppInstruction::OsApi(
- ServerOsApiInstruction::SetTerminalSizeUsingFd(
- *active_terminal_pid,
- top_winsize.columns as u16,
- top_winsize.rows as u16,
- ),
- ))
- .unwrap();
- }
-
- self.active_terminal = Some(pid);
- self.render();
}
self.active_terminal = Some(pid);
@@ -583,60 +576,48 @@ impl Tab {
self.panes.insert(pid, Box::new(new_terminal));
self.active_terminal = Some(pid);
}
- } else {
- // FIXME: This could use a second look
- if let PaneId::Terminal(term_pid) = pid {
- // TODO: check minimum size of active terminal
- let active_pane_id = &self.get_active_pane_id().unwrap();
- let active_pane = self.panes.get_mut(active_pane_id).unwrap();
- if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 {
- self.send_app_instructions
- .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty
- .unwrap();
- return;
- }
- let terminal_ws = PositionAndSize {
- x: active_pane.x(),
- y: active_pane.y(),
- rows: active_pane.rows(),
- columns: active_pane.columns(),
- };
- let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
+ } else if let PaneId::Terminal(term_pid) = pid {
+ // TODO: check minimum size of active terminal
+ let active_pane_id = &self.get_active_pane_id().unwrap();
+ let active_pane = self.panes.get_mut(active_pane_id).unwrap();
+ if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 {
+ self.send_app_instructions
+ .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty
+ .unwrap();
+ return;
+ }
+ let terminal_ws = PositionAndSize {
+ x: active_pane.x(),
+ y: active_pane.y(),
+ rows: active_pane.rows(),
+ columns: active_pane.columns(),
+ };
+ let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
+
+ active_pane.change_pos_and_size(&left_winsize);
let new_terminal = TerminalPane::new(term_pid, right_winsize);
- self.os_api.set_terminal_size_using_fd(
- new_terminal.pid,
- right_winsize.columns as u16,
- right_winsize.rows as u16,
- );
+ self.send_app_instructions
+ .send(AppInstruction::OsApi(
+ ServerOsApiInstruction::SetTerminalSizeUsingFd(
+ new_terminal.pid,
+ right_winsize.columns as u16,
+ right_winsize.rows as u16,
+ ),
+ ))
+ .unwrap();
self.panes.insert(pid, Box::new(new_terminal));
- let new_terminal = TerminalPane::new(term_pid, right_winsize);
+ if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
self.send_app_instructions
.send(AppInstruction::OsApi(
ServerOsApiInstruction::SetTerminalSizeUsingFd(
- new_terminal.pid,
- right_winsize.columns as u16,
- right_winsize.rows as u16,
+ *active_terminal_pid,
+ left_winsize.columns as u16,
+ left_winsize.rows as u16,
),
))
.unwrap();
- self.panes.insert(pid, Box::new(new_terminal));
-
- if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
- self.send_app_instructions
- .send(AppInstruction::OsApi(
- ServerOsApiInstruction::SetTerminalSizeUsingFd(
- *active_terminal_pid,
- left_winsize.columns as u16,
- left_winsize.rows as u16,
- ),
- ))
- .unwrap();
- }
-
- self.active_terminal = Some(pid);
- self.render();
}
self.active_terminal = Some(pid);
diff --git a/src/common/errors.rs b/src/common/errors.rs
index 37729fbb..3b3d79d8 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -332,7 +332,6 @@ pub enum PluginContext {
Render,
Unload,
Exit,
- Tabs,
}
impl From<&PluginInstruction> for PluginContext {
@@ -343,7 +342,6 @@ impl From<&PluginInstruction> for PluginContext {
PluginInstruction::Render(..) => PluginContext::Render,
PluginInstruction::Unload(_) => PluginContext::Unload,
PluginInstruction::Exit => PluginContext::Exit,
- PluginInstruction::UpdateTabs(..) => PluginContext::Tabs,
}
}
}
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index 0eda77bf..52d4082b 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -282,19 +282,6 @@ impl InputHandler {
.send(ScreenInstruction::UpdateTabName(c))
.unwrap();
}
- Action::SaveTabName => {
- self.command_is_executing.updating_tabs();
- self.send_plugin_instructions
- .send(PluginInstruction::Input(
- PluginInputType::Event(EventType::Tab),
- vec![b'\n'],
- ))
- .unwrap();
- self.send_screen_instructions
- .send(ScreenInstruction::UpdateTabName(vec![b'\n']))
- .unwrap();
- self.command_is_executing.wait_until_tabs_are_updated();
- }
Action::NoOp => {}
}
diff --git a/src/common/mod.rs b/src/common/mod.rs
index bb59f1d2..72067219 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -9,34 +9,34 @@ pub mod setup;
pub mod utils;
pub mod wasm_vm;
-use std::io::Write;
-use std::path::Path;
+use std::cell::RefCell;
use std::sync::mpsc;
use std::thread;
use std::{collections::HashMap, fs};
-
-use crate::panes::PaneId;
-use directories_next::ProjectDirs;
-use input::handler::InputMode;
-use serde::{Deserialize, Serialize};
-use termion::input::TermRead;
-use wasm_vm::PluginEnv;
-use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
-use wasmer_wasi::{Pipe, WasiState};
+use std::{
+ collections::HashSet,
+ io::Write,
+ str::FromStr,
+ sync::{Arc, Mutex},
+};
use crate::cli::CliArgs;
use crate::layout::Layout;
+use crate::panes::PaneId;
use crate::server::{start_server, ServerInstruction};
use command_is_executing::CommandIsExecuting;
+use directories_next::ProjectDirs;
use errors::{AppContext, ContextType, ErrorContext, PluginContext, ScreenContext};
use input::handler::input_loop;
use os_input_output::{ClientOsApi, ServerOsApi, ServerOsApiInstruction};
use pty_bus::PtyInstruction;
use screen::{Screen, ScreenInstruction};
-use utils::consts::ZELLIJ_ROOT_PLUGIN_DIR;
-use wasm_vm::{
- wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction,
-};
+use serde::{Deserialize, Serialize};
+use wasm_vm::PluginEnv;
+use wasm_vm::{wasi_stdout, wasi_write_string, zellij_imports, PluginInstruction};
+use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
+use wasmer_wasi::{Pipe, WasiState};
+use zellij_tile::data::{EventType, InputMode};
/// Instructions sent from server to client
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -48,26 +48,6 @@ pub enum ClientInstruction {
Exit,
}
-// FIXME: It would be good to add some more things to this over time
-#[derive(Debug, Clone, Default)]
-pub struct AppState {
- pub input_mode: InputMode,
-}
-
-// FIXME: Make this a method on the big `Communication` struct, so that app_tx can be extracted
-// from self instead of being explicitly passed here
-pub fn update_state(
- app_tx: &SenderWithContext<AppInstruction>,
- update_fn: impl FnOnce(AppState) -> AppState,
-) {
- let (state_tx, state_rx) = mpsc::channel();
-
- drop(app_tx.send(AppInstruction::GetState(state_tx)));
- let state = state_rx.recv().unwrap();
-
- drop(app_tx.send(AppInstruction::SetState(update_fn(state))))
-}
-
/// An [MPSC](mpsc) asynchronous channel with added error context.
pub type ChannelWithContext<T> = (
mpsc::Sender<(T, ErrorContext)>,
@@ -390,6 +370,9 @@ pub fn start(
screen.update_active_tab_name(c);
command_is_executing.done_updating_tabs();
}
+ ScreenInstruction::ChangeInputMode(input_mode) => {
+ screen.change_input_mode(input_mode);
+ }
ScreenInstruction::Exit => {
break;
}
@@ -547,8 +530,6 @@ pub fn start(
send_screen_instructions.update(err_ctx);
os_input.update_senders(err_ctx);
match app_instruction {
- AppInstruction::GetState(state_tx) => drop(state_tx.send(app_state.clone())),
- AppInstruction::SetState(state) => app_state = state,
AppInstruction::Exit => break,
AppInstruction::Error(backtrace) => {
let _ = os_input.send_to_server(ServerInstruction::ClientExit);
diff --git a/src/common/screen.rs b/src/common/screen.rs
index 7dbc2fe4..cba24618 100644
--- a/src/common/screen.rs
+++ b/src/common/screen.rs
@@ -80,7 +80,7 @@ pub struct Screen {
active_tab_index: Option<usize>,
/// The [`ClientOsApi`] this [`Screen`] uses.
os_api: Box<dyn ClientOsApi>,
- tabname_buf: String,
+ input_mode: InputMode,
}
impl Screen {
diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs
index d4580572..31b1000c 100644
--- a/src/common/wasm_vm.rs
+++ b/src/common/wasm_vm.rs
@@ -21,7 +21,6 @@ pub enum PluginInstruction {
Update(Option<u32>, Event), // Focused plugin / broadcast, event data
Render(Sender<String>, u32, usize, usize), // String buffer, plugin id, rows, cols
Unload(u32),
- UpdateTabs(Vec<TabData>), // num tabs, active tab
Exit,
}