From 5a7207676843c3b4fbe3289acd2c623808fa0ea9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 19 Jun 2022 19:04:25 +0800 Subject: [PATCH] add dynamic search as text is typed --- apps/vault/locales/i18n.json | 4 ++-- apps/vault/src/main.rs | 22 ++++++++++++++++++---- apps/vault/src/ux/framework.rs | 9 +++------ apps/vault/src/ux/icontray.rs | 14 +++++++------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/apps/vault/locales/i18n.json b/apps/vault/locales/i18n.json index 5ad5503eb..ee766f124 100644 --- a/apps/vault/locales/i18n.json +++ b/apps/vault/locales/i18n.json @@ -162,10 +162,10 @@ "en-tts": "Delete item" }, "vault.menu_change_font": { - "en": "Change font", + "en": "Change list font", "ja": "フォントを変更する", "zh": "更改字体", - "en-tts": "Change font" + "en-tts": "🔇" }, "vault.menu_close": { "en": "Close submenu", diff --git a/apps/vault/src/main.rs b/apps/vault/src/main.rs index d334d8f28..7105cfd65 100644 --- a/apps/vault/src/main.rs +++ b/apps/vault/src/main.rs @@ -71,6 +71,8 @@ UI concept: pub(crate) enum VaultOp { /// a line of text has arrived Line = 0, // make sure we occupy opcodes with discriminants < 1000, as the rest are used for callbacks + /// incremental line of text + IncrementalLine, /// redraw our UI Redraw, /// change focus @@ -152,21 +154,21 @@ fn main() -> ! { } }); + let conn = xous::connect(sid).unwrap(); // spawn the icontray handler let _ = thread::spawn({ move || { - icontray_server(); + icontray_server(conn); } }); - let conn = xous::connect(sid).unwrap(); let menu_sid = xous::create_server().unwrap(); let _menu_mgr = submenu::create_submenu(conn, menu_sid); let xns = xous_names::XousNames::new().unwrap(); // TODO: add a UX loop that indicates we're waiting for a PDDB mount before moving forward let mut vaultux = VaultUx::new(&xns, sid); - vaultux.gen_fake_data(0); // THIS IS FOR TESTING ONLY replace with a call that does something "more proper" + vaultux.set_mode(VaultMode::Fido); let mut update_vaultux = true; let mut was_callback = false; let mut allow_redraw = false; @@ -175,6 +177,17 @@ fn main() -> ! { let msg = xous::receive_message(sid).unwrap(); log::debug!("got message {:?}", msg); match FromPrimitive::from_usize(msg.body.id()) { + Some(VaultOp::IncrementalLine) => { + let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + let s = buffer.as_flat::, _>().unwrap(); + log::info!("Incremental input: {}", s.as_str()); + vaultux.input(s.as_str()).expect("Vault couldn't accept input string"); + update_vaultux = true; // set a flag, instead of calling here, so message can drop and calling server is released + was_callback = false; + send_message(conn, + Message::new_scalar(VaultOp::Redraw.to_usize().unwrap(), 0, 0, 0, 0) + ).ok(); + } Some(VaultOp::Line) => { let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let s = buffer.as_flat::, _>().unwrap(); @@ -205,7 +218,8 @@ fn main() -> ! { vaultux.nav(NavDir::PageDown); } _ => { - vaultux.input(s.as_str()).expect("Vault couldn't accept input string"); + // someone hit enter. The string is the whole search query, but what we care is that someone hit enter. + vaultux.raise_menu(); } } update_vaultux = true; // set a flag, instead of calling here, so message can drop and calling server is released diff --git a/apps/vault/src/ux/framework.rs b/apps/vault/src/ux/framework.rs index b64080da7..a35154fef 100644 --- a/apps/vault/src/ux/framework.rs +++ b/apps/vault/src/ux/framework.rs @@ -45,9 +45,6 @@ pub(crate) enum NavDir { #[allow(dead_code)] pub(crate) struct VaultUx { - // optional structures that indicate new input to the VaultUx loop per iteration - // an input string - input: Option, // messages not handled by the main loop are routed here msg: Option, @@ -174,7 +171,6 @@ impl VaultUx { let items_per_screen = available_height / item_height; VaultUx { - input: None, msg: None, content, gam, @@ -251,8 +247,9 @@ impl VaultUx { } /// accept a new input string pub(crate) fn input(&mut self, line: &str) -> Result<(), xous::Error> { - self.input = Some(String::from(line)); - + log::info!("filtering by {}", line); + self.filter(line); + log::info!("filtered item count: {}", self.filtered_list.len()); Ok(()) } diff --git a/apps/vault/src/ux/icontray.rs b/apps/vault/src/ux/icontray.rs index 5c89067f5..55e50ff11 100644 --- a/apps/vault/src/ux/icontray.rs +++ b/apps/vault/src/ux/icontray.rs @@ -1,7 +1,7 @@ use ime_plugin_api::*; -use xous_ipc::{String, Buffer}; -use num_traits::FromPrimitive; +use xous_ipc::Buffer; +use num_traits::*; use xous::msg_scalar_unpack; pub(crate) const SERVER_NAME_ICONTRAY: &'static str = "_vault icon tray plugin_"; @@ -13,7 +13,7 @@ const ICONS: [&'static str; 4] = [ "\t🧾🛠", ]; -pub(crate) fn icontray_server() { +pub(crate) fn icontray_server(conn_to_main: xous::CID) { let xns = xous_names::XousNames::new().unwrap(); // one connection only, should be the GAM // however, because the predictor is connected only on demand -- we leave this as open-ended, which @@ -64,10 +64,10 @@ pub(crate) fn icontray_server() { } }), Some(Opcode::Input) => { - let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let s = buffer.as_flat::, _>().unwrap(); - // input is dynamically updated here - log::info!("Input: {}", s.as_str()); + msg.forward( + conn_to_main, + crate::VaultOp::IncrementalLine.to_usize().unwrap() + ).expect("couldn't forward input"); } Some(Opcode::Picked) => { // this is ignored