Merged in mosaic-tile and started renaming to zellij
This commit is contained in:
commit
7bab33e5d2
1398 changed files with 173 additions and 0 deletions
12
zellij-tile/Cargo.toml
Normal file
12
zellij-tile/Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "mosaic-tile"
|
||||||
|
version = "0.4.0"
|
||||||
|
authors = ["Brooks J Rady <b.j.rady@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
description = "A small client-side library for writing mosaic plugins (tiles)"
|
||||||
|
repository = "https://github.com/mosaic-org/mosaic-tile"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
46
zellij-tile/src/lib.rs
Normal file
46
zellij-tile/src/lib.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
mod shim;
|
||||||
|
|
||||||
|
pub use shim::*;
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub trait MosaicTile {
|
||||||
|
fn init(&mut self) {}
|
||||||
|
fn draw(&mut self, rows: usize, cols: usize) {}
|
||||||
|
fn handle_key(&mut self, key: Key) {}
|
||||||
|
fn handle_global_key(&mut self, key: Key) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! register_tile {
|
||||||
|
($t:ty) => {
|
||||||
|
thread_local! {
|
||||||
|
static STATE: std::cell::RefCell<$t> = std::cell::RefCell::new(Default::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
STATE.with(|state| {
|
||||||
|
state.borrow_mut().init();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn draw(rows: i32, cols: i32) {
|
||||||
|
STATE.with(|state| {
|
||||||
|
state.borrow_mut().draw(rows as usize, cols as usize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn handle_key() {
|
||||||
|
STATE.with(|state| {
|
||||||
|
state.borrow_mut().handle_key($crate::get_key());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn handle_global_key() {
|
||||||
|
STATE.with(|state| {
|
||||||
|
state.borrow_mut().handle_global_key($crate::get_key());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
94
zellij-tile/src/shim.rs
Normal file
94
zellij-tile/src/shim.rs
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
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 mode_is_persistent: bool,
|
||||||
|
pub keybinds: Vec<(String, String)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use same struct from main crate?
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub enum InputMode {
|
||||||
|
Normal,
|
||||||
|
Command,
|
||||||
|
CommandPersistent,
|
||||||
|
Resize,
|
||||||
|
Pane,
|
||||||
|
Tab,
|
||||||
|
Scroll,
|
||||||
|
Exiting,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for InputMode {
|
||||||
|
fn default() -> InputMode {
|
||||||
|
InputMode::Normal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_key() -> Key {
|
||||||
|
deserialize_from_stdin().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_file(path: &Path) {
|
||||||
|
println!("{}", path.to_string_lossy());
|
||||||
|
unsafe { host_open_file() };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_max_height(max_height: i32) {
|
||||||
|
unsafe { host_set_max_height(max_height) };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_invisible_borders(invisible_borders: bool) {
|
||||||
|
let invisible_borders = if invisible_borders { 1 } else { 0 };
|
||||||
|
unsafe { host_set_invisible_borders(invisible_borders) };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_selectable(selectable: bool) {
|
||||||
|
let selectable = if selectable { 1 } else { 0 };
|
||||||
|
unsafe { host_set_selectable(selectable) };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_help() -> Help {
|
||||||
|
unsafe { host_get_help() };
|
||||||
|
deserialize_from_stdin().unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_from_stdin<T: DeserializeOwned>() -> Option<T> {
|
||||||
|
let mut json = String::new();
|
||||||
|
io::stdin().read_line(&mut json).unwrap();
|
||||||
|
serde_json::from_str(&json).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(wasm_import_module = "mosaic")]
|
||||||
|
extern "C" {
|
||||||
|
fn host_open_file();
|
||||||
|
fn host_set_max_height(max_height: i32);
|
||||||
|
fn host_set_selectable(selectable: i32);
|
||||||
|
fn host_set_invisible_borders(invisible_borders: i32);
|
||||||
|
fn host_get_help();
|
||||||
|
}
|
||||||
0
mosaic/Cargo.lock → zellij/Cargo.lock
generated
0
mosaic/Cargo.lock → zellij/Cargo.lock
generated
21
zellij/LICENSE.md
Normal file
21
zellij/LICENSE.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Mosaic contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
Before Width: | Height: | Size: 3.4 MiB After Width: | Height: | Size: 3.4 MiB |
|
Before Width: | Height: | Size: 213 KiB After Width: | Height: | Size: 213 KiB |
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue