diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-03-20 01:18:09 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-04 20:47:51 +0530 |
| commit | be060e9a138b1d38cc4476a24cec51fde00c7076 (patch) | |
| tree | 1fa36686f02d8b073f52cd1716d44df29c133d4c /src/common | |
| parent | fix tests (diff) | |
| download | sl0ppij-be060e9a138b1d38cc4476a24cec51fde00c7076.tar.gz sl0ppij-be060e9a138b1d38cc4476a24cec51fde00c7076.tar.xz sl0ppij-be060e9a138b1d38cc4476a24cec51fde00c7076.zip | |
Introduce ServerContext
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/errors.rs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs index 4259600f..e8e02e5a 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -1,7 +1,9 @@ //! Error context system based on a thread-local representation of the call stack, itself based on //! the instructions that are sent between threads. -use super::{os_input_output::ServerOsApiInstruction, AppInstruction, OPENCALLS}; +use super::{ + os_input_output::ServerOsApiInstruction, AppInstruction, ServerInstruction, OPENCALLS, +}; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; use serde::{Deserialize, Serialize}; @@ -144,7 +146,7 @@ pub enum ContextType { Plugin(PluginContext), /// An app-related call. App(AppContext), - IPCServer, // Fix: Create a separate ServerContext when sessions are introduced + IPCServer(ServerContext), StdinHandler, AsyncTask, /// An empty, placeholder call. This should be thought of as representing no call at all. @@ -163,7 +165,7 @@ impl Display for ContextType { ContextType::Os(c) => write!(f, "{}os_thread: {}{:?}", purple, green, c), ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), - ContextType::IpcServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green), + ContextType::IPCServer(c) => write!(f, "{}ipc_server: {}{:?}", purple, green, c), ContextType::StdinHandler => { write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) } @@ -367,3 +369,37 @@ impl From<&AppInstruction> for AppContext { } } } + +/// Stack call representations corresponding to the different types of [`AppInstruction`]s. +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +pub enum ServerContext { + OpenFile, + SplitHorizontally, + SplitVertically, + MoveFocus, + NewClient, + ToPty, + ToScreen, + OsApi, + DoneClosingPane, + ClosePluginPane, + Exit, +} + +impl From<&ServerInstruction> for ServerContext { + fn from(server_instruction: &ServerInstruction) -> Self { + match *server_instruction { + ServerInstruction::OpenFile(_) => ServerContext::OpenFile, + ServerInstruction::SplitHorizontally => ServerContext::SplitHorizontally, + ServerInstruction::SplitVertically => ServerContext::SplitVertically, + ServerInstruction::MoveFocus => ServerContext::MoveFocus, + ServerInstruction::NewClient(_) => ServerContext::NewClient, + ServerInstruction::ToPty(_) => ServerContext::ToPty, + ServerInstruction::ToScreen(_) => ServerContext::ToScreen, + ServerInstruction::OsApi(_) => ServerContext::OsApi, + ServerInstruction::DoneClosingPane => ServerContext::DoneClosingPane, + ServerInstruction::ClosePluginPane(_) => ServerContext::ClosePluginPane, + ServerInstruction::Exit => ServerContext::Exit, + } + } +} |
