mirror of
https://github.com/zellij-org/zellij.git
synced 2024-12-25 02:06:19 +03:00
Deduplicate the WASM interface structs
This commit is contained in:
parent
3e10e34575
commit
06bce9a1fd
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -2258,7 +2258,6 @@ dependencies = [
|
||||
"strip-ansi-escapes",
|
||||
"structopt",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"termion_temporary_zellij_fork",
|
||||
"termios",
|
||||
"toml",
|
||||
@ -2268,6 +2267,7 @@ dependencies = [
|
||||
"walkdir",
|
||||
"wasmer",
|
||||
"wasmer-wasi",
|
||||
"zellij-tile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2276,4 +2276,6 @@ version = "0.5.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
]
|
||||
|
@ -27,17 +27,17 @@ signal-hook = "0.1.10"
|
||||
strip-ansi-escapes = "0.1.0"
|
||||
structopt = "0.3"
|
||||
# termion = { git = "https://gitlab.com/TheLostLambda/termion.git", version = "1.6.0", features = ["serde"] }
|
||||
termion = { package = "termion_temporary_zellij_fork" , version = "1.6.0", features = ["serde"]}
|
||||
termion = { package = "termion_temporary_zellij_fork", version = "1.6.0", features = ["serde"]}
|
||||
termios = "0.3"
|
||||
unicode-truncate = "0.2.0"
|
||||
unicode-width = "0.1.8"
|
||||
vte = "0.8.0"
|
||||
strum = "0.20.0"
|
||||
strum_macros = "0.20.0"
|
||||
lazy_static = "1.4.0"
|
||||
wasmer = "1.0.0"
|
||||
wasmer-wasi = "1.0.0"
|
||||
interprocess = "1.0.1"
|
||||
zellij-tile = { path = "zellij-tile/", version = "0.5.0" }
|
||||
|
||||
[dependencies.async-std]
|
||||
version = "1.3.0"
|
||||
|
@ -1,6 +1,6 @@
|
||||
use colored::*;
|
||||
use std::fmt::{Display, Error, Formatter};
|
||||
use zellij_tile::*;
|
||||
use zellij_tile::prelude::*;
|
||||
|
||||
// for more of these, copy paste from: https://en.wikipedia.org/wiki/Box-drawing_character
|
||||
static ARROW_SEPARATOR: &str = " ";
|
||||
@ -152,7 +152,7 @@ fn key_path(help: &Help) -> LinePart {
|
||||
len,
|
||||
)
|
||||
}
|
||||
InputMode::Normal | _ => {
|
||||
InputMode::Normal => {
|
||||
let key_path = superkey_text.on_green();
|
||||
let separator = ARROW_SEPARATOR.green().on_black();
|
||||
(
|
||||
|
@ -3,7 +3,7 @@ mod state;
|
||||
use colored::*;
|
||||
use state::{FsEntry, State};
|
||||
use std::{cmp::min, fs::read_dir};
|
||||
use zellij_tile::*;
|
||||
use zellij_tile::prelude::*;
|
||||
|
||||
register_tile!(State);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod line;
|
||||
mod tab;
|
||||
|
||||
use zellij_tile::*;
|
||||
use zellij_tile::prelude::*;
|
||||
|
||||
use crate::line::tab_line;
|
||||
use crate::tab::tab_style;
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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>>;
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -8,4 +8,6 @@ license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
serde_json = "1.0"
|
||||
strum = "0.20.0"
|
||||
strum_macros = "0.20.0"
|
68
zellij-tile/src/data.rs
Normal file
68
zellij-tile/src/data.rs
Normal file
@ -0,0 +1,68 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Key {
|
||||
Backspace,
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
Home,
|
||||
End,
|
||||
PageUp,
|
||||
PageDown,
|
||||
BackTab,
|
||||
Delete,
|
||||
Insert,
|
||||
F(u8),
|
||||
Char(char),
|
||||
Alt(char),
|
||||
Ctrl(char),
|
||||
Null,
|
||||
Esc,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
impl Default for InputMode {
|
||||
fn default() -> InputMode {
|
||||
InputMode::Normal
|
||||
}
|
||||
}
|
||||
|
||||
/// 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>
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct TabData {
|
||||
/* subset of fields to publish to plugins */
|
||||
pub position: usize,
|
||||
pub name: String,
|
||||
pub active: bool,
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
mod shim;
|
||||
pub mod data;
|
||||
pub mod prelude;
|
||||
pub mod shim;
|
||||
|
||||
use data::*;
|
||||
|
||||
pub use shim::*;
|
||||
#[allow(unused_variables)]
|
||||
pub trait ZellijTile {
|
||||
fn load(&mut self) {}
|
||||
@ -34,14 +37,16 @@ macro_rules! register_tile {
|
||||
#[no_mangle]
|
||||
pub fn handle_key() {
|
||||
STATE.with(|state| {
|
||||
state.borrow_mut().handle_key($crate::get_key());
|
||||
state.borrow_mut().handle_key($crate::shim::get_key());
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn handle_global_key() {
|
||||
STATE.with(|state| {
|
||||
state.borrow_mut().handle_global_key($crate::get_key());
|
||||
state
|
||||
.borrow_mut()
|
||||
.handle_global_key($crate::shim::get_key());
|
||||
});
|
||||
}
|
||||
|
||||
@ -57,7 +62,7 @@ macro_rules! register_tile {
|
||||
STATE.with(|state| {
|
||||
state
|
||||
.borrow_mut()
|
||||
.handle_tab_rename_keypress($crate::get_key());
|
||||
.handle_tab_rename_keypress($crate::shim::get_key());
|
||||
})
|
||||
}
|
||||
};
|
||||
|
3
zellij-tile/src/prelude.rs
Normal file
3
zellij-tile/src/prelude.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub use crate::data::*;
|
||||
pub use crate::shim::*;
|
||||
pub use crate::*;
|
@ -1,61 +1,7 @@
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::{io, path::Path};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Key {
|
||||
Backspace,
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
Home,
|
||||
End,
|
||||
PageUp,
|
||||
PageDown,
|
||||
BackTab,
|
||||
Delete,
|
||||
Insert,
|
||||
F(u8),
|
||||
Char(char),
|
||||
Alt(char),
|
||||
Ctrl(char),
|
||||
Null,
|
||||
Esc,
|
||||
}
|
||||
|
||||
// TODO: use same struct from main crate?
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Help {
|
||||
pub mode: InputMode,
|
||||
pub keybinds: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
// TODO: use same struct from main crate?
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum InputMode {
|
||||
Normal,
|
||||
Command,
|
||||
Resize,
|
||||
Pane,
|
||||
Tab,
|
||||
RenameTab,
|
||||
Scroll,
|
||||
Exiting,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct TabData {
|
||||
/* subset of fields to publish to plugins */
|
||||
pub position: usize,
|
||||
pub name: String,
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
impl Default for InputMode {
|
||||
fn default() -> InputMode {
|
||||
InputMode::Normal
|
||||
}
|
||||
}
|
||||
use crate::data::*;
|
||||
|
||||
pub fn get_key() -> Key {
|
||||
deserialize_from_stdin().unwrap()
|
||||
|
Loading…
Reference in New Issue
Block a user