Markups from self-review

This commit is contained in:
Kyle Sutherland-Cash 2021-05-08 05:07:41 -07:00
parent 9a3e8bcb84
commit 4fb4faa28d
5 changed files with 46 additions and 48 deletions

View file

@ -1,22 +1,21 @@
use ::async_std::stream::*; use async_std::stream::*;
use ::async_std::task; use async_std::task;
use ::async_std::task::*; use async_std::task::*;
use ::std::collections::HashMap; use std::collections::HashMap;
use ::std::os::unix::io::RawFd; use std::os::unix::io::RawFd;
use ::std::pin::*; use std::pin::*;
use ::std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use std::path::PathBuf; use std::path::PathBuf;
use super::{screen::ScreenInstruction, thread_bus::SenderWithContext}; use crate::client::panes::PaneId;
use crate::common::errors::{get_current_ctx, ContextType, PtyContext};
use crate::common::screen::ScreenInstruction;
use crate::common::thread_bus::{Bus, ThreadSenders};
use crate::layout::Layout;
use crate::os_input_output::ServerOsApi; use crate::os_input_output::ServerOsApi;
use crate::server::ServerInstruction;
use crate::utils::logging::debug_to_file; use crate::utils::logging::debug_to_file;
use crate::wasm_vm::PluginInstruction; use crate::wasm_vm::PluginInstruction;
use crate::{
common::thread_bus::Bus,
errors::{get_current_ctx, ContextType, PtyContext},
panes::PaneId,
};
use crate::{layout::Layout, server::ServerInstruction};
pub struct ReadFromPid { pub struct ReadFromPid {
pid: RawFd, pid: RawFd,
@ -143,7 +142,7 @@ pub fn pty_thread_main(mut pty: Pty, maybe_layout: Option<Layout>) {
fn stream_terminal_bytes( fn stream_terminal_bytes(
pid: RawFd, pid: RawFd,
send_screen_instructions: SenderWithContext<ScreenInstruction>, senders: ThreadSenders,
os_input: Box<dyn ServerOsApi>, os_input: Box<dyn ServerOsApi>,
debug: bool, debug: bool,
) -> JoinHandle<()> { ) -> JoinHandle<()> {
@ -165,7 +164,7 @@ fn stream_terminal_bytes(
} }
} }
if !bytes_is_empty { if !bytes_is_empty {
let _ = send_screen_instructions.send(ScreenInstruction::PtyBytes(pid, bytes)); let _ = senders.send_to_screen(ScreenInstruction::PtyBytes(pid, bytes));
// for UX reasons, if we got something on the wire, we only send the render notice if: // for UX reasons, if we got something on the wire, we only send the render notice if:
// 1. there aren't any more bytes on the wire afterwards // 1. there aren't any more bytes on the wire afterwards
// 2. a certain period (currently 30ms) has elapsed since the last render // 2. a certain period (currently 30ms) has elapsed since the last render
@ -176,7 +175,7 @@ fn stream_terminal_bytes(
Some(receive_time) => { Some(receive_time) => {
if receive_time.elapsed() > max_render_pause { if receive_time.elapsed() > max_render_pause {
pending_render = false; pending_render = false;
let _ = send_screen_instructions.send(ScreenInstruction::Render); let _ = senders.send_to_screen(ScreenInstruction::Render);
last_byte_receive_time = Some(Instant::now()); last_byte_receive_time = Some(Instant::now());
} else { } else {
pending_render = true; pending_render = true;
@ -190,21 +189,21 @@ fn stream_terminal_bytes(
} else { } else {
if pending_render { if pending_render {
pending_render = false; pending_render = false;
let _ = send_screen_instructions.send(ScreenInstruction::Render); let _ = senders.send_to_screen(ScreenInstruction::Render);
} }
last_byte_receive_time = None; last_byte_receive_time = None;
task::sleep(::std::time::Duration::from_millis(10)).await; task::sleep(::std::time::Duration::from_millis(10)).await;
} }
} }
send_screen_instructions senders
.send(ScreenInstruction::Render) .send_to_screen(ScreenInstruction::Render)
.unwrap(); .unwrap();
#[cfg(not(test))] #[cfg(not(test))]
// this is a little hacky, and is because the tests end the file as soon as // this is a little hacky, and is because the tests end the file as soon as
// we read everything, rather than hanging until there is new data // we read everything, rather than hanging until there is new data
// a better solution would be to fix the test fakes, but this will do for now // a better solution would be to fix the test fakes, but this will do for now
send_screen_instructions senders
.send(ScreenInstruction::ClosePane(PaneId::Terminal(pid))) .send_to_screen(ScreenInstruction::ClosePane(PaneId::Terminal(pid)))
.unwrap(); .unwrap();
} }
}) })
@ -228,7 +227,7 @@ impl Pty {
.spawn_terminal(file_to_open); .spawn_terminal(file_to_open);
let task_handle = stream_terminal_bytes( let task_handle = stream_terminal_bytes(
pid_primary, pid_primary,
self.bus.senders.to_screen.as_ref().unwrap().clone(), self.bus.senders.clone(),
self.bus.os_input.as_ref().unwrap().clone(), self.bus.os_input.as_ref().unwrap().clone(),
self.debug_to_file, self.debug_to_file,
); );
@ -255,7 +254,7 @@ impl Pty {
for id in new_pane_pids { for id in new_pane_pids {
let task_handle = stream_terminal_bytes( let task_handle = stream_terminal_bytes(
id, id,
self.bus.senders.to_screen.as_ref().unwrap().clone(), self.bus.senders.clone(),
self.bus.os_input.as_ref().unwrap().clone(), self.bus.os_input.as_ref().unwrap().clone(),
self.debug_to_file, self.debug_to_file,
); );

View file

@ -7,11 +7,12 @@ use std::str;
use crate::common::pty::{PtyInstruction, VteBytes}; use crate::common::pty::{PtyInstruction, VteBytes};
use crate::common::thread_bus::Bus; use crate::common::thread_bus::Bus;
use crate::errors::{ContextType, ScreenContext}; use crate::errors::{ContextType, ScreenContext};
use crate::layout::Layout;
use crate::panes::PaneId;
use crate::panes::PositionAndSize; use crate::panes::PositionAndSize;
use crate::server::ServerInstruction; use crate::server::ServerInstruction;
use crate::tab::Tab; use crate::tab::Tab;
use crate::wasm_vm::PluginInstruction; use crate::wasm_vm::PluginInstruction;
use crate::{layout::Layout, panes::PaneId};
use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, TabInfo}; use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, TabInfo};

View file

@ -1,14 +1,13 @@
use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::PathBuf;
use std::process;
use std::str::FromStr;
use std::sync::{mpsc::Sender, Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use std::{
collections::{HashMap, HashSet},
fs,
path::PathBuf,
process,
str::FromStr,
sync::{mpsc::Sender, Arc, Mutex},
thread,
time::{Duration, Instant},
};
use wasmer::{ use wasmer::{
imports, ChainableNamedResolver, Function, ImportObject, Instance, Module, Store, Value, imports, ChainableNamedResolver, Function, ImportObject, Instance, Module, Store, Value,
WasmerEnv, WasmerEnv,
@ -16,13 +15,11 @@ use wasmer::{
use wasmer_wasi::{Pipe, WasiEnv, WasiState}; use wasmer_wasi::{Pipe, WasiEnv, WasiState};
use zellij_tile::data::{Event, EventType, PluginIds}; use zellij_tile::data::{Event, EventType, PluginIds};
use super::{ use crate::common::errors::{ContextType, PluginContext};
errors::{ContextType, PluginContext}, use crate::common::pty::PtyInstruction;
pty::PtyInstruction, use crate::common::screen::ScreenInstruction;
screen::ScreenInstruction, use crate::common::thread_bus::{Bus, ThreadSenders};
thread_bus::{Bus, ThreadSenders}, use crate::common::PaneId;
PaneId,
};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum PluginInstruction { pub enum PluginInstruction {

View file

@ -69,7 +69,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>) -> thread::JoinHandle<()> {
let to_server = to_server.clone(); let to_server = to_server.clone();
move || route_thread_main(sessions, os_input, to_server) move || route_thread_main(sessions, os_input, to_server)
}); }).unwrap();
#[cfg(not(test))] #[cfg(not(test))]
let _ = thread::Builder::new() let _ = thread::Builder::new()
.name("server_listener".to_string()) .name("server_listener".to_string())
@ -185,7 +185,7 @@ fn init_session(
Some(&to_screen), Some(&to_screen),
None, None,
Some(&to_plugin), Some(&to_plugin),
None, Some(&to_server),
Some(os_input.clone()), Some(os_input.clone()),
), ),
opts.debug, opts.debug,
@ -221,8 +221,8 @@ fn init_session(
plugin_receiver, plugin_receiver,
Some(&to_screen), Some(&to_screen),
Some(&to_pty), Some(&to_pty),
Some(&to_plugin), None,
Some(&to_server), None,
None, None,
); );
let store = Store::default(); let store = Store::default();

View file

@ -3,8 +3,8 @@ use std::sync::{Arc, RwLock};
use zellij_tile::data::Event; use zellij_tile::data::Event;
use crate::common::errors::{ContextType, ServerContext}; use crate::common::errors::{ContextType, ServerContext};
use crate::common::input::actions::Action; use crate::common::input::actions::{Action, Direction};
use crate::common::input::{actions::Direction, handler::get_mode_info}; use crate::common::input::handler::get_mode_info;
use crate::common::os_input_output::ServerOsApi; use crate::common::os_input_output::ServerOsApi;
use crate::common::pty::PtyInstruction; use crate::common::pty::PtyInstruction;
use crate::common::screen::ScreenInstruction; use crate::common::screen::ScreenInstruction;
@ -168,6 +168,7 @@ fn route_action(action: Action, session: &SessionMetaData, os_input: &dyn Server
Action::Quit => panic!("Received unexpected action"), Action::Quit => panic!("Received unexpected action"),
} }
} }
pub fn route_thread_main( pub fn route_thread_main(
sessions: Arc<RwLock<Option<SessionMetaData>>>, sessions: Arc<RwLock<Option<SessionMetaData>>>,
mut os_input: Box<dyn ServerOsApi>, mut os_input: Box<dyn ServerOsApi>,