add dynamic search as text is typed

This commit is contained in:
bunnie 2022-06-19 19:04:25 +08:00
parent 72e6be8679
commit 5a72076768
4 changed files with 30 additions and 19 deletions

View file

@ -162,10 +162,10 @@
"en-tts": "Delete item" "en-tts": "Delete item"
}, },
"vault.menu_change_font": { "vault.menu_change_font": {
"en": "Change font", "en": "Change list font",
"ja": "フォントを変更する", "ja": "フォントを変更する",
"zh": "更改字体", "zh": "更改字体",
"en-tts": "Change font" "en-tts": "🔇"
}, },
"vault.menu_close": { "vault.menu_close": {
"en": "Close submenu", "en": "Close submenu",

View file

@ -71,6 +71,8 @@ UI concept:
pub(crate) enum VaultOp { pub(crate) enum VaultOp {
/// a line of text has arrived /// a line of text has arrived
Line = 0, // make sure we occupy opcodes with discriminants < 1000, as the rest are used for callbacks 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 our UI
Redraw, Redraw,
/// change focus /// change focus
@ -152,21 +154,21 @@ fn main() -> ! {
} }
}); });
let conn = xous::connect(sid).unwrap();
// spawn the icontray handler // spawn the icontray handler
let _ = thread::spawn({ let _ = thread::spawn({
move || { move || {
icontray_server(); icontray_server(conn);
} }
}); });
let conn = xous::connect(sid).unwrap();
let menu_sid = xous::create_server().unwrap(); let menu_sid = xous::create_server().unwrap();
let _menu_mgr = submenu::create_submenu(conn, menu_sid); let _menu_mgr = submenu::create_submenu(conn, menu_sid);
let xns = xous_names::XousNames::new().unwrap(); let xns = xous_names::XousNames::new().unwrap();
// TODO: add a UX loop that indicates we're waiting for a PDDB mount before moving forward // TODO: add a UX loop that indicates we're waiting for a PDDB mount before moving forward
let mut vaultux = VaultUx::new(&xns, sid); 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 update_vaultux = true;
let mut was_callback = false; let mut was_callback = false;
let mut allow_redraw = false; let mut allow_redraw = false;
@ -175,6 +177,17 @@ fn main() -> ! {
let msg = xous::receive_message(sid).unwrap(); let msg = xous::receive_message(sid).unwrap();
log::debug!("got message {:?}", msg); log::debug!("got message {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) { 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::<xous_ipc::String<4000>, _>().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) => { Some(VaultOp::Line) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let s = buffer.as_flat::<xous_ipc::String<4000>, _>().unwrap(); let s = buffer.as_flat::<xous_ipc::String<4000>, _>().unwrap();
@ -205,7 +218,8 @@ fn main() -> ! {
vaultux.nav(NavDir::PageDown); 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 update_vaultux = true; // set a flag, instead of calling here, so message can drop and calling server is released

View file

@ -45,9 +45,6 @@ pub(crate) enum NavDir {
#[allow(dead_code)] #[allow(dead_code)]
pub(crate) struct VaultUx { pub(crate) struct VaultUx {
// optional structures that indicate new input to the VaultUx loop per iteration
// an input string
input: Option<String>,
// messages not handled by the main loop are routed here // messages not handled by the main loop are routed here
msg: Option<MessageEnvelope>, msg: Option<MessageEnvelope>,
@ -174,7 +171,6 @@ impl VaultUx {
let items_per_screen = available_height / item_height; let items_per_screen = available_height / item_height;
VaultUx { VaultUx {
input: None,
msg: None, msg: None,
content, content,
gam, gam,
@ -251,8 +247,9 @@ impl VaultUx {
} }
/// accept a new input string /// accept a new input string
pub(crate) fn input(&mut self, line: &str) -> Result<(), xous::Error> { 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(()) Ok(())
} }

View file

@ -1,7 +1,7 @@
use ime_plugin_api::*; use ime_plugin_api::*;
use xous_ipc::{String, Buffer}; use xous_ipc::Buffer;
use num_traits::FromPrimitive; use num_traits::*;
use xous::msg_scalar_unpack; use xous::msg_scalar_unpack;
pub(crate) const SERVER_NAME_ICONTRAY: &'static str = "_vault icon tray plugin_"; pub(crate) const SERVER_NAME_ICONTRAY: &'static str = "_vault icon tray plugin_";
@ -13,7 +13,7 @@ const ICONS: [&'static str; 4] = [
"\t🧾🛠", "\t🧾🛠",
]; ];
pub(crate) fn icontray_server() { pub(crate) fn icontray_server(conn_to_main: xous::CID) {
let xns = xous_names::XousNames::new().unwrap(); let xns = xous_names::XousNames::new().unwrap();
// one connection only, should be the GAM // one connection only, should be the GAM
// however, because the predictor is connected only on demand -- we leave this as open-ended, which // 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) => { Some(Opcode::Input) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; msg.forward(
let s = buffer.as_flat::<String::<4000>, _>().unwrap(); conn_to_main,
// input is dynamically updated here crate::VaultOp::IncrementalLine.to_usize().unwrap()
log::info!("Input: {}", s.as_str()); ).expect("couldn't forward input");
} }
Some(Opcode::Picked) => { Some(Opcode::Picked) => {
// this is ignored // this is ignored