wip: working on osapi message variants

This commit is contained in:
denis 2021-03-01 15:19:40 +02:00 committed by Kunal Mohan
parent ef1c902be6
commit 627e6b3672
3 changed files with 29 additions and 3 deletions

View File

@ -31,7 +31,7 @@ use crate::server::start_server;
use command_is_executing::CommandIsExecuting; use command_is_executing::CommandIsExecuting;
use errors::{AppContext, ContextType, ErrorContext, PluginContext, ScreenContext}; use errors::{AppContext, ContextType, ErrorContext, PluginContext, ScreenContext};
use input::handler::input_loop; use input::handler::input_loop;
use os_input_output::OsApi; use os_input_output::{OsApi, OsApiInstruction};
use pty_bus::PtyInstruction; use pty_bus::PtyInstruction;
use screen::{Screen, ScreenInstruction}; use screen::{Screen, ScreenInstruction};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -51,6 +51,7 @@ pub enum ServerInstruction {
NewClient(String), NewClient(String),
ToPty(PtyInstruction), ToPty(PtyInstruction),
ToScreen(ScreenInstruction), ToScreen(ScreenInstruction),
OsApi(OsApiInstruction),
DoneClosingPane, DoneClosingPane,
ClosePluginPane(u32), ClosePluginPane(u32),
Exit, Exit,

View File

@ -13,7 +13,7 @@ use std::os::unix::io::RawFd;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::{Child, Command}; use std::process::{Child, Command};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use zellij_tile::data::Palette; use serde::{Deserialize, Serialize};
use signal_hook::{consts::signal::*, iterator::Signals}; use signal_hook::{consts::signal::*, iterator::Signals};
@ -269,6 +269,22 @@ impl OsApi for OsInputOutput {
} }
} }
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum OsApiInstruction {
GetTerminalSizeUsingFd(RawFd),
SetTerminalSizeUsingFd(RawFd, u16, u16),
SetRawMode(RawFd),
UnsetRawMode(RawFd),
SpawnTerminal(Option<PathBuf>),
ReadFromTtyStdout(RawFd, Vec<u8>),
WriteToTtyStdin(RawFd, Vec<u8>),
TcDrain(RawFd),
Kill(RawFd),
ReadFromStdin,
GetStdoutWriter,
BoxClone
}
impl Clone for Box<dyn OsApi> { impl Clone for Box<dyn OsApi> {
fn clone(&self) -> Box<dyn OsApi> { fn clone(&self) -> Box<dyn OsApi> {
self.box_clone() self.box_clone()

View File

@ -4,7 +4,7 @@ use crate::common::{
ServerInstruction, ServerInstruction,
}; };
use crate::errors::{ContextType, ErrorContext, PtyContext}; use crate::errors::{ContextType, ErrorContext, PtyContext};
use crate::os_input_output::OsApi; use crate::os_input_output::{OsApi, OsApiInstruction};
use crate::panes::PaneId; use crate::panes::PaneId;
use crate::pty_bus::{PtyBus, PtyInstruction}; use crate::pty_bus::{PtyBus, PtyInstruction};
use crate::screen::ScreenInstruction; use crate::screen::ScreenInstruction;
@ -24,6 +24,12 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> thread::JoinHand
let server_buffer = SharedRingBuffer::create(ZELLIJ_IPC_PIPE, 8192).unwrap(); let server_buffer = SharedRingBuffer::create(ZELLIJ_IPC_PIPE, 8192).unwrap();
let (send_os_instructions, receive_os_instructions): ChannelWithContext<OsApiInstruction> = channel();
let mut send_os_instructions = SenderWithContext::new(
ErrorContext::new(),
SenderType::Sender(send_os_instructions),
);
// Don't use default layouts in tests, but do everywhere else // Don't use default layouts in tests, but do everywhere else
#[cfg(not(test))] #[cfg(not(test))]
let default_layout = Some(PathBuf::from("default")); let default_layout = Some(PathBuf::from("default"));
@ -160,6 +166,9 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> thread::JoinHand
.send(ClientInstruction::ToScreen(instr)) .send(ClientInstruction::ToScreen(instr))
.unwrap(); .unwrap();
} }
ServerInstruction::OsApi(instr) => {
send_os_instructions.send(instr).unwrap();
}
ServerInstruction::DoneClosingPane => { ServerInstruction::DoneClosingPane => {
send_client_instructions[0] send_client_instructions[0]
.send(ClientInstruction::DoneClosingPane) .send(ClientInstruction::DoneClosingPane)