aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordenis <denismaximov98@gmail.com>2021-01-29 07:25:58 +0200
committerdenis <denismaximov98@gmail.com>2021-01-29 07:25:58 +0200
commit354316d20c9326ae272fa93f5ab935aaca31e16f (patch)
tree22f3cafab28957e1e3a8b262089f5cb948d5aea2 /src
parentwip: moved stuff from main into common (diff)
downloadsl0ppij-354316d20c9326ae272fa93f5ab935aaca31e16f.tar.gz
sl0ppij-354316d20c9326ae272fa93f5ab935aaca31e16f.tar.xz
sl0ppij-354316d20c9326ae272fa93f5ab935aaca31e16f.zip
chore: formatting
Diffstat (limited to 'src')
-rw-r--r--src/client/mod.rs7
-rw-r--r--src/client/panes/plugin_pane.rs2
-rw-r--r--src/client/tab.rs2
-rw-r--r--src/common/errors.rs2
-rw-r--r--src/common/input.rs4
-rw-r--r--src/common/ipc.rs6
-rw-r--r--src/common/mod.rs59
-rw-r--r--src/common/pty_bus.rs2
-rw-r--r--src/common/screen.rs2
-rw-r--r--src/common/wasm_vm.rs4
-rw-r--r--src/main.rs14
11 files changed, 50 insertions, 54 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 619ba375..c8276253 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 5e0ea7fa..ff173d18 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 c217db04..3b49a1c4 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 c646b160..90ca6f9e 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 f71fa6e0..125b3ced 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 0bfc0451..425d81d6 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<Session>),
-} \ No newline at end of file
+}
diff --git a/src/common/mod.rs b/src/common/mod.rs
index a4bbfede..d1479ab2 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 crate::layout::Layout;
use command_is_executing::CommandIsExecuting;
-use errors::{
- AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext,
-};
+use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext};
use input::input_loop;
-use crate::layout::Layout;
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<AppInstruction>,
+ 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<T> = (Sender<(T, ErrorContext)>, Receiver<(T, ErrorContext)>);
pub type SyncChannelWithContext<T> = (SyncSender<(T, ErrorContext)>, Receiver<(T, ErrorContext)>);
@@ -97,31 +115,11 @@ impl<T: Clone> SenderWithContext<T> {
}
}
-#[derive(Serialize, Deserialize, Debug)]
-pub enum ApiCommand {
- OpenFile(PathBuf),
- SplitHorizontally,
- SplitVertically,
- MoveFocus,
-}
-
unsafe impl<T: Clone> Send for SenderWithContext<T> {}
unsafe impl<T: Clone> Sync for SenderWithContext<T> {}
thread_local!(static OPENCALLS: RefCell<ErrorContext> = RefCell::default());
-pub fn update_state(
- app_tx: &SenderWithContext<AppInstruction>,
- 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<AppState>),
@@ -130,7 +128,6 @@ pub enum AppInstruction {
Error(String),
}
-
pub fn start(mut os_input: Box<dyn OsApi>, 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<dyn OsApi>, 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 bb4b420e..d341662d 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 0dba038c..2438dba0 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 aca60582..d678401d 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 434eff3a..aea289fb 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
+}