mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
format apps/mtxcli
somehow, this was missed.
This commit is contained in:
parent
0c50581e9c
commit
536ad89010
15 changed files with 413 additions and 454 deletions
|
|
@ -1,15 +1,16 @@
|
||||||
use xous::{MessageEnvelope, Message,StringBuffer};
|
|
||||||
use xous_ipc::String as XousString;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
use core::str::FromStr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write as StdWrite, Error, ErrorKind};
|
use std::io::{Error, ErrorKind, Read, Write as StdWrite};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH}; // to help gen_txn_id
|
use std::time::{SystemTime, UNIX_EPOCH}; // to help gen_txn_id
|
||||||
use core::str::FromStr;
|
|
||||||
|
|
||||||
mod migrations; use migrations::run_migrations;
|
use xous::{Message, MessageEnvelope, StringBuffer};
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
mod migrations;
|
||||||
|
use migrations::run_migrations;
|
||||||
mod url;
|
mod url;
|
||||||
mod web;
|
mod web;
|
||||||
|
|
||||||
|
|
@ -69,12 +70,11 @@ fn get_version(ticktimer: &ticktimer_server::Ticktimer) -> String {
|
||||||
let v: Vec<&str> = xous_version.split('-').collect();
|
let v: Vec<&str> = xous_version.split('-').collect();
|
||||||
if v.len() > 2 {
|
if v.len() > 2 {
|
||||||
let n = v[1].parse::<usize>().expect("could not parse version");
|
let n = v[1].parse::<usize>().expect("could not parse version");
|
||||||
let version = format!("{}-{:04}",v[0], n);
|
let version = format!("{}-{:04}", v[0], n);
|
||||||
log::info!("version={}=", version);
|
log::info!("version={}=", version);
|
||||||
version
|
version
|
||||||
} else {
|
} else {
|
||||||
log::info!("ERROR, couldn't find version from xous_version: {}",
|
log::info!("ERROR, couldn't find version from xous_version: {}", xous_version);
|
||||||
xous_version);
|
|
||||||
xous_version
|
xous_version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,9 +83,17 @@ fn get_version(ticktimer: &ticktimer_server::Ticktimer) -> String {
|
||||||
pub trait ShellCmdApi<'a> {
|
pub trait ShellCmdApi<'a> {
|
||||||
// user implemented:
|
// user implemented:
|
||||||
// called to process the command with the remainder of the string attached
|
// called to process the command with the remainder of the string attached
|
||||||
fn process(&mut self, args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error>;
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error>;
|
||||||
// called to process incoming messages that may have been origniated by the most recently issued command
|
// called to process incoming messages that may have been origniated by the most recently issued command
|
||||||
fn callback(&mut self, msg: &MessageEnvelope, _env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn callback(
|
||||||
|
&mut self,
|
||||||
|
msg: &MessageEnvelope,
|
||||||
|
_env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
log::info!("received unhandled message {:?}", msg);
|
log::info!("received unhandled message {:?}", msg);
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
@ -99,16 +107,8 @@ pub trait ShellCmdApi<'a> {
|
||||||
// the argument to this macro is the command verb
|
// the argument to this macro is the command verb
|
||||||
macro_rules! cmd_api {
|
macro_rules! cmd_api {
|
||||||
($verb:expr) => {
|
($verb:expr) => {
|
||||||
fn verb(&self) -> &'static str {
|
fn verb(&self) -> &'static str { stringify!($verb) }
|
||||||
stringify!($verb)
|
fn matches(&self, verb: &str) -> bool { if verb == stringify!($verb) { true } else { false } }
|
||||||
}
|
|
||||||
fn matches(&self, verb: &str) -> bool {
|
|
||||||
if verb == stringify!($verb) {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ use trng::*;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CommonEnv {
|
pub struct CommonEnv {
|
||||||
ticktimer: ticktimer_server::Ticktimer,
|
ticktimer: ticktimer_server::Ticktimer,
|
||||||
cb_registrations: HashMap::<u32, XousString::<256>>,
|
cb_registrations: HashMap<u32, XousString<256>>,
|
||||||
async_msg_callback_id: u32,
|
async_msg_callback_id: u32,
|
||||||
async_msg_conn: u32,
|
async_msg_conn: u32,
|
||||||
trng: Trng,
|
trng: Trng,
|
||||||
|
|
@ -139,8 +139,7 @@ pub struct CommonEnv {
|
||||||
}
|
}
|
||||||
impl CommonEnv {
|
impl CommonEnv {
|
||||||
pub fn new() -> CommonEnv {
|
pub fn new() -> CommonEnv {
|
||||||
let ticktimer = ticktimer_server::Ticktimer::new()
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
.expect("Couldn't connect to Ticktimer");
|
|
||||||
let cb_registrations = HashMap::new();
|
let cb_registrations = HashMap::new();
|
||||||
let async_msg_callback_id: u32 = 0;
|
let async_msg_callback_id: u32 = 0;
|
||||||
let async_msg_conn: u32 = 0;
|
let async_msg_conn: u32 = 0;
|
||||||
|
|
@ -172,7 +171,7 @@ impl CommonEnv {
|
||||||
common
|
common
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_handler(&mut self, verb: XousString::<256>) -> u32 {
|
pub fn register_handler(&mut self, verb: XousString<256>) -> u32 {
|
||||||
let mut key: u32;
|
let mut key: u32;
|
||||||
loop {
|
loop {
|
||||||
key = self.trng.get_u32().unwrap();
|
key = self.trng.get_u32().unwrap();
|
||||||
|
|
@ -193,31 +192,25 @@ impl CommonEnv {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scalar_async_msg(&self, async_msg_id: usize) {
|
pub fn scalar_async_msg(&self, async_msg_id: usize) {
|
||||||
let msg = Message::new_scalar(self.async_msg_callback_id as usize,
|
let msg = Message::new_scalar(self.async_msg_callback_id as usize, 0, 0, 0, async_msg_id);
|
||||||
0, 0, 0, async_msg_id);
|
|
||||||
xous::send_message(self.async_msg_conn, msg).unwrap();
|
xous::send_message(self.async_msg_conn, msg).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_async_msg(&self, async_msg: &str) {
|
pub fn send_async_msg(&self, async_msg: &str) {
|
||||||
let str_buf = StringBuffer::from_str(async_msg)
|
let str_buf = StringBuffer::from_str(async_msg).expect("unable to create string message");
|
||||||
.expect("unable to create string message");
|
str_buf.send(self.async_msg_conn, self.async_msg_callback_id).expect("unable to send string message");
|
||||||
str_buf.send(self.async_msg_conn, self.async_msg_callback_id)
|
|
||||||
.expect("unable to send string message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_txn_id(&mut self) -> String {
|
pub fn gen_txn_id(&mut self) -> String {
|
||||||
let mut txn_id = self.trng.get_u32()
|
let mut txn_id = self.trng.get_u32().expect("unable to generate random u32");
|
||||||
.expect("unable to generate random u32");
|
|
||||||
log::info!("trng.get_u32() = {}", txn_id);
|
log::info!("trng.get_u32() = {}", txn_id);
|
||||||
txn_id += SystemTime::now().duration_since(UNIX_EPOCH)
|
txn_id += SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards").subsec_nanos();
|
||||||
.expect("Time went backwards").subsec_nanos();
|
|
||||||
txn_id.to_string()
|
txn_id.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, key: &str, value: &str) -> Result<(), Error> {
|
pub fn set(&mut self, key: &str, value: &str) -> Result<(), Error> {
|
||||||
if key.starts_with("__") {
|
if key.starts_with("__") {
|
||||||
Err(Error::new(ErrorKind::PermissionDenied,
|
Err(Error::new(ErrorKind::PermissionDenied, "may not set a variable beginning with __ "))
|
||||||
"may not set a variable beginning with __ "))
|
|
||||||
} else {
|
} else {
|
||||||
log::info!("set '{}' = '{}'", key, value);
|
log::info!("set '{}' = '{}'", key, value);
|
||||||
let mut keypath = PathBuf::new();
|
let mut keypath = PathBuf::new();
|
||||||
|
|
@ -230,16 +223,33 @@ impl CommonEnv {
|
||||||
}
|
}
|
||||||
keypath.push(key);
|
keypath.push(key);
|
||||||
File::create(keypath)?.write_all(value.as_bytes())?;
|
File::create(keypath)?.write_all(value.as_bytes())?;
|
||||||
match key { // special case side effects
|
match key {
|
||||||
FILTER_KEY => { self.filter = value.to_string(); }
|
// special case side effects
|
||||||
PASSWORD_KEY => { self.set_password(); }
|
FILTER_KEY => {
|
||||||
ROOM_ID_KEY => { self.room_id = value.to_string(); }
|
self.filter = value.to_string();
|
||||||
ROOM_KEY => { self.set_room(); }
|
}
|
||||||
SERVER_KEY => { self.server = value.to_string(); }
|
PASSWORD_KEY => {
|
||||||
SINCE_KEY => { self.since = value.to_string(); }
|
self.set_password();
|
||||||
USERNAME_KEY => { self.username = value.to_string(); }
|
}
|
||||||
USER_KEY => { self.set_user(value); }
|
ROOM_ID_KEY => {
|
||||||
_ => { }
|
self.room_id = value.to_string();
|
||||||
|
}
|
||||||
|
ROOM_KEY => {
|
||||||
|
self.set_room();
|
||||||
|
}
|
||||||
|
SERVER_KEY => {
|
||||||
|
self.server = value.to_string();
|
||||||
|
}
|
||||||
|
SINCE_KEY => {
|
||||||
|
self.since = value.to_string();
|
||||||
|
}
|
||||||
|
USERNAME_KEY => {
|
||||||
|
self.username = value.to_string();
|
||||||
|
}
|
||||||
|
USER_KEY => {
|
||||||
|
self.set_user(value);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -248,9 +258,7 @@ impl CommonEnv {
|
||||||
// will log on error (vs. panic)
|
// will log on error (vs. panic)
|
||||||
pub fn set_debug(&mut self, key: &str, value: &str) -> bool {
|
pub fn set_debug(&mut self, key: &str, value: &str) -> bool {
|
||||||
match self.set(key, value) {
|
match self.set(key, value) {
|
||||||
Ok(()) => {
|
Ok(()) => true,
|
||||||
true
|
|
||||||
},
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("error setting key {}: {:?}", key, e);
|
log::info!("error setting key {}: {:?}", key, e);
|
||||||
false
|
false
|
||||||
|
|
@ -261,12 +269,12 @@ impl CommonEnv {
|
||||||
pub fn set_user(&mut self, value: &str) {
|
pub fn set_user(&mut self, value: &str) {
|
||||||
log::info!("# USER_KEY set '{}' = '{}'", USER_KEY, value);
|
log::info!("# USER_KEY set '{}' = '{}'", USER_KEY, value);
|
||||||
let i = match value.find('@') {
|
let i = match value.find('@') {
|
||||||
Some(index) => { index + 1 },
|
Some(index) => index + 1,
|
||||||
None => { 0 },
|
None => 0,
|
||||||
};
|
};
|
||||||
let j = match value.find(':') {
|
let j = match value.find(':') {
|
||||||
Some(index) => { index },
|
Some(index) => index,
|
||||||
None => { value.len() },
|
None => value.len(),
|
||||||
};
|
};
|
||||||
self.username = (&value[i..j]).to_string();
|
self.username = (&value[i..j]).to_string();
|
||||||
if j < value.len() {
|
if j < value.len() {
|
||||||
|
|
@ -296,8 +304,7 @@ impl CommonEnv {
|
||||||
|
|
||||||
pub fn unset(&mut self, key: &str) -> Result<(), Error> {
|
pub fn unset(&mut self, key: &str) -> Result<(), Error> {
|
||||||
if key.starts_with("__") {
|
if key.starts_with("__") {
|
||||||
Err(Error::new(ErrorKind::PermissionDenied,
|
Err(Error::new(ErrorKind::PermissionDenied, "may not unset a variable beginning with __ "))
|
||||||
"may not unset a variable beginning with __ "))
|
|
||||||
} else {
|
} else {
|
||||||
log::info!("unset '{}'", key);
|
log::info!("unset '{}'", key);
|
||||||
let mut keypath = PathBuf::new();
|
let mut keypath = PathBuf::new();
|
||||||
|
|
@ -309,18 +316,32 @@ impl CommonEnv {
|
||||||
std::fs::create_dir_all(&keypath)?;
|
std::fs::create_dir_all(&keypath)?;
|
||||||
}
|
}
|
||||||
keypath.push(key);
|
keypath.push(key);
|
||||||
if std::fs::metadata(&keypath).is_ok() { // keypath exists
|
if std::fs::metadata(&keypath).is_ok() {
|
||||||
|
// keypath exists
|
||||||
log::info!("dict:key = '{}:{}' exists.. deleting it", MTXCLI_DICT, key);
|
log::info!("dict:key = '{}:{}' exists.. deleting it", MTXCLI_DICT, key);
|
||||||
std::fs::remove_file(keypath)?;
|
std::fs::remove_file(keypath)?;
|
||||||
}
|
}
|
||||||
match key { // special case side effects -- update cached values
|
match key {
|
||||||
FILTER_KEY => { self.filter = EMPTY.to_string(); }
|
// special case side effects -- update cached values
|
||||||
ROOM_ID_KEY => { self.room_id = EMPTY.to_string(); }
|
FILTER_KEY => {
|
||||||
SINCE_KEY => { self.since = EMPTY.to_string(); }
|
self.filter = EMPTY.to_string();
|
||||||
SERVER_KEY => { self.server = EMPTY.to_string(); }
|
}
|
||||||
USER_KEY => { self.user = EMPTY.to_string(); }
|
ROOM_ID_KEY => {
|
||||||
USERNAME_KEY => { self.username = EMPTY.to_string(); }
|
self.room_id = EMPTY.to_string();
|
||||||
_ => { }
|
}
|
||||||
|
SINCE_KEY => {
|
||||||
|
self.since = EMPTY.to_string();
|
||||||
|
}
|
||||||
|
SERVER_KEY => {
|
||||||
|
self.server = EMPTY.to_string();
|
||||||
|
}
|
||||||
|
USER_KEY => {
|
||||||
|
self.user = EMPTY.to_string();
|
||||||
|
}
|
||||||
|
USERNAME_KEY => {
|
||||||
|
self.username = EMPTY.to_string();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -329,9 +350,7 @@ impl CommonEnv {
|
||||||
// will log on error (vs. panic)
|
// will log on error (vs. panic)
|
||||||
pub fn unset_debug(&mut self, key: &str) -> bool {
|
pub fn unset_debug(&mut self, key: &str) -> bool {
|
||||||
match self.unset(key) {
|
match self.unset(key) {
|
||||||
Ok(()) => {
|
Ok(()) => true,
|
||||||
true
|
|
||||||
},
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("error unsetting key {}: {:?}", key, e);
|
log::info!("error unsetting key {}: {:?}", key, e);
|
||||||
false
|
false
|
||||||
|
|
@ -352,7 +371,7 @@ impl CommonEnv {
|
||||||
std::fs::create_dir_all(&keypath)?;
|
std::fs::create_dir_all(&keypath)?;
|
||||||
}
|
}
|
||||||
keypath.push(key);
|
keypath.push(key);
|
||||||
if let Ok(mut file)= File::open(keypath) {
|
if let Ok(mut file) = File::open(keypath) {
|
||||||
let mut value = String::new();
|
let mut value = String::new();
|
||||||
file.read_to_string(&mut value)?;
|
file.read_to_string(&mut value)?;
|
||||||
log::info!("get '{}' = '{}'", key, value);
|
log::info!("get '{}' = '{}'", key, value);
|
||||||
|
|
@ -365,12 +384,8 @@ impl CommonEnv {
|
||||||
|
|
||||||
pub fn get_default(&mut self, key: &str, default: &str) -> String {
|
pub fn get_default(&mut self, key: &str, default: &str) -> String {
|
||||||
match self.get(key) {
|
match self.get(key) {
|
||||||
Ok(None) => {
|
Ok(None) => default.to_string(),
|
||||||
default.to_string()
|
Ok(Some(value)) => value.to_string(),
|
||||||
},
|
|
||||||
Ok(Some(value)) => {
|
|
||||||
value.to_string()
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("error getting key {}: {:?}", key, e);
|
log::info!("error getting key {}: {:?}", key, e);
|
||||||
default.to_string()
|
default.to_string()
|
||||||
|
|
@ -379,18 +394,18 @@ impl CommonEnv {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_says(&mut self, text: &str) {
|
pub fn user_says(&mut self, text: &str) {
|
||||||
if ! self.logged_in {
|
if !self.logged_in {
|
||||||
if ! self.login() {
|
if !self.login() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.room_id.len() == 0 {
|
if self.room_id.len() == 0 {
|
||||||
if ! self.get_room_id() {
|
if !self.get_room_id() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.filter.len() == 0 {
|
if self.filter.len() == 0 {
|
||||||
if ! self.get_filter() {
|
if !self.get_filter() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -413,7 +428,7 @@ impl CommonEnv {
|
||||||
self.logged_in = true;
|
self.logged_in = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ! self.logged_in {
|
if !self.logged_in {
|
||||||
if web::get_login_type(&self.server) {
|
if web::get_login_type(&self.server) {
|
||||||
let user = self.get_default(USER_KEY, USER_KEY);
|
let user = self.get_default(USER_KEY, USER_KEY);
|
||||||
if user.len() == 0 {
|
if user.len() == 0 {
|
||||||
|
|
@ -461,18 +476,14 @@ impl CommonEnv {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
let mut room_server = String::new();
|
let mut room_server = String::new();
|
||||||
if ! room.starts_with("#") {
|
if !room.starts_with("#") {
|
||||||
room_server.push_str("#");
|
room_server.push_str("#");
|
||||||
}
|
}
|
||||||
room_server.push_str(&room);
|
room_server.push_str(&room);
|
||||||
room_server.push_str(":");
|
room_server.push_str(":");
|
||||||
let i = match server.find(HTTPS) {
|
let i = match server.find(HTTPS) {
|
||||||
Some(index) => {
|
Some(index) => index + HTTPS.len(),
|
||||||
index + HTTPS.len()
|
None => server.len(),
|
||||||
},
|
|
||||||
None => {
|
|
||||||
server.len()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
if i >= server.len() {
|
if i >= server.len() {
|
||||||
self.scalar_async_msg(SET_SERVER_ID);
|
self.scalar_async_msg(SET_SERVER_ID);
|
||||||
|
|
@ -496,8 +507,7 @@ impl CommonEnv {
|
||||||
if self.filter.len() > 0 {
|
if self.filter.len() > 0 {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
if let Some(new_filter) = web::get_filter(&self.user, &self.server,
|
if let Some(new_filter) = web::get_filter(&self.user, &self.server, &self.room_id, &self.token) {
|
||||||
&self.room_id, &self.token) {
|
|
||||||
self.set_debug(FILTER_KEY, &new_filter);
|
self.set_debug(FILTER_KEY, &new_filter);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -512,17 +522,17 @@ impl CommonEnv {
|
||||||
log::info!("Already listening");
|
log::info!("Already listening");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ! self.logged_in {
|
if !self.logged_in {
|
||||||
log::info!("Not logged in");
|
log::info!("Not logged in");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.room_id.len() == 0 {
|
if self.room_id.len() == 0 {
|
||||||
if ! self.get_room_id() {
|
if !self.get_room_id() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.filter.len() == 0 {
|
if self.filter.len() == 0 {
|
||||||
if ! self.get_filter() {
|
if !self.get_filter() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -540,16 +550,16 @@ impl CommonEnv {
|
||||||
// log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT);
|
// log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT);
|
||||||
let mut response = String::new();
|
let mut response = String::new();
|
||||||
response.push(SENTINEL);
|
response.push(SENTINEL);
|
||||||
if let Some((since, messages)) = web::client_sync(&server, &filter, &since, MTX_LONG_TIMEOUT, &room_id, &token) {
|
if let Some((since, messages)) =
|
||||||
|
web::client_sync(&server, &filter, &since, MTX_LONG_TIMEOUT, &room_id, &token)
|
||||||
|
{
|
||||||
response.push_str(&since);
|
response.push_str(&since);
|
||||||
response.push(SENTINEL);
|
response.push(SENTINEL);
|
||||||
response.push_str(&messages);
|
response.push_str(&messages);
|
||||||
response.push(SENTINEL);
|
response.push(SENTINEL);
|
||||||
}
|
}
|
||||||
let str_buf = StringBuffer::from_str(&response)
|
let str_buf = StringBuffer::from_str(&response).expect("unable to create string message");
|
||||||
.expect("unable to create string message");
|
str_buf.send(async_msg_conn, async_msg_callback_id).expect("unable to send string message");
|
||||||
str_buf.send(async_msg_conn, async_msg_callback_id)
|
|
||||||
.expect("unable to send string message");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -580,18 +590,26 @@ impl CommonEnv {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///// 1. add your module here, and pull its namespace into the local crate
|
///// 1. add your module here, and pull its namespace into the local crate
|
||||||
mod get; use get::*;
|
mod get;
|
||||||
mod heap; use heap::*;
|
use get::*;
|
||||||
mod help; use help::*;
|
mod heap;
|
||||||
mod login; use login::*;
|
use heap::*;
|
||||||
mod logout; use logout::*;
|
mod help;
|
||||||
mod set; use set::*;
|
use help::*;
|
||||||
mod status; use status::*;
|
mod login;
|
||||||
mod unset; use unset::*;
|
use login::*;
|
||||||
|
mod logout;
|
||||||
|
use logout::*;
|
||||||
|
mod set;
|
||||||
|
use set::*;
|
||||||
|
mod status;
|
||||||
|
use status::*;
|
||||||
|
mod unset;
|
||||||
|
use unset::*;
|
||||||
|
|
||||||
pub struct CmdEnv {
|
pub struct CmdEnv {
|
||||||
common_env: CommonEnv,
|
common_env: CommonEnv,
|
||||||
lastverb: XousString::<256>,
|
lastverb: XousString<256>,
|
||||||
///// 2. declare storage for your command here.
|
///// 2. declare storage for your command here.
|
||||||
get_cmd: Get,
|
get_cmd: Get,
|
||||||
heap_cmd: Heap,
|
heap_cmd: Heap,
|
||||||
|
|
@ -621,11 +639,15 @@ impl CmdEnv {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch(&mut self, maybe_cmdline: Option<&mut XousString::<1024>>, maybe_callback: Option<&MessageEnvelope>) -> Result<Option<XousString::<1024>>, xous::Error> {
|
pub fn dispatch(
|
||||||
|
&mut self,
|
||||||
|
maybe_cmdline: Option<&mut XousString<1024>>,
|
||||||
|
maybe_callback: Option<&MessageEnvelope>,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
self.common_env.first_line = true;
|
self.common_env.first_line = true;
|
||||||
|
|
||||||
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
let commands: &mut [&mut dyn ShellCmdApi] = &mut [
|
||||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||||
&mut self.get_cmd,
|
&mut self.get_cmd,
|
||||||
&mut self.heap_cmd,
|
&mut self.heap_cmd,
|
||||||
|
|
@ -653,17 +675,17 @@ impl CmdEnv {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cmdline) = maybe_cmdline {
|
if let Some(cmdline) = maybe_cmdline {
|
||||||
if ! self.common_env.initialized {
|
if !self.common_env.initialized {
|
||||||
log::info!("initializing");
|
log::info!("initializing");
|
||||||
log::info!("WiFi connected: {}", self.common_env.wifi_connected);
|
log::info!("WiFi connected: {}", self.common_env.wifi_connected);
|
||||||
if clock_not_set() {
|
if clock_not_set() {
|
||||||
self.common_env.scalar_async_msg(CLOCK_NOT_SET_ID);
|
self.common_env.scalar_async_msg(CLOCK_NOT_SET_ID);
|
||||||
}
|
}
|
||||||
if ! self.common_env.wifi_connected && ! prev_wifi_connected {
|
if !self.common_env.wifi_connected && !prev_wifi_connected {
|
||||||
self.common_env.scalar_async_msg(WIFI_NOT_CONNECTED_ID);
|
self.common_env.scalar_async_msg(WIFI_NOT_CONNECTED_ID);
|
||||||
}
|
}
|
||||||
let pddb = pddb::PddbMountPoller::new();
|
let pddb = pddb::PddbMountPoller::new();
|
||||||
if ! pddb.is_mounted_nonblocking() {
|
if !pddb.is_mounted_nonblocking() {
|
||||||
self.common_env.scalar_async_msg(PDDB_NOT_MOUNTED_ID);
|
self.common_env.scalar_async_msg(PDDB_NOT_MOUNTED_ID);
|
||||||
} else {
|
} else {
|
||||||
log::info!("PDDB is mounted");
|
log::info!("PDDB is mounted");
|
||||||
|
|
@ -685,16 +707,17 @@ impl CmdEnv {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! self.common_env.listening &&
|
if !self.common_env.listening
|
||||||
self.common_env.logged_in &&
|
&& self.common_env.logged_in
|
||||||
(HOSTED_MODE || self.common_env.wifi_connected) &&
|
&& (HOSTED_MODE || self.common_env.wifi_connected)
|
||||||
self.common_env.initialized {
|
&& self.common_env.initialized
|
||||||
|
{
|
||||||
self.common_env.listen();
|
self.common_env.listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_verb = tokenize(cmdline);
|
let maybe_verb = tokenize(cmdline);
|
||||||
|
|
||||||
let mut cmd_ret: Result<Option<XousString::<1024>>, xous::Error> = Ok(None);
|
let mut cmd_ret: Result<Option<XousString<1024>>, xous::Error> = Ok(None);
|
||||||
if let Some(verb_string) = maybe_verb {
|
if let Some(verb_string) = maybe_verb {
|
||||||
let verb = verb_string.to_str();
|
let verb = verb_string.to_str();
|
||||||
|
|
||||||
|
|
@ -729,7 +752,8 @@ impl CmdEnv {
|
||||||
} else {
|
} else {
|
||||||
cmd_ret
|
cmd_ret
|
||||||
}
|
}
|
||||||
} else { // chat
|
} else {
|
||||||
|
// chat
|
||||||
let mut text = String::from(verb);
|
let mut text = String::from(verb);
|
||||||
text.push_str(" ");
|
text.push_str(" ");
|
||||||
text.push_str(cmdline.to_str());
|
text.push_str(cmdline.to_str());
|
||||||
|
|
@ -742,15 +766,11 @@ impl CmdEnv {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
} else if let Some(callback) = maybe_callback {
|
} else if let Some(callback) = maybe_callback {
|
||||||
let mut cmd_ret: Result<Option<XousString::<1024>>, xous::Error> = Ok(None);
|
let mut cmd_ret: Result<Option<XousString<1024>>, xous::Error> = Ok(None);
|
||||||
// first check and see if we have a callback registration; if not, just map to the last verb
|
// first check and see if we have a callback registration; if not, just map to the last verb
|
||||||
let verb = match self.common_env.cb_registrations.get(&(callback.body.id() as u32)) {
|
let verb = match self.common_env.cb_registrations.get(&(callback.body.id() as u32)) {
|
||||||
Some(verb) => {
|
Some(verb) => verb.to_str(),
|
||||||
verb.to_str()
|
None => self.lastverb.to_str(),
|
||||||
},
|
|
||||||
None => {
|
|
||||||
self.lastverb.to_str()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// now dispatch
|
// now dispatch
|
||||||
let mut verbfound = false;
|
let mut verbfound = false;
|
||||||
|
|
@ -761,22 +781,17 @@ impl CmdEnv {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if verbfound {
|
if verbfound { cmd_ret } else { Ok(None) }
|
||||||
cmd_ret
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// extract the first token, as delimited by spaces
|
/// extract the first token, as delimited by spaces
|
||||||
/// modifies the incoming line by removing the token and returning the remainder
|
/// modifies the incoming line by removing the token and returning the remainder
|
||||||
/// returns the found token
|
/// returns the found token
|
||||||
pub fn tokenize(line: &mut XousString::<1024>) -> Option<XousString::<1024>> {
|
pub fn tokenize(line: &mut XousString<1024>) -> Option<XousString<1024>> {
|
||||||
let mut token = XousString::<1024>::new();
|
let mut token = XousString::<1024>::new();
|
||||||
let mut retline = XousString::<1024>::new();
|
let mut retline = XousString::<1024>::new();
|
||||||
|
|
||||||
|
|
@ -799,15 +814,13 @@ pub fn tokenize(line: &mut XousString::<1024>) -> Option<XousString::<1024>> {
|
||||||
}
|
}
|
||||||
line.clear();
|
line.clear();
|
||||||
write!(line, "{}", retline.as_str().unwrap()).unwrap();
|
write!(line, "{}", retline.as_str().unwrap()).unwrap();
|
||||||
if token.len() > 0 {
|
if token.len() > 0 { Some(token) } else { None }
|
||||||
Some(token)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn heap_usage() -> usize {
|
pub(crate) fn heap_usage() -> usize {
|
||||||
match xous::rsyscall(xous::SysCall::IncreaseHeap(0, xous::MemoryFlags::R)).expect("couldn't get heap size") {
|
match xous::rsyscall(xous::SysCall::IncreaseHeap(0, xous::MemoryFlags::R))
|
||||||
|
.expect("couldn't get heap size")
|
||||||
|
{
|
||||||
xous::Result::MemoryRange(m) => {
|
xous::Result::MemoryRange(m) => {
|
||||||
let usage = m.len();
|
let usage = m.len();
|
||||||
usage
|
usage
|
||||||
|
|
@ -815,15 +828,13 @@ pub(crate) fn heap_usage() -> usize {
|
||||||
_ => {
|
_ => {
|
||||||
log::info!("Couldn't measure heap usage");
|
log::info!("Couldn't measure heap usage");
|
||||||
0
|
0
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn clock_not_set() -> bool {
|
pub fn clock_not_set() -> bool {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let since_the_epoch = now.duration_since(UNIX_EPOCH)
|
let since_the_epoch = now.duration_since(UNIX_EPOCH).expect("Time went backwards");
|
||||||
.expect("Time went backwards");
|
|
||||||
let seconds: u64 = since_the_epoch.as_secs();
|
let seconds: u64 = since_the_epoch.as_secs();
|
||||||
if seconds < DATE_2023 {
|
if seconds < DATE_2023 {
|
||||||
log::info!("clock NOT set, seconds since epoch: {}", seconds);
|
log::info!("clock NOT set, seconds since epoch: {}", seconds);
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
|
||||||
use xous_ipc::String as XousString;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Get {
|
pub struct Get {}
|
||||||
}
|
|
||||||
impl Get {
|
impl Get {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Get {} }
|
||||||
Get {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Get {
|
impl<'a> ShellCmdApi<'a> for Get {
|
||||||
cmd_api!(get);
|
cmd_api!(get);
|
||||||
|
|
||||||
fn process(&mut self, args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
let mut tokens = args.as_str().unwrap().split(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
|
|
@ -25,19 +27,17 @@ impl<'a> ShellCmdApi<'a> for Get {
|
||||||
"" => {
|
"" => {
|
||||||
write!(ret, "{}", t!("mtxcli.get.help", locales::LANG)).unwrap();
|
write!(ret, "{}", t!("mtxcli.get.help", locales::LANG)).unwrap();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => match env.get(key) {
|
||||||
match env.get(key) {
|
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
write!(ret, "{} is UNSET", key).unwrap();
|
write!(ret, "{} is UNSET", key).unwrap();
|
||||||
},
|
}
|
||||||
Ok(Some(value)) => {
|
Ok(Some(value)) => {
|
||||||
write!(ret, "{}", value).unwrap();
|
write!(ret, "{}", value).unwrap();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("error getting key {}: {:?}", key, e);
|
log::error!("error getting key {}: {:?}", key, e);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv,heap_usage};
|
|
||||||
use xous_ipc::String as XousString;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::{heap_usage, CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Heap {
|
pub struct Heap {}
|
||||||
}
|
|
||||||
impl Heap {
|
impl Heap {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Heap {} }
|
||||||
Heap {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Heap {
|
impl<'a> ShellCmdApi<'a> for Heap {
|
||||||
cmd_api!(heap);
|
cmd_api!(heap);
|
||||||
|
|
||||||
fn process(&mut self, _args: XousString::<1024>, _env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
_args: XousString<1024>,
|
||||||
|
_env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
let heap = heap_usage();
|
let heap = heap_usage();
|
||||||
write!(ret, "heap usage: {}", heap).unwrap();
|
write!(ret, "heap usage: {}", heap).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,31 @@
|
||||||
use crate::{ShellCmdApi, CommonEnv};
|
|
||||||
use crate::cmds::*;
|
|
||||||
use xous::{MessageEnvelope, Message, StringBuffer};
|
|
||||||
use xous_ipc::String as XousString;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
use xous::{Message, MessageEnvelope, StringBuffer};
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::cmds::*;
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Help {
|
pub struct Help {}
|
||||||
}
|
|
||||||
impl Help {
|
impl Help {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Help {} }
|
||||||
Help {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Help {
|
impl<'a> ShellCmdApi<'a> for Help {
|
||||||
cmd_api!(help);
|
cmd_api!(help);
|
||||||
|
|
||||||
fn process(&mut self, args: XousString::<1024>, _env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
args: XousString<1024>,
|
||||||
|
_env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
let mut tokens = args.as_str().unwrap().split(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
if let Some(slashcmd) = tokens.next() {
|
if let Some(slashcmd) = tokens.next() {
|
||||||
let cmd = if slashcmd.starts_with("/") {
|
let cmd = if slashcmd.starts_with("/") { &slashcmd[1..] } else { slashcmd };
|
||||||
&slashcmd[1..]
|
|
||||||
} else {
|
|
||||||
slashcmd
|
|
||||||
};
|
|
||||||
match cmd {
|
match cmd {
|
||||||
"get" => {
|
"get" => {
|
||||||
write!(ret, "{}", t!("mtxcli.get.help", locales::LANG)).unwrap();
|
write!(ret, "{}", t!("mtxcli.get.help", locales::LANG)).unwrap();
|
||||||
|
|
@ -65,8 +63,7 @@ impl<'a> ShellCmdApi<'a> for Help {
|
||||||
write!(ret, "{}", t!("mtxcli.unset.help", locales::LANG)).unwrap();
|
write!(ret, "{}", t!("mtxcli.unset.help", locales::LANG)).unwrap();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
write!(ret, "{}: {}",
|
write!(ret, "{}: {}", t!("mtxcli.unknown.help", locales::LANG), cmd).unwrap();
|
||||||
t!("mtxcli.unknown.help", locales::LANG), cmd).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,74 +71,75 @@ impl<'a> ShellCmdApi<'a> for Help {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: the help callback is used to process async messages
|
// NOTE: the help callback is used to process async messages
|
||||||
fn callback(&mut self, msg: &MessageEnvelope, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn callback(
|
||||||
|
&mut self,
|
||||||
|
msg: &MessageEnvelope,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
match &msg.body {
|
match &msg.body {
|
||||||
Message::Scalar(xous::ScalarMessage{id: _, arg1: _, arg2: _,
|
Message::Scalar(xous::ScalarMessage { id: _, arg1: _, arg2: _, arg3: _, arg4: async_msg_id }) => {
|
||||||
arg3: _, arg4: async_msg_id}) => {
|
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
let warning = match *async_msg_id {
|
let warning = match *async_msg_id {
|
||||||
CLOCK_NOT_SET_ID => {
|
CLOCK_NOT_SET_ID => {
|
||||||
t!("mtxcli.clock.warning", locales::LANG)
|
t!("mtxcli.clock.warning", locales::LANG)
|
||||||
},
|
}
|
||||||
PDDB_NOT_MOUNTED_ID => {
|
PDDB_NOT_MOUNTED_ID => {
|
||||||
t!("mtxcli.pddb.warning", locales::LANG)
|
t!("mtxcli.pddb.warning", locales::LANG)
|
||||||
},
|
}
|
||||||
WIFI_NOT_CONNECTED_ID => {
|
WIFI_NOT_CONNECTED_ID => {
|
||||||
t!("mtxcli.wifi.warning", locales::LANG)
|
t!("mtxcli.wifi.warning", locales::LANG)
|
||||||
},
|
}
|
||||||
MTXCLI_INITIALIZED_ID => {
|
MTXCLI_INITIALIZED_ID => {
|
||||||
t!("mtxcli.initialized", locales::LANG)
|
t!("mtxcli.initialized", locales::LANG)
|
||||||
},
|
}
|
||||||
WIFI_CONNECTED_ID => {
|
WIFI_CONNECTED_ID => {
|
||||||
t!("mtxcli.wifi.connected", locales::LANG)
|
t!("mtxcli.wifi.connected", locales::LANG)
|
||||||
},
|
}
|
||||||
SET_USER_ID => {
|
SET_USER_ID => {
|
||||||
t!("mtxcli.please.set.user", locales::LANG)
|
t!("mtxcli.please.set.user", locales::LANG)
|
||||||
},
|
}
|
||||||
SET_PASSWORD_ID => {
|
SET_PASSWORD_ID => {
|
||||||
t!("mtxcli.please.set.password", locales::LANG)
|
t!("mtxcli.please.set.password", locales::LANG)
|
||||||
},
|
}
|
||||||
LOGGED_IN_ID => {
|
LOGGED_IN_ID => {
|
||||||
t!("mtxcli.logged.in", locales::LANG)
|
t!("mtxcli.logged.in", locales::LANG)
|
||||||
},
|
}
|
||||||
LOGIN_FAILED_ID => {
|
LOGIN_FAILED_ID => {
|
||||||
t!("mtxcli.login.failed", locales::LANG)
|
t!("mtxcli.login.failed", locales::LANG)
|
||||||
},
|
}
|
||||||
SET_ROOM_ID => {
|
SET_ROOM_ID => {
|
||||||
t!("mtxcli.please.set.room", locales::LANG)
|
t!("mtxcli.please.set.room", locales::LANG)
|
||||||
},
|
}
|
||||||
ROOMID_FAILED_ID => {
|
ROOMID_FAILED_ID => {
|
||||||
t!("mtxcli.roomid.failed", locales::LANG)
|
t!("mtxcli.roomid.failed", locales::LANG)
|
||||||
},
|
}
|
||||||
FILTER_FAILED_ID => {
|
FILTER_FAILED_ID => {
|
||||||
t!("mtxcli.filter.failed", locales::LANG)
|
t!("mtxcli.filter.failed", locales::LANG)
|
||||||
},
|
}
|
||||||
SET_SERVER_ID => {
|
SET_SERVER_ID => {
|
||||||
t!("mtxcli.please.set.server", locales::LANG)
|
t!("mtxcli.please.set.server", locales::LANG)
|
||||||
},
|
}
|
||||||
LOGGING_IN_ID => {
|
LOGGING_IN_ID => {
|
||||||
t!("mtxcli.logging.in", locales::LANG)
|
t!("mtxcli.logging.in", locales::LANG)
|
||||||
},
|
}
|
||||||
LOGGED_OUT_ID => {
|
LOGGED_OUT_ID => {
|
||||||
t!("mtxcli.logged.out", locales::LANG)
|
t!("mtxcli.logged.out", locales::LANG)
|
||||||
},
|
}
|
||||||
NOT_CONNECTED_ID => {
|
NOT_CONNECTED_ID => {
|
||||||
t!("mtxcli.not.connected", locales::LANG)
|
t!("mtxcli.not.connected", locales::LANG)
|
||||||
},
|
}
|
||||||
FAILED_TO_SEND_ID => {
|
FAILED_TO_SEND_ID => {
|
||||||
t!("mtxcli.send.failed", locales::LANG)
|
t!("mtxcli.send.failed", locales::LANG)
|
||||||
},
|
}
|
||||||
PLEASE_LOGIN_ID => {
|
PLEASE_LOGIN_ID => {
|
||||||
t!("mtxcli.please.login", locales::LANG)
|
t!("mtxcli.please.login", locales::LANG)
|
||||||
},
|
}
|
||||||
_ => {
|
_ => "unknown async_msg_id",
|
||||||
"unknown async_msg_id"
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
write!(ret, "{}", warning).unwrap();
|
write!(ret, "{}", warning).unwrap();
|
||||||
log::warn!("{}", warning);
|
log::warn!("{}", warning);
|
||||||
return Ok(Some(ret));
|
return Ok(Some(ret));
|
||||||
},
|
}
|
||||||
Message::Move(mm) => {
|
Message::Move(mm) => {
|
||||||
let str_buf = unsafe { StringBuffer::from_memory_message(mm) };
|
let str_buf = unsafe { StringBuffer::from_memory_message(mm) };
|
||||||
let msg = str_buf.to_str();
|
let msg = str_buf.to_str();
|
||||||
|
|
@ -166,7 +164,7 @@ impl<'a> ShellCmdApi<'a> for Help {
|
||||||
write!(ret, "{}", msg).unwrap();
|
write!(ret, "{}", msg).unwrap();
|
||||||
return Ok(Some(ret));
|
return Ok(Some(ret));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("received unknown callback type: {:?}", msg)
|
log::error!("received unknown callback type: {:?}", msg)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
|
||||||
use xous_ipc::String as XousString;
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Login {
|
pub struct Login {}
|
||||||
}
|
|
||||||
impl Login {
|
impl Login {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Login {} }
|
||||||
Login {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Login {
|
impl<'a> ShellCmdApi<'a> for Login {
|
||||||
cmd_api!(login);
|
cmd_api!(login);
|
||||||
|
|
||||||
fn process(&mut self, _args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
_args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
env.login();
|
env.login();
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
|
||||||
use xous_ipc::String as XousString;
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Logout {
|
pub struct Logout {}
|
||||||
}
|
|
||||||
impl Logout {
|
impl Logout {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Logout {} }
|
||||||
Logout {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Logout {
|
impl<'a> ShellCmdApi<'a> for Logout {
|
||||||
cmd_api!(logout);
|
cmd_api!(logout);
|
||||||
|
|
||||||
fn process(&mut self, _args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
_args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
env.logout();
|
env.logout();
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,13 @@
|
||||||
//! Runs migrations up to the current version
|
//! Runs migrations up to the current version
|
||||||
|
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use crate::cmds::{CommonEnv,VERSION_KEY};
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
|
||||||
mod v0_9_11_0120; use v0_9_11_0120::*;
|
use crate::cmds::{CommonEnv, VERSION_KEY};
|
||||||
|
|
||||||
|
mod v0_9_11_0120;
|
||||||
|
use v0_9_11_0120::*;
|
||||||
|
|
||||||
const DEFAULT_VERSION: &str = "0";
|
const DEFAULT_VERSION: &str = "0";
|
||||||
|
|
||||||
|
|
@ -23,18 +26,11 @@ pub trait MigrationApi<'a> {
|
||||||
// the argument to this macro is the command verb
|
// the argument to this macro is the command verb
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! migration_api {
|
macro_rules! migration_api {
|
||||||
($version:expr) => { // NOTE the expr will have literal quotes
|
($version:expr) => {
|
||||||
fn version(&self) -> &'static str {
|
// NOTE the expr will have literal quotes
|
||||||
$version
|
fn version(&self) -> &'static str { $version }
|
||||||
}
|
|
||||||
|
|
||||||
fn applies(&self, version: &str) -> bool {
|
fn applies(&self, version: &str) -> bool { if version < self.version() { true } else { false } }
|
||||||
if version < self.version() {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,8 +39,7 @@ pub fn run_migrations(common: &mut CommonEnv) {
|
||||||
let version = common.get_default(VERSION_KEY, DEFAULT_VERSION);
|
let version = common.get_default(VERSION_KEY, DEFAULT_VERSION);
|
||||||
if version.ne(&common.version) {
|
if version.ne(&common.version) {
|
||||||
let running_migrations = t!("mtxcli.running.migrations", locales::LANG);
|
let running_migrations = t!("mtxcli.running.migrations", locales::LANG);
|
||||||
let msg = format!("{} {} .. {}",
|
let msg = format!("{} {} .. {}", running_migrations, version, common.version);
|
||||||
running_migrations, version, common.version);
|
|
||||||
log::info!("{}", msg);
|
log::info!("{}", msg);
|
||||||
common.send_async_msg(&msg);
|
common.send_async_msg(&msg);
|
||||||
let mut migrations: Vec<Box<dyn MigrationApi>> = Vec::new();
|
let mut migrations: Vec<Box<dyn MigrationApi>> = Vec::new();
|
||||||
|
|
@ -54,23 +49,19 @@ pub fn run_migrations(common: &mut CommonEnv) {
|
||||||
match migration.process(common) {
|
match migration.process(common) {
|
||||||
Ok(boolean) => {
|
Ok(boolean) => {
|
||||||
let migration_completed = t!("mtxcli.migration.completed", locales::LANG);
|
let migration_completed = t!("mtxcli.migration.completed", locales::LANG);
|
||||||
let msg = format!("{}: {}: {}",
|
let msg = format!("{}: {}: {}", migration_completed, migration.version(), boolean);
|
||||||
migration_completed, migration.version(), boolean);
|
|
||||||
common.send_async_msg(&msg);
|
common.send_async_msg(&msg);
|
||||||
if boolean {
|
if boolean {
|
||||||
common.set(VERSION_KEY, migration.version())
|
common.set(VERSION_KEY, migration.version()).expect("cannot set _version");
|
||||||
.expect("cannot set _version");
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("error running migration: {}: {:?}",
|
log::error!("error running migration: {}: {:?}", migration.version(), e);
|
||||||
migration.version(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
common.set(VERSION_KEY, &common.version.clone())
|
common.set(VERSION_KEY, &common.version.clone()).expect("cannot set _version");
|
||||||
.expect("cannot set _version");
|
|
||||||
let migrations_complete = t!("mtxcli.migrations.complete", locales::LANG);
|
let migrations_complete = t!("mtxcli.migrations.complete", locales::LANG);
|
||||||
log::info!("{}", migrations_complete);
|
log::info!("{}", migrations_complete);
|
||||||
common.send_async_msg(&migrations_complete);
|
common.send_async_msg(&migrations_complete);
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
|
||||||
use crate::cmds::{CommonEnv,FILTER_KEY};
|
|
||||||
use crate::cmds::migrations::MigrationApi;
|
use crate::cmds::migrations::MigrationApi;
|
||||||
|
use crate::cmds::{CommonEnv, FILTER_KEY};
|
||||||
use crate::migration_api;
|
use crate::migration_api;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct V0_9_11_0120 {
|
pub struct V0_9_11_0120 {}
|
||||||
}
|
|
||||||
impl V0_9_11_0120 {
|
impl V0_9_11_0120 {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { V0_9_11_0120 {} }
|
||||||
V0_9_11_0120 {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MigrationApi<'a> for V0_9_11_0120 {
|
impl<'a> MigrationApi<'a> for V0_9_11_0120 {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
|
||||||
use xous_ipc::String as XousString;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Set {
|
pub struct Set {}
|
||||||
}
|
|
||||||
impl Set {
|
impl Set {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Set {} }
|
||||||
Set {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Set {
|
impl<'a> ShellCmdApi<'a> for Set {
|
||||||
cmd_api!(set);
|
cmd_api!(set);
|
||||||
|
|
||||||
fn process(&mut self, args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
let mut tokens = args.as_str().unwrap().split(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
|
|
@ -31,16 +33,14 @@ impl<'a> ShellCmdApi<'a> for Set {
|
||||||
"" => {
|
"" => {
|
||||||
write!(ret, "{}", t!("mtxcli.set.help", locales::LANG)).unwrap();
|
write!(ret, "{}", t!("mtxcli.set.help", locales::LANG)).unwrap();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => match env.set(key, value) {
|
||||||
match env.set(key, value) {
|
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
write!(ret, "set {}", key).unwrap();
|
write!(ret, "set {}", key).unwrap();
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("error setting key {}: {:?}", key, e);
|
log::error!("error setting key {}: {:?}", key, e);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Instead of an error -- set to the empty string
|
// Instead of an error -- set to the empty string
|
||||||
|
|
@ -49,7 +49,7 @@ impl<'a> ShellCmdApi<'a> for Set {
|
||||||
match env.set(key, "") {
|
match env.set(key, "") {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
write!(ret, "set {} EMPTY", key).unwrap();
|
write!(ret, "set {} EMPTY", key).unwrap();
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("error setting key {}: {:?}", key, e);
|
log::error!("error setting key {}: {:?}", key, e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
|
||||||
use crate::cmds::*;
|
|
||||||
use xous_ipc::String as XousString;
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::cmds::*;
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Status {
|
pub struct Status {}
|
||||||
}
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Status {} }
|
||||||
Status {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Status {
|
impl<'a> ShellCmdApi<'a> for Status {
|
||||||
cmd_api!(status);
|
cmd_api!(status);
|
||||||
|
|
||||||
fn process(&mut self, _args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
_args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
if env.logged_in {
|
if env.logged_in {
|
||||||
env.scalar_async_msg(LOGGED_IN_ID);
|
env.scalar_async_msg(LOGGED_IN_ID);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
|
||||||
use xous_ipc::String as XousString;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Unset {
|
pub struct Unset {}
|
||||||
}
|
|
||||||
impl Unset {
|
impl Unset {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Unset {} }
|
||||||
Unset {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Unset {
|
impl<'a> ShellCmdApi<'a> for Unset {
|
||||||
cmd_api!(unset);
|
cmd_api!(unset);
|
||||||
|
|
||||||
fn process(&mut self, args: XousString::<1024>, env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
fn process(
|
||||||
|
&mut self,
|
||||||
|
args: XousString<1024>,
|
||||||
|
env: &mut CommonEnv,
|
||||||
|
) -> Result<Option<XousString<1024>>, xous::Error> {
|
||||||
let mut ret = XousString::<1024>::new();
|
let mut ret = XousString::<1024>::new();
|
||||||
let mut tokens = args.as_str().unwrap().split(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
|
|
@ -29,7 +31,7 @@ impl<'a> ShellCmdApi<'a> for Unset {
|
||||||
match env.unset(key) {
|
match env.unset(key) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
write!(ret, "unset {}", key).unwrap();
|
write!(ret, "unset {}", key).unwrap();
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// NOTE: we current expect this error
|
// NOTE: we current expect this error
|
||||||
// when unsetting a non existant key
|
// when unsetting a non existant key
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,15 @@
|
||||||
//! URL encoding and decoding
|
//! URL encoding and decoding
|
||||||
|
|
||||||
/// Encoding to use for conversions
|
/// Encoding to use for conversions
|
||||||
pub const RFC3986: &percent_encoding::AsciiSet = &percent_encoding::NON_ALPHANUMERIC
|
pub const RFC3986: &percent_encoding::AsciiSet =
|
||||||
.remove(b'.')
|
&percent_encoding::NON_ALPHANUMERIC.remove(b'.').remove(b'-').remove(b'_').remove(b'~');
|
||||||
.remove(b'-')
|
|
||||||
.remove(b'_')
|
|
||||||
.remove(b'~');
|
|
||||||
|
|
||||||
/// URL encode string
|
/// URL encode string
|
||||||
pub fn encode(v: &str) -> String {
|
pub fn encode(v: &str) -> String { percent_encoding::utf8_percent_encode(v, RFC3986).to_string() }
|
||||||
percent_encoding::utf8_percent_encode(v, RFC3986).to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// URL decode string
|
/// URL decode string
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn decode(v: &str) -> String {
|
pub fn decode(v: &str) -> String {
|
||||||
let decoded = percent_encoding::percent_decode_str(v)
|
let decoded = percent_encoding::percent_decode_str(v).decode_utf8().expect("unable to decode");
|
||||||
.decode_utf8()
|
|
||||||
.expect("unable to decode");
|
|
||||||
decoded.to_string()
|
decoded.to_string()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use serde::{Serialize,Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ureq::serde_json::{Value, Map};
|
|
||||||
use ureq;
|
use ureq;
|
||||||
|
use ureq::serde_json::{Map, Value};
|
||||||
|
|
||||||
use crate::cmds::url;
|
use crate::cmds::url;
|
||||||
|
|
||||||
|
|
@ -14,21 +14,19 @@ const MTX_ID_USER: &str = "m.id.user";
|
||||||
|
|
||||||
pub fn get_username(user: &str) -> String {
|
pub fn get_username(user: &str) -> String {
|
||||||
let i = match user.find('@') {
|
let i = match user.find('@') {
|
||||||
Some(index) => { index + 1 },
|
Some(index) => index + 1,
|
||||||
None => { 0 },
|
None => 0,
|
||||||
};
|
};
|
||||||
let j = match user.find(':') {
|
let j = match user.find(':') {
|
||||||
Some(index) => { index },
|
Some(index) => index,
|
||||||
None => { user.len() },
|
None => user.len(),
|
||||||
};
|
};
|
||||||
(&user[i..j]).to_string()
|
(&user[i..j]).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize<T: ?Sized + Serialize>(object: &T) -> Option<String> {
|
fn serialize<T: ?Sized + Serialize>(object: &T) -> Option<String> {
|
||||||
match ureq::serde_json::to_string(&object) {
|
match ureq::serde_json::to_string(&object) {
|
||||||
Ok(value) => {
|
Ok(value) => Some(value),
|
||||||
Some(value)
|
|
||||||
},
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("ERROR in serialize: {:?}", e);
|
log::info!("ERROR in serialize: {:?}", e);
|
||||||
None
|
None
|
||||||
|
|
@ -36,7 +34,7 @@ fn serialize<T: ?Sized + Serialize>(object: &T) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_response(maybe_response: Result<ureq::Response,ureq::Error>) -> Option<Value> {
|
pub fn handle_response(maybe_response: Result<ureq::Response, ureq::Error>) -> Option<Value> {
|
||||||
match maybe_response {
|
match maybe_response {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if let Ok(body) = response.into_json() {
|
if let Ok(body) = response.into_json() {
|
||||||
|
|
@ -45,7 +43,7 @@ pub fn handle_response(maybe_response: Result<ureq::Response,ureq::Error>) -> Op
|
||||||
log::info!("Error: could not convert response into JSON");
|
log::info!("Error: could not convert response into JSON");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(ureq::Error::Status(code, response)) => {
|
Err(ureq::Error::Status(code, response)) => {
|
||||||
/* the server returned an unexpected status
|
/* the server returned an unexpected status
|
||||||
code (such as 400, 500 etc) */
|
code (such as 400, 500 etc) */
|
||||||
|
|
@ -61,42 +59,29 @@ pub fn handle_response(maybe_response: Result<ureq::Response,ureq::Error>) -> Op
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_json(url: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn get_json(url: &str) -> Result<ureq::Response, ureq::Error> {
|
||||||
ureq::get(&url)
|
ureq::get(&url).set(ACCEPT, ACCEPT_JSON).call()
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
|
||||||
.call()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_json_auth(url: &str, token:&str) -> Result<ureq::Response, ureq::Error> {
|
pub fn get_json_auth(url: &str, token: &str) -> Result<ureq::Response, ureq::Error> {
|
||||||
let mut authorization = String::from(BEARER);
|
let mut authorization = String::from(BEARER);
|
||||||
authorization.push_str(token);
|
authorization.push_str(token);
|
||||||
ureq::get(&url)
|
ureq::get(&url).set(ACCEPT, ACCEPT_JSON).set(AUTHORIZATION, &authorization).call()
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
|
||||||
.set(AUTHORIZATION, &authorization)
|
|
||||||
.call()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post_string(url: &str, request_body: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn post_string(url: &str, request_body: &str) -> Result<ureq::Response, ureq::Error> {
|
||||||
ureq::post(&url)
|
ureq::post(&url).set(ACCEPT, ACCEPT_JSON).send_string(request_body)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
|
||||||
.send_string(request_body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post_string_auth(url: &str, request_body: &str, token: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn post_string_auth(url: &str, request_body: &str, token: &str) -> Result<ureq::Response, ureq::Error> {
|
||||||
let mut authorization = String::from(BEARER);
|
let mut authorization = String::from(BEARER);
|
||||||
authorization.push_str(token);
|
authorization.push_str(token);
|
||||||
ureq::post(&url)
|
ureq::post(&url).set(ACCEPT, ACCEPT_JSON).set(AUTHORIZATION, &authorization).send_string(request_body)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
|
||||||
.set(AUTHORIZATION, &authorization)
|
|
||||||
.send_string(request_body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_string_auth(url: &str, request_body: &str, token: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn put_string_auth(url: &str, request_body: &str, token: &str) -> Result<ureq::Response, ureq::Error> {
|
||||||
let mut authorization = String::from(BEARER);
|
let mut authorization = String::from(BEARER);
|
||||||
authorization.push_str(token);
|
authorization.push_str(token);
|
||||||
ureq::put(&url)
|
ureq::put(&url).set(ACCEPT, ACCEPT_JSON).set(AUTHORIZATION, &authorization).send_string(request_body)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
|
||||||
.set(AUTHORIZATION, &authorization)
|
|
||||||
.send_string(request_body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
|
@ -157,15 +142,8 @@ struct AuthRequest {
|
||||||
|
|
||||||
impl AuthRequest {
|
impl AuthRequest {
|
||||||
pub fn new(user: &str, password: &str) -> Self {
|
pub fn new(user: &str, password: &str) -> Self {
|
||||||
let identifier = AuthIdentifier {
|
let identifier = AuthIdentifier { type_: MTX_ID_USER.to_string(), user: user.to_string() };
|
||||||
type_: MTX_ID_USER.to_string(),
|
AuthRequest { type_: MTX_LOGIN_PASSWORD.to_string(), identifier, password: password.to_string() }
|
||||||
user: user.to_string()
|
|
||||||
};
|
|
||||||
AuthRequest {
|
|
||||||
type_: MTX_LOGIN_PASSWORD.to_string(),
|
|
||||||
identifier: identifier,
|
|
||||||
password: password.to_string()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,10 +199,7 @@ impl EventFilter {
|
||||||
pub fn new(limit: i32) -> Self {
|
pub fn new(limit: i32) -> Self {
|
||||||
let mut not_types: Vec<String> = Vec::new();
|
let mut not_types: Vec<String> = Vec::new();
|
||||||
not_types.push("*".to_string());
|
not_types.push("*".to_string());
|
||||||
EventFilter {
|
EventFilter { limit, not_types }
|
||||||
limit,
|
|
||||||
not_types,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,11 +216,7 @@ impl RoomEventFilter {
|
||||||
types.push(type_0.to_string());
|
types.push(type_0.to_string());
|
||||||
let mut rooms: Vec<String> = Vec::new();
|
let mut rooms: Vec<String> = Vec::new();
|
||||||
rooms.push(room_id.to_string());
|
rooms.push(room_id.to_string());
|
||||||
RoomEventFilter {
|
RoomEventFilter { limit, types, rooms }
|
||||||
limit,
|
|
||||||
types,
|
|
||||||
rooms,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,13 +237,7 @@ impl RoomFilter {
|
||||||
rooms.push(room_id.to_string());
|
rooms.push(room_id.to_string());
|
||||||
let state = EventFilter::new(0);
|
let state = EventFilter::new(0);
|
||||||
let timeline = RoomEventFilter::new(10, room_id, "m.room.message");
|
let timeline = RoomEventFilter::new(10, room_id, "m.room.message");
|
||||||
RoomFilter {
|
RoomFilter { account_data, ephemeral, rooms, state, timeline }
|
||||||
account_data,
|
|
||||||
ephemeral,
|
|
||||||
rooms,
|
|
||||||
state,
|
|
||||||
timeline,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,17 +258,11 @@ impl FilterRequest {
|
||||||
event_fields.push("content.body".to_string());
|
event_fields.push("content.body".to_string());
|
||||||
let presence = EventFilter::new(0);
|
let presence = EventFilter::new(0);
|
||||||
let room = RoomFilter::new(room_id);
|
let room = RoomFilter::new(room_id);
|
||||||
FilterRequest {
|
FilterRequest { account_data, event_fields, presence, room }
|
||||||
account_data,
|
|
||||||
event_fields,
|
|
||||||
presence,
|
|
||||||
room,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_filter(user: &str, server: &str, room_id: &str, token: &str)
|
pub fn get_filter(user: &str, server: &str, room_id: &str, token: &str) -> Option<String> {
|
||||||
-> Option<String> {
|
|
||||||
let user_encoded = url::encode(user);
|
let user_encoded = url::encode(user);
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/v3/user/");
|
url.push_str("/_matrix/client/v3/user/");
|
||||||
|
|
@ -358,7 +317,6 @@ fn get_messages(body: Map<String, Value>, room_id: &str) -> String {
|
||||||
if let Some(Value::Object(content)) = event.get("content") {
|
if let Some(Value::Object(content)) = event.get("content") {
|
||||||
if let Some(Value::String(body)) = content.get("body") {
|
if let Some(Value::String(body)) = content.get("body") {
|
||||||
messages.push_str(body);
|
messages.push_str(body);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
messages.push_str("....");
|
messages.push_str("....");
|
||||||
}
|
}
|
||||||
|
|
@ -376,8 +334,14 @@ fn get_messages(body: Map<String, Value>, room_id: &str) -> String {
|
||||||
messages
|
messages
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn client_sync(server: &str, filter: &str, since: &str, timeout: i32,
|
pub fn client_sync(
|
||||||
room_id: &str, token: &str) -> Option<(String, String)> {
|
server: &str,
|
||||||
|
filter: &str,
|
||||||
|
since: &str,
|
||||||
|
timeout: i32,
|
||||||
|
room_id: &str,
|
||||||
|
token: &str,
|
||||||
|
) -> Option<(String, String)> {
|
||||||
log::info!("heap usage: {}", crate::cmds::heap_usage());
|
log::info!("heap usage: {}", crate::cmds::heap_usage());
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/r0/sync?filter=");
|
url.push_str("/_matrix/client/r0/sync?filter=");
|
||||||
|
|
@ -416,10 +380,7 @@ impl MessageRequest {
|
||||||
pub fn new(text: &str) -> Self {
|
pub fn new(text: &str) -> Self {
|
||||||
let msgtype = "m.text".to_string();
|
let msgtype = "m.text".to_string();
|
||||||
let body = text.to_string();
|
let body = text.to_string();
|
||||||
MessageRequest {
|
MessageRequest { msgtype, body }
|
||||||
msgtype,
|
|
||||||
body,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,9 @@ pub(crate) enum MtxcliOp {
|
||||||
// This name should be (1) unique (2) under 64 characters long and (3) ideally descriptive.
|
// This name should be (1) unique (2) under 64 characters long and (3) ideally descriptive.
|
||||||
pub(crate) const SERVER_NAME_MTXCLI: &str = "_Matrix cli_";
|
pub(crate) const SERVER_NAME_MTXCLI: &str = "_Matrix cli_";
|
||||||
|
|
||||||
fn main () -> ! {
|
fn main() -> ! {
|
||||||
let stack_size = 1024 * 1024;
|
let stack_size = 1024 * 1024;
|
||||||
std::thread::Builder::new()
|
std::thread::Builder::new().stack_size(stack_size).spawn(wrapped_main).unwrap().join().unwrap()
|
||||||
.stack_size(stack_size)
|
|
||||||
.spawn(wrapped_main)
|
|
||||||
.unwrap()
|
|
||||||
.join()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrapped_main() -> ! {
|
fn wrapped_main() -> ! {
|
||||||
|
|
@ -40,11 +35,8 @@ fn wrapped_main() -> ! {
|
||||||
|
|
||||||
const HEAP_LARGER_LIMIT: usize = 2048 * 1024;
|
const HEAP_LARGER_LIMIT: usize = 2048 * 1024;
|
||||||
let new_limit = HEAP_LARGER_LIMIT;
|
let new_limit = HEAP_LARGER_LIMIT;
|
||||||
let result = xous::rsyscall(xous::SysCall::AdjustProcessLimit(
|
let result =
|
||||||
xous::Limits::HeapMaximum as usize,
|
xous::rsyscall(xous::SysCall::AdjustProcessLimit(xous::Limits::HeapMaximum as usize, 0, new_limit));
|
||||||
0,
|
|
||||||
new_limit,
|
|
||||||
));
|
|
||||||
|
|
||||||
if let Ok(xous::Result::Scalar2(1, current_limit)) = result {
|
if let Ok(xous::Result::Scalar2(1, current_limit)) = result {
|
||||||
xous::rsyscall(xous::SysCall::AdjustProcessLimit(
|
xous::rsyscall(xous::SysCall::AdjustProcessLimit(
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
use super::*;
|
|
||||||
use gam::UxRegistration;
|
|
||||||
use graphics_server::{Gid, Point, Rectangle, TextBounds, TextView, DrawStyle, PixelColor};
|
|
||||||
use graphics_server::api::GlyphStyle;
|
|
||||||
use xous::MessageEnvelope;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
use gam::UxRegistration;
|
||||||
|
use graphics_server::api::GlyphStyle;
|
||||||
|
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView};
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
use xous::MessageEnvelope;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct History {
|
struct History {
|
||||||
|
|
@ -22,7 +24,7 @@ pub(crate) struct Mtxcli {
|
||||||
msg: Option<MessageEnvelope>,
|
msg: Option<MessageEnvelope>,
|
||||||
|
|
||||||
// record our input history
|
// record our input history
|
||||||
history: Vec::<History>,
|
history: Vec<History>,
|
||||||
history_len: usize,
|
history_len: usize,
|
||||||
content: Gid,
|
content: Gid,
|
||||||
gam: gam::Gam,
|
gam: gam::Gam,
|
||||||
|
|
@ -38,25 +40,31 @@ pub(crate) struct Mtxcli {
|
||||||
// command environment
|
// command environment
|
||||||
env: CmdEnv,
|
env: CmdEnv,
|
||||||
}
|
}
|
||||||
impl Mtxcli{
|
impl Mtxcli {
|
||||||
pub(crate) fn new(xns: &xous_names::XousNames, sid: xous::SID) -> Self {
|
pub(crate) fn new(xns: &xous_names::XousNames, sid: xous::SID) -> Self {
|
||||||
let gam = gam::Gam::new(xns).expect("can't connect to GAM");
|
let gam = gam::Gam::new(xns).expect("can't connect to GAM");
|
||||||
|
|
||||||
let token = gam.register_ux(UxRegistration {
|
let token = gam
|
||||||
|
.register_ux(UxRegistration {
|
||||||
app_name: xous_ipc::String::<128>::from_str(gam::APP_NAME_MTXCLI),
|
app_name: xous_ipc::String::<128>::from_str(gam::APP_NAME_MTXCLI),
|
||||||
ux_type: gam::UxType::Chat,
|
ux_type: gam::UxType::Chat,
|
||||||
predictor: Some(xous_ipc::String::<64>::from_str(ime_plugin_shell::SERVER_NAME_IME_PLUGIN_SHELL)),
|
predictor: Some(xous_ipc::String::<64>::from_str(
|
||||||
listener: sid.to_array(), // note disclosure of our SID to the GAM -- the secret is now shared with the GAM!
|
ime_plugin_shell::SERVER_NAME_IME_PLUGIN_SHELL,
|
||||||
|
)),
|
||||||
|
listener: sid.to_array(), /* note disclosure of our SID to the GAM -- the secret is now
|
||||||
|
* shared with the GAM! */
|
||||||
redraw_id: MtxcliOp::Redraw.to_u32().unwrap(),
|
redraw_id: MtxcliOp::Redraw.to_u32().unwrap(),
|
||||||
gotinput_id: Some(MtxcliOp::Line.to_u32().unwrap()),
|
gotinput_id: Some(MtxcliOp::Line.to_u32().unwrap()),
|
||||||
audioframe_id: None,
|
audioframe_id: None,
|
||||||
rawkeys_id: None,
|
rawkeys_id: None,
|
||||||
focuschange_id: Some(MtxcliOp::ChangeFocus.to_u32().unwrap()),
|
focuschange_id: Some(MtxcliOp::ChangeFocus.to_u32().unwrap()),
|
||||||
}).expect("couldn't register Ux context for mtxcli");
|
})
|
||||||
|
.expect("couldn't register Ux context for mtxcli");
|
||||||
|
|
||||||
let content = gam.request_content_canvas(token.unwrap()).expect("couldn't get content canvas");
|
let content = gam.request_content_canvas(token.unwrap()).expect("couldn't get content canvas");
|
||||||
let screensize = gam.get_canvas_bounds(content).expect("couldn't get dimensions of content canvas");
|
let screensize = gam.get_canvas_bounds(content).expect("couldn't get dimensions of content canvas");
|
||||||
let history: Vec::<History> = vec![History{text: String::from(t!("mtxcli.greeting", locales::LANG)), is_input: false}];
|
let history: Vec<History> =
|
||||||
|
vec![History { text: String::from(t!("mtxcli.greeting", locales::LANG)), is_input: false }];
|
||||||
let env = CmdEnv::new();
|
let env = CmdEnv::new();
|
||||||
Mtxcli {
|
Mtxcli {
|
||||||
input: None,
|
input: None,
|
||||||
|
|
@ -82,9 +90,7 @@ impl Mtxcli{
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn msg(&mut self, message: MessageEnvelope) {
|
pub(crate) fn msg(&mut self, message: MessageEnvelope) { self.msg = Some(message); }
|
||||||
self.msg = Some(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn circular_push(&mut self, item: History) {
|
fn circular_push(&mut self, item: History) {
|
||||||
if self.history.len() >= self.history_len {
|
if self.history.len() >= self.history_len {
|
||||||
|
|
@ -97,10 +103,7 @@ impl Mtxcli{
|
||||||
pub(crate) fn update(&mut self, was_callback: bool) -> Result<(), xous::Error> {
|
pub(crate) fn update(&mut self, was_callback: bool) -> Result<(), xous::Error> {
|
||||||
// if we had an input string, do something
|
// if we had an input string, do something
|
||||||
if let Some(local) = &self.input {
|
if let Some(local) = &self.input {
|
||||||
let input_history = History {
|
let input_history = History { text: local.to_string(), is_input: true };
|
||||||
text: local.to_string(),
|
|
||||||
is_input: true,
|
|
||||||
};
|
|
||||||
self.circular_push(input_history);
|
self.circular_push(input_history);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,28 +112,29 @@ impl Mtxcli{
|
||||||
// side effect our commands
|
// side effect our commands
|
||||||
|
|
||||||
// redraw UI once upon accepting all input
|
// redraw UI once upon accepting all input
|
||||||
if !was_callback { // don't need to redraw on a callback, save some cycles
|
if !was_callback {
|
||||||
|
// don't need to redraw on a callback, save some cycles
|
||||||
self.redraw().expect("can't redraw");
|
self.redraw().expect("can't redraw");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dirty = true;
|
let mut dirty = true;
|
||||||
// take the input and pass it on to the various command parsers, and attach result
|
// take the input and pass it on to the various command parsers, and attach result
|
||||||
if let Some(local) = &self.input {
|
if let Some(local) = &self.input {
|
||||||
if let Some(res) = self.env.dispatch(Some(&mut xous_ipc::String::<1024>::from_str(&local)), None).expect("command dispatch failed") {
|
if let Some(res) = self
|
||||||
let output_history = History {
|
.env
|
||||||
text: String::from(res.as_str().unwrap_or("UTF-8 Error")),
|
.dispatch(Some(&mut xous_ipc::String::<1024>::from_str(&local)), None)
|
||||||
is_input: false
|
.expect("command dispatch failed")
|
||||||
};
|
{
|
||||||
|
let output_history =
|
||||||
|
History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false };
|
||||||
self.circular_push(output_history);
|
self.circular_push(output_history);
|
||||||
} else {
|
} else {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
} else if let Some(msg) = &self.msg {
|
} else if let Some(msg) = &self.msg {
|
||||||
if let Some(res) = self.env.dispatch(None, Some(msg)).expect("callback failed") {
|
if let Some(res) = self.env.dispatch(None, Some(msg)).expect("callback failed") {
|
||||||
let output_history = History {
|
let output_history =
|
||||||
text: String::from(res.as_str().unwrap_or("UTF-8 Error")),
|
History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false };
|
||||||
is_input: false
|
|
||||||
};
|
|
||||||
self.circular_push(output_history);
|
self.circular_push(output_history);
|
||||||
} else {
|
} else {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
|
@ -149,15 +153,18 @@ impl Mtxcli{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_area(&self) {
|
fn clear_area(&self) {
|
||||||
self.gam.draw_rectangle(self.content,
|
self.gam
|
||||||
Rectangle::new_with_style(Point::new(0, 0), self.screensize,
|
.draw_rectangle(
|
||||||
DrawStyle {
|
self.content,
|
||||||
fill_color: Some(PixelColor::Light),
|
Rectangle::new_with_style(
|
||||||
stroke_color: None,
|
Point::new(0, 0),
|
||||||
stroke_width: 0
|
self.screensize,
|
||||||
}
|
DrawStyle { fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0 },
|
||||||
)).expect("can't clear content area");
|
),
|
||||||
|
)
|
||||||
|
.expect("can't clear content area");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn redraw(&mut self) -> Result<(), xous::Error> {
|
pub(crate) fn redraw(&mut self) -> Result<(), xous::Error> {
|
||||||
self.clear_area();
|
self.clear_area();
|
||||||
|
|
||||||
|
|
@ -167,17 +174,19 @@ impl Mtxcli{
|
||||||
// iterator returns from oldest to newest
|
// iterator returns from oldest to newest
|
||||||
// .rev() iterator is from newest to oldest
|
// .rev() iterator is from newest to oldest
|
||||||
for h in self.history.iter().rev() {
|
for h in self.history.iter().rev() {
|
||||||
let mut bubble_tv =
|
let mut bubble_tv = if h.is_input {
|
||||||
if h.is_input {
|
TextView::new(
|
||||||
TextView::new(self.content,
|
self.content,
|
||||||
TextBounds::GrowableFromBr(
|
TextBounds::GrowableFromBr(
|
||||||
Point::new(self.screensize.x - self.margin.x, bubble_baseline),
|
Point::new(self.screensize.x - self.margin.x, bubble_baseline),
|
||||||
self.bubble_width))
|
self.bubble_width,
|
||||||
|
),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
TextView::new(self.content,
|
TextView::new(
|
||||||
TextBounds::GrowableFromBl(
|
self.content,
|
||||||
Point::new(self.margin.x, bubble_baseline),
|
TextBounds::GrowableFromBl(Point::new(self.margin.x, bubble_baseline), self.bubble_width),
|
||||||
self.bubble_width))
|
)
|
||||||
};
|
};
|
||||||
if h.is_input {
|
if h.is_input {
|
||||||
bubble_tv.border_width = 1;
|
bubble_tv.border_width = 1;
|
||||||
|
|
@ -189,13 +198,14 @@ impl Mtxcli{
|
||||||
bubble_tv.rounded_border = Some(self.bubble_radius);
|
bubble_tv.rounded_border = Some(self.bubble_radius);
|
||||||
bubble_tv.style = GlyphStyle::Regular;
|
bubble_tv.style = GlyphStyle::Regular;
|
||||||
bubble_tv.margin = self.bubble_margin;
|
bubble_tv.margin = self.bubble_margin;
|
||||||
bubble_tv.ellipsis = false; bubble_tv.insertion = None;
|
bubble_tv.ellipsis = false;
|
||||||
|
bubble_tv.insertion = None;
|
||||||
write!(bubble_tv.text, "{}", h.text.as_str()).expect("couldn't write history text to TextView");
|
write!(bubble_tv.text, "{}", h.text.as_str()).expect("couldn't write history text to TextView");
|
||||||
self.gam.post_textview(&mut bubble_tv).expect("couldn't render bubble textview");
|
self.gam.post_textview(&mut bubble_tv).expect("couldn't render bubble textview");
|
||||||
|
|
||||||
if let Some(bounds) = bubble_tv.bounds_computed {
|
if let Some(bounds) = bubble_tv.bounds_computed {
|
||||||
// we only subtract 1x of the margin because the bounds were computed from a "bottom right" that already counted
|
// we only subtract 1x of the margin because the bounds were computed from a "bottom right"
|
||||||
// the margin once.
|
// that already counted the margin once.
|
||||||
bubble_baseline -= (bounds.br.y - bounds.tl.y) + self.bubble_space + self.bubble_margin.y;
|
bubble_baseline -= (bounds.br.y - bounds.tl.y) + self.bubble_space + self.bubble_margin.y;
|
||||||
if bubble_baseline <= 0 {
|
if bubble_baseline <= 0 {
|
||||||
// don't draw history that overflows the top of the screen
|
// don't draw history that overflows the top of the screen
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue