summaryrefslogtreecommitdiffstats
path: root/zellij-tile
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-03-09 19:39:42 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-03-09 19:39:42 +0000
commit06bce9a1fd88651a2e85c120776bc07399206806 (patch)
tree6ecb2e8535d9cf2071d4ad5c22a295cd45089d18 /zellij-tile
parent3e10e345754e9b2759cf5240126de398921db691 (diff)
Deduplicate the WASM interface structs
Diffstat (limited to 'zellij-tile')
-rw-r--r--zellij-tile/Cargo.toml4
-rw-r--r--zellij-tile/src/data.rs68
-rw-r--r--zellij-tile/src/lib.rs15
-rw-r--r--zellij-tile/src/prelude.rs3
-rw-r--r--zellij-tile/src/shim.rs58
5 files changed, 86 insertions, 62 deletions
diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml
index bdabb1756..eb9a2d594 100644
--- a/zellij-tile/Cargo.toml
+++ b/zellij-tile/Cargo.toml
@@ -8,4 +8,6 @@ license = "MIT"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
-serde_json = "1.0" \ No newline at end of file
+serde_json = "1.0"
+strum = "0.20.0"
+strum_macros = "0.20.0" \ No newline at end of file
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs
new file mode 100644
index 000000000..b64f1e4e8
--- /dev/null
+++ b/zellij-tile/src/data.rs
@@ -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,
+}
diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs
index 51ec96803..ea38f6c9b 100644
--- a/zellij-tile/src/lib.rs
+++ b/zellij-tile/src/lib.rs
@@ -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());
})
}
};
diff --git a/zellij-tile/src/prelude.rs b/zellij-tile/src/prelude.rs
new file mode 100644
index 000000000..2dd24a471
--- /dev/null
+++ b/zellij-tile/src/prelude.rs
@@ -0,0 +1,3 @@
+pub use crate::data::*;
+pub use crate::shim::*;
+pub use crate::*;
diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs
index 20185c72f..bb038e827 100644
--- a/zellij-tile/src/shim.rs
+++ b/zellij-tile/src/shim.rs
@@ -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()