zellij/zellij-tile/src/shim.rs
categorille c74e2ef273
feat(input): new keybindings and persistent mode as default (#181)
* added some comments in the input module

* InputHandler now has InputState instead of separate InputMode and permanent bool

* keybinds are now associated with a Vec<Action> instead of a single Action

* removing "persistent" modes alltogether to reimplement the feature, help bar broken

* locked command mode by default, fixes #161, help bar still broken

* status bar fixed, still a few improvements/bugs to go

* better shortcut help bar contents

* fixed last bits and i think we are good

* modified tests according to new controls, not working

* Revert "modified tests according to new controls, not working"

This reverts commit f2d9421ff0169feb83dbd9b246e59b9244cafc16.

* basic.rs tests now pass, not the rest

* close_pane.rs tests pass, but very slowly?

* compatibility.rs tests pass, very slowly as well

* {layout, {move_focus_*}}.rs all working mildly slowly

* {resize_*}.rs should all work but very slowly and funky, see PR comments

* {tabs,toggle_fullscreen}.rs pass. Test performance issue yet to be fixed

* tests now work, with a hack :| ready for merge

* rustfmt + deleted references to InputState and mode persistency
2021-02-12 14:55:22 +01:00

92 lines
2 KiB
Rust

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 keybinds: Vec<(String, String)>,
}
// TODO: use same struct from main crate?
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum InputMode {
Normal,
Command,
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 = "zellij")]
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();
}