diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-03-09 19:39:42 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-03-09 19:39:42 +0000 |
| commit | 06bce9a1fd88651a2e85c120776bc07399206806 (patch) | |
| tree | 6ecb2e8535d9cf2071d4ad5c22a295cd45089d18 /src | |
| parent | Rename init() to load() in plugin API + Bump deps (diff) | |
| download | sl0ppij-06bce9a1fd88651a2e85c120776bc07399206806.tar.gz sl0ppij-06bce9a1fd88651a2e85c120776bc07399206806.tar.xz sl0ppij-06bce9a1fd88651a2e85c120776bc07399206806.zip | |
Deduplicate the WASM interface structs
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/tab.rs | 9 | ||||
| -rw-r--r-- | src/common/input/actions.rs | 4 | ||||
| -rw-r--r-- | src/common/input/handler.rs | 39 | ||||
| -rw-r--r-- | src/common/input/keybinds.rs | 2 | ||||
| -rw-r--r-- | src/common/mod.rs | 17 | ||||
| -rw-r--r-- | src/common/screen.rs | 4 | ||||
| -rw-r--r-- | src/common/wasm_vm.rs | 2 |
7 files changed, 16 insertions, 61 deletions
diff --git a/src/client/tab.rs b/src/client/tab.rs index 1ef0b720..8ee3775b 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -8,7 +8,6 @@ use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::wasm_vm::{PluginInputType, PluginInstruction}; use crate::{boundaries::Boundaries, panes::PluginPane}; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; -use serde::{Deserialize, Serialize}; use std::os::unix::io::RawFd; use std::{ cmp::Reverse, @@ -67,14 +66,6 @@ pub struct Tab { expansion_boundary: Option<PositionAndSize>, } -#[derive(Clone, Debug, Default, Serialize, Deserialize)] -pub struct TabData { - /* subset of fields to publish to plugins */ - pub position: usize, - pub name: String, - pub active: bool, -} - // FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication pub trait Pane { fn x(&self) -> usize; diff --git a/src/common/input/actions.rs b/src/common/input/actions.rs index 88a7036f..059255d3 100644 --- a/src/common/input/actions.rs +++ b/src/common/input/actions.rs @@ -1,6 +1,6 @@ //! Definition of the actions that can be bound to keys. -use super::handler; +use zellij_tile::data::InputMode; /// The four directions (left, right, up, down). #[derive(Clone, Debug)] @@ -19,7 +19,7 @@ pub enum Action { /// Write to the terminal. Write(Vec<u8>), /// Switch to the specified input mode. - SwitchToMode(handler::InputMode), + SwitchToMode(InputMode), /// Resize focus pane in specified direction. Resize(Direction), /// Switch focus to next pane in specified direction. diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 52db9b4f..e498fbb6 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -10,9 +10,8 @@ use crate::screen::ScreenInstruction; use crate::wasm_vm::{EventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; -use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; use termion::input::TermReadEventsAndRaw; +use zellij_tile::data::{Help, InputMode}; use super::keybinds::key_to_actions; @@ -269,42 +268,6 @@ impl InputHandler { } } -/// Describes the different input modes, which change the way that keystrokes will be interpreted. -#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize)] -pub enum InputMode { - /// In `Normal` mode, input is always written to the terminal, except for one special input that - /// triggers the switch to [`InputMode::Command`] mode. - Normal, - /// In `Command` mode, input is bound to actions (more precisely, sequences of actions). - /// `Command` mode gives access to the other modes non-`InputMode::Normal` modes. - /// etc. - Command, - /// `Resize` mode allows resizing the different existing panes. - Resize, - /// `Pane` mode allows creating and closing panes, as well as moving between them. - Pane, - /// `Tab` mode allows creating and closing tabs, as well as moving between them. - Tab, - /// `Scroll` mode allows scrolling up and down within a pane. - Scroll, - RenameTab, -} - -/// Represents the contents of the help message that is printed in the status bar, -/// which indicates the current [`InputMode`] and what the keybinds for that mode -/// are. Related to the default `status-bar` plugin. -#[derive(Default, Debug, Clone, Serialize, Deserialize)] -pub struct Help { - pub mode: InputMode, - pub keybinds: Vec<(String, String)>, // <shortcut> => <shortcut description> -} - -impl Default for InputMode { - fn default() -> InputMode { - InputMode::Normal - } -} - /// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds /// (as pairs of [`String`]s). // TODO this should probably be automatically generated in some way diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index 46abf4ab..da0f1c15 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -1,12 +1,12 @@ //! Mapping of inputs to sequences of actions. use super::actions::{Action, Direction}; -use super::handler::InputMode; use std::collections::HashMap; use strum::IntoEnumIterator; use termion::event::Key; +use zellij_tile::data::*; type Keybinds = HashMap<InputMode, ModeKeybinds>; type ModeKeybinds = HashMap<Key, Vec<Action>>; diff --git a/src/common/mod.rs b/src/common/mod.rs index 7b19bcef..9c41e131 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -16,27 +16,26 @@ 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::handler::InputMode; -use serde::{Deserialize, Serialize}; -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 crate::panes::PaneId; use command_is_executing::CommandIsExecuting; +use directories_next::ProjectDirs; use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext}; use input::handler::input_loop; use os_input_output::OsApi; use pty_bus::{PtyBus, PtyInstruction}; use screen::{Screen, ScreenInstruction}; +use serde::{Deserialize, Serialize}; +use termion::input::TermRead; use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; +use wasm_vm::PluginEnv; use wasm_vm::{ wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction, }; +use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; +use wasmer_wasi::{Pipe, WasiState}; +use zellij_tile::data::InputMode; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { diff --git a/src/common/screen.rs b/src/common/screen.rs index 199a1223..b848cc49 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -9,10 +9,12 @@ use super::{AppInstruction, SenderWithContext}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; -use crate::tab::{Tab, TabData}; +use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; +use zellij_tile::data::TabData; + /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] pub enum ScreenInstruction { diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 15b920ad..24e8d2a6 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -1,4 +1,3 @@ -use crate::tab::TabData; use serde::{Deserialize, Serialize}; use std::{ path::PathBuf, @@ -6,6 +5,7 @@ use std::{ }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; +use zellij_tile::data::TabData; use super::{ input::handler::get_help, pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, |
