aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-01-11 21:37:47 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-01-11 21:37:47 +0000
commit680a986cf66ad14a4a0d147ed34b8aa3d1ffaacd (patch)
tree32ae0bbe52fa954f21d1d563e21b0d3ad028fb78
parentNo more glob imports in the register_tile! macro (diff)
downloadsl0ppij-680a986cf66ad14a4a0d147ed34b8aa3d1ffaacd.tar.gz
sl0ppij-680a986cf66ad14a4a0d147ed34b8aa3d1ffaacd.tar.xz
sl0ppij-680a986cf66ad14a4a0d147ed34b8aa3d1ffaacd.zip
Add get_help function
-rw-r--r--Cargo.toml2
-rw-r--r--src/shim.rs18
2 files changed, 15 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index dd7a6636..b9fbe0a5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mosaic-tile"
-version = "0.3.1"
+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)"
diff --git a/src/shim.rs b/src/shim.rs
index 60bdfbd5..6fa8b0e6 100644
--- a/src/shim.rs
+++ b/src/shim.rs
@@ -1,4 +1,4 @@
-use serde::{Deserialize, Serialize};
+use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{io, path::Path};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
@@ -24,9 +24,7 @@ pub enum Key {
}
pub fn get_key() -> Key {
- let mut json = String::new();
- io::stdin().read_line(&mut json).unwrap();
- serde_json::from_str(&json).unwrap()
+ deserialize_from_stdin().unwrap()
}
pub fn open_file(path: &Path) {
@@ -39,8 +37,20 @@ pub fn set_selectable(selectable: bool) {
unsafe { host_set_selectable(selectable) };
}
+pub fn get_help() -> Vec<String> {
+ 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_selectable(selectable: i32);
+ fn host_get_help();
}