aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-03-29 22:43:54 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:48:14 +0530
commitea732166e35368b423de348a41db41662c3686ad (patch)
tree32c20dac42250ae0bc264030e3278f6519aa3ccd /src/common
parentsplit start into start_server and start_client (diff)
downloadsl0ppij-ea732166e35368b423de348a41db41662c3686ad.tar.gz
sl0ppij-ea732166e35368b423de348a41db41662c3686ad.tar.xz
sl0ppij-ea732166e35368b423de348a41db41662c3686ad.zip
client side threads should send messages directly to server and router threads should do the actual routing
Diffstat (limited to 'src/common')
-rw-r--r--src/common/errors.rs10
-rw-r--r--src/common/input/handler.rs12
-rw-r--r--src/common/ipc.rs2
-rw-r--r--src/common/os_input_output.rs6
-rw-r--r--src/common/screen.rs10
5 files changed, 17 insertions, 23 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs
index ab831bc4..3ee36752 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -350,11 +350,8 @@ impl From<&PluginInstruction> for PluginContext {
pub enum AppContext {
Exit,
Error,
- ToPty,
- ToPlugin,
- ToScreen,
DoneClosingPane,
- OsApi,
+ ToPty,
}
impl From<&AppInstruction> for AppContext {
@@ -362,11 +359,8 @@ impl From<&AppInstruction> for AppContext {
match *app_instruction {
AppInstruction::Exit => AppContext::Exit,
AppInstruction::Error(_) => AppContext::Error,
- AppInstruction::ToPty(_) => AppContext::ToPty,
- AppInstruction::OsApi(_) => AppContext::OsApi,
- AppInstruction::ToPlugin(_) => AppContext::ToPlugin,
- AppInstruction::ToScreen(_) => AppContext::ToScreen,
AppInstruction::DoneClosingPane => AppContext::DoneClosingPane,
+ AppInstruction::ToPty(_) => AppContext::ToPty,
}
}
}
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index 447cc443..09cc1a0d 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -8,6 +8,7 @@ use crate::errors::ContextType;
use crate::os_input_output::ClientOsApi;
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruction;
+use crate::server::ServerInstruction;
use crate::wasm_vm::PluginInstruction;
use crate::CommandIsExecuting;
@@ -56,6 +57,7 @@ impl InputHandler {
err_ctx.add_call(ContextType::StdinHandler);
self.send_app_instructions.update(err_ctx);
self.send_screen_instructions.update(err_ctx);
+ self.os_input.update_senders(err_ctx);
if let Ok(keybinds) = get_default_keybinds() {
'input_loop: loop {
//@@@ I think this should actually just iterate over stdin directly
@@ -225,9 +227,8 @@ impl InputHandler {
None => PtyInstruction::SpawnTerminal(None),
};
self.command_is_executing.opening_new_pane();
- self.send_app_instructions
- .send(AppInstruction::ToPty(pty_instr))
- .unwrap();
+ self.os_input
+ .send_to_server(ServerInstruction::ToPty(pty_instr));
self.command_is_executing.wait_until_new_pane_is_opened();
}
Action::CloseFocus => {
@@ -239,9 +240,8 @@ impl InputHandler {
}
Action::NewTab => {
self.command_is_executing.updating_tabs();
- self.send_app_instructions
- .send(AppInstruction::ToPty(PtyInstruction::NewTab))
- .unwrap();
+ self.os_input
+ .send_to_server(ServerInstruction::ToPty(PtyInstruction::NewTab));
self.command_is_executing.wait_until_tabs_are_updated();
}
Action::GoToNextTab => {
diff --git a/src/common/ipc.rs b/src/common/ipc.rs
index 81576b86..68aa676b 100644
--- a/src/common/ipc.rs
+++ b/src/common/ipc.rs
@@ -24,7 +24,7 @@ pub enum ClientType {
// Types of messages sent from the client to the server
#[derive(Serialize, Deserialize)]
-pub enum ClientToServerMsg {
+pub enum _ClientToServerMsg {
// List which sessions are available
ListSessions,
// Create a new session
diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs
index 92fc51cb..7cc43e27 100644
--- a/src/common/os_input_output.rs
+++ b/src/common/os_input_output.rs
@@ -189,7 +189,7 @@ impl<T: Serialize> IpcSenderWithContext<T> {
/// Sends an event, along with the current [`ErrorContext`], on this
/// [`IpcSenderWithContext`]'s channel.
- fn send(&mut self, msg: T) -> ipmpsc::Result<()> {
+ fn send(&self, msg: T) -> ipmpsc::Result<()> {
self.sender.send(&(msg, self.err_ctx))
}
}
@@ -335,7 +335,7 @@ pub trait ClientOsApi: Send + Sync {
/// Returns a [`Box`] pointer to this [`ClientOsApi`] struct.
fn box_clone(&self) -> Box<dyn ClientOsApi>;
/// Sends a message to the server.
- fn send_to_server(&mut self, msg: ServerInstruction);
+ fn send_to_server(&self, msg: ServerInstruction);
/// Update ErrorContext of senders
fn update_senders(&mut self, new_ctx: ErrorContext);
/// Receives a message on client-side IPC channel
@@ -372,7 +372,7 @@ impl ClientOsApi for ClientOsInputOutput {
let stdout = ::std::io::stdout();
Box::new(stdout)
}
- fn send_to_server(&mut self, msg: ServerInstruction) {
+ fn send_to_server(&self, msg: ServerInstruction) {
self.server_sender.send(msg).unwrap();
}
fn update_senders(&mut self, new_ctx: ErrorContext) {
diff --git a/src/common/screen.rs b/src/common/screen.rs
index 229939f1..65222894 100644
--- a/src/common/screen.rs
+++ b/src/common/screen.rs
@@ -11,7 +11,8 @@ use crate::client::AppInstruction;
use crate::common::SenderWithContext;
use crate::os_input_output::ClientOsApi;
use crate::panes::PositionAndSize;
-use crate::pty_bus::{PtyInstruction, VteBytes};
+use crate::pty_bus::{PtyInstruction, VteEvent};
+use crate::server::ServerInstruction;
use crate::tab::Tab;
use crate::{errors::ErrorContext, wasm_vm::PluginInstruction};
use crate::{layout::Layout, panes::PaneId};
@@ -80,7 +81,7 @@ pub struct Screen {
/// The index of this [`Screen`]'s active [`Tab`].
active_tab_index: Option<usize>,
/// The [`ClientOsApi`] this [`Screen`] uses.
- os_api: Box<dyn ClientOsApi>,
+ pub os_api: Box<dyn ClientOsApi>,
input_mode: InputMode,
}
@@ -210,9 +211,8 @@ impl Screen {
// below we don't check the result of sending the CloseTab instruction to the pty thread
// because this might be happening when the app is closing, at which point the pty thread
// has already closed and this would result in an error
- let _ = self
- .send_app_instructions
- .send(AppInstruction::ToPty(PtyInstruction::CloseTab(pane_ids)));
+ self.os_api
+ .send_to_server(ServerInstruction::ToPty(PtyInstruction::CloseTab(pane_ids)));
if self.tabs.is_empty() {
self.active_tab_index = None;
self.send_app_instructions