From 354316d20c9326ae272fa93f5ab935aaca31e16f Mon Sep 17 00:00:00 2001 From: denis Date: Fri, 29 Jan 2021 07:25:58 +0200 Subject: [PATCH] chore: formatting --- src/client/mod.rs | 7 ++-- src/client/panes/plugin_pane.rs | 2 +- src/client/tab.rs | 2 +- src/common/errors.rs | 2 +- src/common/input.rs | 4 +-- src/common/ipc.rs | 6 ++-- src/common/mod.rs | 61 ++++++++++++++++----------------- src/common/pty_bus.rs | 2 +- src/common/screen.rs | 2 +- src/common/wasm_vm.rs | 4 +-- src/main.rs | 14 ++++---- 11 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 619ba375f..c8276253a 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,9 +1,6 @@ pub mod boundaries; pub mod layout; -pub mod tab; pub mod panes; +pub mod tab; - -pub fn start_client() { - -} \ No newline at end of file +pub fn start_client() {} diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index 5e0ea7fa1..ff173d187 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -1,6 +1,6 @@ #![allow(clippy::clippy::if_same_then_else)] -use crate::{pty_bus::VteEvent, tab::Pane, wasm_vm::PluginInstruction, common::SenderWithContext}; +use crate::{common::SenderWithContext, pty_bus::VteEvent, tab::Pane, wasm_vm::PluginInstruction}; use std::{sync::mpsc::channel, unimplemented}; diff --git a/src/client/tab.rs b/src/client/tab.rs index c217db04f..3b49a1c4a 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,9 +1,9 @@ +use crate::common::{AppInstruction, SenderWithContext}; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::{boundaries::Boundaries, panes::PluginPane}; use crate::{layout::Layout, wasm_vm::PluginInstruction}; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; -use crate::common::{AppInstruction, SenderWithContext}; use std::os::unix::io::RawFd; use std::{ cmp::Reverse, diff --git a/src/common/errors.rs b/src/common/errors.rs index c646b160d..90ca6f9ec 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -1,6 +1,6 @@ +use super::{AppInstruction, OPENCALLS}; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; -use super::{AppInstruction, OPENCALLS}; use std::fmt::{Display, Error, Formatter}; diff --git a/src/common/input.rs b/src/common/input.rs index f71fa6e0a..125b3ced2 100644 --- a/src/common/input.rs +++ b/src/common/input.rs @@ -1,9 +1,9 @@ +use super::{os_input_output::OsApi, update_state, AppState}; +use super::{AppInstruction, SenderWithContext, OPENCALLS}; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; use crate::CommandIsExecuting; use crate::{errors::ContextType, wasm_vm::PluginInstruction}; -use super::{os_input_output::OsApi, update_state, AppState}; -use super::{AppInstruction, SenderWithContext, OPENCALLS}; struct InputHandler { mode: InputMode, diff --git a/src/common/ipc.rs b/src/common/ipc.rs index 0bfc04511..425d81d68 100644 --- a/src/common/ipc.rs +++ b/src/common/ipc.rs @@ -1,6 +1,6 @@ // IPC stuff for starting to split things into a client and server model +use serde::{Deserialize, Serialize}; use std::collections::HashSet; -use serde::{Serialize, Deserialize}; type SessionID = u64; @@ -30,7 +30,7 @@ pub enum ClientToServerMsg { CreateSession, // Attach to a running session AttachToSession(SessionID, ClientType), - // Force detach + // Force detach DetachSession(SessionID), // Disconnect from the session we're connected to DisconnectFromSession, @@ -43,4 +43,4 @@ pub enum ServerToClientMsg { SessionInfo(Session), // A list of sessions SessionList(HashSet), -} \ No newline at end of file +} diff --git a/src/common/mod.rs b/src/common/mod.rs index a4bbfedef..d1479ab20 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,12 +1,12 @@ +pub mod command_is_executing; +pub mod errors; pub mod input; +pub mod ipc; pub mod os_input_output; pub mod pty_bus; pub mod screen; -pub mod ipc; -pub mod wasm_vm; -pub mod command_is_executing; -pub mod errors; pub mod utils; +pub mod wasm_vm; use std::io::Write; use std::os::unix::net::UnixStream; @@ -16,23 +16,21 @@ use std::thread; use std::{cell::RefCell, sync::mpsc::TrySendError}; use std::{collections::HashMap, fs}; +use crate::panes::PaneId; use directories_next::ProjectDirs; use input::InputMode; use serde::{Deserialize, Serialize}; use structopt::StructOpt; -use crate::panes::PaneId; use termion::input::TermRead; use wasm_vm::PluginEnv; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; use crate::cli::CliArgs; -use command_is_executing::CommandIsExecuting; -use errors::{ - AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext, -}; -use input::input_loop; use crate::layout::Layout; +use command_is_executing::CommandIsExecuting; +use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext}; +use input::input_loop; use os_input_output::{get_os_input, OsApi}; use pty_bus::{PtyBus, PtyInstruction, VteEvent}; use screen::{Screen, ScreenInstruction}; @@ -43,6 +41,14 @@ use utils::{ }; use wasm_vm::{mosaic_imports, wasi_stdout, wasi_write_string, PluginInstruction}; +#[derive(Serialize, Deserialize, Debug)] +pub enum ApiCommand { + OpenFile(PathBuf), + SplitHorizontally, + SplitVertically, + MoveFocus, +} +// FIXME: It would be good to add some more things to this over time #[derive(Debug, Clone)] pub struct AppState { pub input_mode: InputMode, @@ -55,7 +61,19 @@ impl Default for AppState { } } } +// 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, + update_fn: impl FnOnce(AppState) -> AppState, +) { + let (state_tx, state_rx) = channel(); + drop(app_tx.send(AppInstruction::GetState(state_tx))); + let state = state_rx.recv().unwrap(); + + drop(app_tx.send(AppInstruction::SetState(update_fn(state)))) +} pub type ChannelWithContext = (Sender<(T, ErrorContext)>, Receiver<(T, ErrorContext)>); pub type SyncChannelWithContext = (SyncSender<(T, ErrorContext)>, Receiver<(T, ErrorContext)>); @@ -97,31 +115,11 @@ impl SenderWithContext { } } -#[derive(Serialize, Deserialize, Debug)] -pub enum ApiCommand { - OpenFile(PathBuf), - SplitHorizontally, - SplitVertically, - MoveFocus, -} - unsafe impl Send for SenderWithContext {} unsafe impl Sync for SenderWithContext {} thread_local!(static OPENCALLS: RefCell = RefCell::default()); -pub fn update_state( - app_tx: &SenderWithContext, - update_fn: impl FnOnce(AppState) -> AppState, -) { - let (state_tx, state_rx) = channel(); - - drop(app_tx.send(AppInstruction::GetState(state_tx))); - let state = state_rx.recv().unwrap(); - - drop(app_tx.send(AppInstruction::SetState(update_fn(state)))) -} - #[derive(Clone)] pub enum AppInstruction { GetState(Sender), @@ -130,7 +128,6 @@ pub enum AppInstruction { Error(String), } - pub fn start(mut os_input: Box, opts: CliArgs) { let take_snapshot = "\u{1b}[?1049h"; os_input.unset_raw_mode(0); @@ -668,4 +665,4 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .write(goodbye_message.as_bytes()) .unwrap(); os_input.get_stdout_writer().flush().unwrap(); -} \ No newline at end of file +} diff --git a/src/common/pty_bus.rs b/src/common/pty_bus.rs index bb4b420e3..d341662dc 100644 --- a/src/common/pty_bus.rs +++ b/src/common/pty_bus.rs @@ -9,6 +9,7 @@ use ::std::time::{Duration, Instant}; use ::vte; use std::path::PathBuf; +use super::{ScreenInstruction, SenderWithContext, OPENCALLS}; use crate::os_input_output::OsApi; use crate::utils::logging::debug_to_file; use crate::{ @@ -16,7 +17,6 @@ use crate::{ panes::PaneId, }; use crate::{layout::Layout, wasm_vm::PluginInstruction}; -use super::{ScreenInstruction, SenderWithContext, OPENCALLS}; pub struct ReadFromPid { pid: RawFd, diff --git a/src/common/screen.rs b/src/common/screen.rs index 0dba038c9..2438dba09 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -2,13 +2,13 @@ use std::collections::BTreeMap; use std::os::unix::io::RawFd; use std::sync::mpsc::Receiver; +use super::{AppInstruction, SenderWithContext}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; -use super::{AppInstruction, SenderWithContext}; /* * Screen diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index aca60582e..d678401de 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -6,8 +6,8 @@ use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; use super::{ - input::get_help, PaneId, pty_bus::PtyInstruction, screen::ScreenInstruction, - AppInstruction, SenderWithContext, + input::get_help, pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, PaneId, + SenderWithContext, }; #[derive(Clone, Debug)] diff --git a/src/main.rs b/src/main.rs index 434eff3a8..aea289fbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,11 @@ mod common; // TODO mod server; mod client; -use common::{pty_bus, os_input_output, screen, ipc, wasm_vm, command_is_executing, errors, utils, start, ApiCommand}; -use client::{tab, layout, boundaries, panes}; - +use client::{boundaries, layout, panes, tab}; +use common::{ + command_is_executing, errors, ipc, os_input_output, pty_bus, screen, start, utils, wasm_vm, + ApiCommand, +}; use std::io::Write; use std::os::unix::net::UnixStream; @@ -17,8 +19,8 @@ use structopt::StructOpt; use crate::cli::CliArgs; use crate::command_is_executing::CommandIsExecuting; -use crate::os_input_output::{get_os_input}; -use crate::pty_bus::{VteEvent}; +use crate::os_input_output::get_os_input; +use crate::pty_bus::VteEvent; use crate::utils::{ consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR}, logging::*, @@ -54,4 +56,4 @@ pub fn main() { atomic_create_dir(MOSAIC_TMP_LOG_DIR).unwrap(); start(Box::new(os_input), opts); } -} \ No newline at end of file +}