mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
WIP #287: Adds /heap command to mtxcli
Signed-off-by: Tom Marble <tmarble@info9.net>
This commit is contained in:
parent
afd1570bbc
commit
b4566bc22e
4 changed files with 67 additions and 15 deletions
|
|
@ -20,6 +20,13 @@
|
||||||
"ja": "シンプルなMTXCLIデモへようこそ",
|
"ja": "シンプルなMTXCLIデモへようこそ",
|
||||||
"zh": "简单的 mtxcli 演示活动"
|
"zh": "简单的 mtxcli 演示活动"
|
||||||
},
|
},
|
||||||
|
"mtxcli.heap.help": {
|
||||||
|
"en": "/heap",
|
||||||
|
"en-tts": "heap",
|
||||||
|
"fr": "/heap",
|
||||||
|
"ja": "/heap",
|
||||||
|
"zh": "/heap"
|
||||||
|
},
|
||||||
"mtxcli.help.help": {
|
"mtxcli.help.help": {
|
||||||
"en": "/help [cmd]",
|
"en": "/help [cmd]",
|
||||||
"en-tts": "help [cmd]",
|
"en-tts": "help [cmd]",
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ const SERVER_KEY: &str = "server";
|
||||||
const TOKEN_KEY: &str = "_token";
|
const TOKEN_KEY: &str = "_token";
|
||||||
const USER_KEY: &str = "user";
|
const USER_KEY: &str = "user";
|
||||||
const USERNAME_KEY: &str = "username";
|
const USERNAME_KEY: &str = "username";
|
||||||
|
const VERSION_KEY: &str = "_version";
|
||||||
|
const CURRENT_VERSION_KEY: &str = "__version";
|
||||||
|
|
||||||
const HTTPS: &str = "https://";
|
const HTTPS: &str = "https://";
|
||||||
const SERVER_MATRIX: &str = "https://matrix.org";
|
const SERVER_MATRIX: &str = "https://matrix.org";
|
||||||
|
|
@ -203,23 +205,33 @@ impl CommonEnv {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn xous_version(&self) -> String {
|
||||||
|
// Currently breaks in hosted mode:
|
||||||
|
// self.ticktimer.get_version()
|
||||||
|
"v0.9.11".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get(&mut self, key: &str) -> Result<Option<String>, Error> {
|
pub fn get(&mut self, key: &str) -> Result<Option<String>, Error> {
|
||||||
let mut keypath = PathBuf::new();
|
if key.eq(CURRENT_VERSION_KEY) {
|
||||||
keypath.push(MTXCLI_DICT);
|
Ok(Some(self.xous_version()))
|
||||||
if std::fs::metadata(&keypath).is_ok() { // keypath exists
|
|
||||||
log::info!("dict '{}' exists", MTXCLI_DICT);
|
|
||||||
} else {
|
} else {
|
||||||
log::info!("dict '{}' does NOT exist.. creating it", MTXCLI_DICT);
|
let mut keypath = PathBuf::new();
|
||||||
std::fs::create_dir_all(&keypath)?;
|
keypath.push(MTXCLI_DICT);
|
||||||
}
|
if std::fs::metadata(&keypath).is_ok() { // keypath exists
|
||||||
keypath.push(key);
|
log::info!("dict '{}' exists", MTXCLI_DICT);
|
||||||
if let Ok(mut file)= File::open(keypath) {
|
} else {
|
||||||
let mut value = String::new();
|
log::info!("dict '{}' does NOT exist.. creating it", MTXCLI_DICT);
|
||||||
file.read_to_string(&mut value)?;
|
std::fs::create_dir_all(&keypath)?;
|
||||||
// log::info!("get '{}' = '{}'", key, value);
|
}
|
||||||
Ok(Some(value))
|
keypath.push(key);
|
||||||
} else {
|
if let Ok(mut file)= File::open(keypath) {
|
||||||
Ok(None)
|
let mut value = String::new();
|
||||||
|
file.read_to_string(&mut value)?;
|
||||||
|
// log::info!("get '{}' = '{}'", key, value);
|
||||||
|
Ok(Some(value))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,6 +434,7 @@ 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; use get::*;
|
||||||
|
mod heap; use heap::*;
|
||||||
mod help; use help::*;
|
mod help; use help::*;
|
||||||
mod login; use login::*;
|
mod login; use login::*;
|
||||||
mod logout; use logout::*;
|
mod logout; use logout::*;
|
||||||
|
|
@ -434,6 +447,7 @@ pub struct CmdEnv {
|
||||||
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,
|
||||||
help_cmd: Help,
|
help_cmd: Help,
|
||||||
login_cmd: Login,
|
login_cmd: Login,
|
||||||
logout_cmd: Logout,
|
logout_cmd: Logout,
|
||||||
|
|
@ -471,6 +485,7 @@ impl CmdEnv {
|
||||||
lastverb: XousString::<256>::new(),
|
lastverb: XousString::<256>::new(),
|
||||||
///// 3. initialize your storage, by calling new()
|
///// 3. initialize your storage, by calling new()
|
||||||
get_cmd: Get::new(&xns),
|
get_cmd: Get::new(&xns),
|
||||||
|
heap_cmd: Heap::new(&xns),
|
||||||
help_cmd: Help::new(&xns),
|
help_cmd: Help::new(&xns),
|
||||||
login_cmd: Login::new(&xns),
|
login_cmd: Login::new(&xns),
|
||||||
logout_cmd: Logout::new(&xns),
|
logout_cmd: Logout::new(&xns),
|
||||||
|
|
@ -487,6 +502,7 @@ impl CmdEnv {
|
||||||
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.help_cmd,
|
&mut self.help_cmd,
|
||||||
&mut self.login_cmd,
|
&mut self.login_cmd,
|
||||||
&mut self.logout_cmd,
|
&mut self.logout_cmd,
|
||||||
|
|
|
||||||
25
apps/mtxcli/src/cmds/heap.rs
Normal file
25
apps/mtxcli/src/cmds/heap.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
use crate::{ShellCmdApi,CommonEnv,heap_usage};
|
||||||
|
use xous_ipc::String as XousString;
|
||||||
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Heap {
|
||||||
|
}
|
||||||
|
impl Heap {
|
||||||
|
pub fn new(_xns: &xous_names::XousNames) -> Self {
|
||||||
|
Heap {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> ShellCmdApi<'a> for Heap {
|
||||||
|
cmd_api!(heap);
|
||||||
|
|
||||||
|
fn process(&mut self, _args: XousString::<1024>, _env: &mut CommonEnv) -> Result<Option<XousString::<1024>>, xous::Error> {
|
||||||
|
let mut ret = XousString::<1024>::new();
|
||||||
|
let heap = heap_usage();
|
||||||
|
write!(ret, "heap usage: {}", heap).unwrap();
|
||||||
|
log::info!("heap usage: {}", heap);
|
||||||
|
Ok(Some(ret))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,9 @@ impl<'a> ShellCmdApi<'a> for Help {
|
||||||
"get" => {
|
"get" => {
|
||||||
write!(ret, "{}", t!("mtxcli.get.help", xous::LANG)).unwrap();
|
write!(ret, "{}", t!("mtxcli.get.help", xous::LANG)).unwrap();
|
||||||
}
|
}
|
||||||
|
"heap" => {
|
||||||
|
write!(ret, "{}", t!("mtxcli.heap.help", xous::LANG)).unwrap();
|
||||||
|
}
|
||||||
"help" => {
|
"help" => {
|
||||||
write!(ret, "{}", t!("mtxcli.help.help", xous::LANG)).unwrap();
|
write!(ret, "{}", t!("mtxcli.help.help", xous::LANG)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +54,7 @@ impl<'a> ShellCmdApi<'a> for Help {
|
||||||
"" => {
|
"" => {
|
||||||
write!(ret, "{}\n", t!("mtxcli.help.overview", xous::LANG)).unwrap();
|
write!(ret, "{}\n", t!("mtxcli.help.overview", xous::LANG)).unwrap();
|
||||||
write!(ret, "{}\n", t!("mtxcli.get.help", xous::LANG)).unwrap();
|
write!(ret, "{}\n", t!("mtxcli.get.help", xous::LANG)).unwrap();
|
||||||
|
write!(ret, "{}\n", t!("mtxcli.heap.help", xous::LANG)).unwrap();
|
||||||
write!(ret, "{}\n", t!("mtxcli.help.help", xous::LANG)).unwrap();
|
write!(ret, "{}\n", t!("mtxcli.help.help", xous::LANG)).unwrap();
|
||||||
write!(ret, "{}\n", t!("mtxcli.login.help", xous::LANG)).unwrap();
|
write!(ret, "{}\n", t!("mtxcli.login.help", xous::LANG)).unwrap();
|
||||||
write!(ret, "{}\n", t!("mtxcli.logout.help", xous::LANG)).unwrap();
|
write!(ret, "{}\n", t!("mtxcli.logout.help", xous::LANG)).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue