From 8d810dcc51800ea93f394097f1576188de6676cb Mon Sep 17 00:00:00 2001
From: Tom Marble <107828+tmarble@users.noreply.github.com>
Date: Wed, 19 Oct 2022 12:50:00 -0500
Subject: [PATCH] Adds mtxcli commands using the PDDB (#246)
* Adds mtxcli commands using the PDDB
/get key -- shows value of key (from the PDDB)
/set key value -- sets value of key (in the PDDB)
/unset key -- removes key (from the PDDB)
/status -- shows status of the connection
Updates .gitignore for PDDB in hosted mode
---
.gitignore | 4 +-
apps/mtxcli/README.md | 84 ++++++------------
apps/mtxcli/locales/i18n.json | 30 ++++++-
apps/mtxcli/src/cmds.rs | 155 ++++++++++++++++++++++-----------
apps/mtxcli/src/cmds/get.rs | 47 ++++++++++
apps/mtxcli/src/cmds/help.rs | 33 +++++--
apps/mtxcli/src/cmds/set.rs | 57 ++++++++++++
apps/mtxcli/src/cmds/status.rs | 25 ++++++
apps/mtxcli/src/cmds/unset.rs | 45 ++++++++++
9 files changed, 362 insertions(+), 118 deletions(-)
create mode 100644 apps/mtxcli/src/cmds/get.rs
create mode 100644 apps/mtxcli/src/cmds/set.rs
create mode 100644 apps/mtxcli/src/cmds/status.rs
create mode 100644 apps/mtxcli/src/cmds/unset.rs
diff --git a/.gitignore b/.gitignore
index 9ce368011..a55fe4d85 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,6 +37,9 @@ tools/__pycache__
# PDDB backup files
*.pddb
+# PDDB for mtxcli (only for testing in hosted mode)
+/kernel/mtxcli
+
# performance monitoring page table
tools/ct_data/v2p.txt
@@ -72,4 +75,3 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
-
diff --git a/apps/mtxcli/README.md b/apps/mtxcli/README.md
index 7aff57abb..67cbaf276 100644
--- a/apps/mtxcli/README.md
+++ b/apps/mtxcli/README.md
@@ -2,70 +2,40 @@
This is a new Matrix chat application which will be derived from REPL.
-_NOTE_: constant is in gam/src/lib.rs (APP_NAME_MTXCLI) is generated automatically
-with `cargo xtask app-image mtxcli` or `cargo xtask run mtxcli`.
+
-# Inherited from REPL
+## Background
-A simple demo application that provides a bare-bones REPL framework.
-## Copying This Demo to a New App
+This is a simple [Matrix chat](https://matrix.org/) application based on the REPL framework.
-1. Copy this demo application, and rename the relevant structures in its `Cargo.toml` and `main.rs`.
-2. Add it to the Workspace `default-members` and `members` arrays by editing `./Cargo.toml`
-3. Edit the `manifest.json` file as documented in its [README](../README.md)
-4. Build using `cargo xtask app-image you_new_app` to create a flashable Xous image with your app in it.
-## Details
+## Setup
-
+In order to simplify the **mtxcli** application as much as possible the following
+must be setup on a conventional device before using Betrusted (laptop, mobile phone).
-`repl` is a baseline demo application for Xous. It uses a chat-client
-style interface (stacking bubbles of text, with user input right-aligned
-and shell feedback left-aligned) to facilitate interactions.
+* Create a new Matrix user:
+ * https://matrix.org/faq/#how-do-i-get-an-account-and-get-started%3F
+* Find (or create) a new room to join for chatting:
+ * https://doc.matrix.tu-dresden.de/en/rooms/create/
+ * https://spec.matrix.org/latest/#room-structure
+* Join the room
+* Save the configuration in the pddb
+ * `/set user @myname:matrix.org`
+ * `/set password AbigSecret`
+ * `/set room #my-chat-room`
-It implements the basic envisioned structure of a Xous application, namely:
+## Commands
- - Text input comes via the `ime-frontend`
- - Graphical output is rendered via the `gam`
+The following commands are available in **mtxcli**:
+* `/help [cmd]` -- shows help message for all commands (or one cmd if given)
+* `/get key` -- shows value of key (from the PDDB)
+* `/set key value` -- sets value of key (in the PDDB)
+* `/unset key` -- removes key (from the PDDB)
+* `/status` -- shows status of the connection
-[Push Events and Listeners](https://github.com/betrusted-io/xous-core/wiki/Push-Events-and-Listeners) provides an overview of the flow of
-messages between an Xous application and the Xous Services.
+## Chatting
-The one demo command provisioned in the `repl` app plays a tone via
-the `codec` service. This was chosen because it is about one of the most complicated
-and comprehensive things you can do in the `repl` environment, as it requires
-real-time callbacks to fill the audio buffer with new samples. If you have
-specific questions about how the callbacks work, we encourage you to open
-an issue in this repo and ask your question. Your questions will help us
-direct effort toward building the documentation base.
+Any line not starting with a slash ('/') will be sent to the current room.
+New messages from the current room will be displayed.
-To make your own command, copy the `audio.rs` template
-in the `apps/repl/src/cmds/` directory, or use this very basic `echo`
-template:
-
-```Rust
-use crate::{ShellCmdApi, CommonEnv};
-use xous_ipc::String;
-
-#[derive(Debug)]
-pub struct Echo {
-}
-
-impl<'a> ShellCmdApi<'a> for Echo {
- cmd_api!(echo); // inserts boilerplate for command API
-
- fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result