Add get_help function

This commit is contained in:
Brooks J Rady 2021-01-11 21:37:47 +00:00
parent 1275a9e73a
commit 680a986cf6
2 changed files with 15 additions and 5 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mosaic-tile" name = "mosaic-tile"
version = "0.3.1" version = "0.4.0"
authors = ["Brooks J Rady <b.j.rady@gmail.com>"] authors = ["Brooks J Rady <b.j.rady@gmail.com>"]
edition = "2018" edition = "2018"
description = "A small client-side library for writing mosaic plugins (tiles)" description = "A small client-side library for writing mosaic plugins (tiles)"

View File

@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{io, path::Path}; use std::{io, path::Path};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
@ -24,9 +24,7 @@ pub enum Key {
} }
pub fn get_key() -> Key { pub fn get_key() -> Key {
let mut json = String::new(); deserialize_from_stdin().unwrap()
io::stdin().read_line(&mut json).unwrap();
serde_json::from_str(&json).unwrap()
} }
pub fn open_file(path: &Path) { pub fn open_file(path: &Path) {
@ -39,8 +37,20 @@ pub fn set_selectable(selectable: bool) {
unsafe { host_set_selectable(selectable) }; 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")] #[link(wasm_import_module = "mosaic")]
extern "C" { extern "C" {
fn host_open_file(); fn host_open_file();
fn host_set_selectable(selectable: i32); fn host_set_selectable(selectable: i32);
fn host_get_help();
} }