tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
This commit is contained in:
parent
0af97e144a
commit
0131803f9c
4 changed files with 1058 additions and 16 deletions
625
src/tui.rs
625
src/tui.rs
|
|
@ -1,5 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use std::io::{self, IsTerminal};
|
||||
use std::io::{self, IsTerminal, Write};
|
||||
use std::sync::{Arc, mpsc};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
|
|
@ -7,6 +7,7 @@ use ratatui::crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, Ke
|
|||
use ratatui::layout::{Constraint, Layout, Rect};
|
||||
use ratatui::style::{Color, Modifier, Style};
|
||||
use ratatui::symbols::border;
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragraph, Wrap};
|
||||
use ratatui::{DefaultTerminal, Frame};
|
||||
use zeroize::{Zeroize, Zeroizing};
|
||||
|
|
@ -547,6 +548,7 @@ OnionWire keys\n\
|
|||
F5 selected friend's profile (/who)\n\
|
||||
F6 wallet (receive QR, create/import)\n\
|
||||
F8 rotate prekey\n\
|
||||
F9 wallets & settings menu\n\
|
||||
/profile edit name, bio, Monero address\n\
|
||||
/pay <xmr> [memo] invoice to receive\n\
|
||||
/tip <xmr> [memo] pay selected friend\n\
|
||||
|
|
@ -555,6 +557,9 @@ OnionWire keys\n\
|
|||
/file /path send file to selected friend (1 MiB)\n\
|
||||
/backup /path encrypted identity export\n\
|
||||
/restore /path overwrite self keys\n\
|
||||
/wipe wipe messages; identity and friends stay\n\
|
||||
/wipe-all wipe identity too — you become a new person\n\
|
||||
/settings wallets & settings menu\n\
|
||||
? this help\n\
|
||||
Ctrl-Q quit; type CLEAR or QUIT\n\
|
||||
\n\
|
||||
|
|
@ -652,6 +657,8 @@ pub enum SlashCmd {
|
|||
Wipe(WipeKind),
|
||||
Profile,
|
||||
Who,
|
||||
/// `/settings` — the WALLETS & SETTINGS menu (same screen as F9).
|
||||
Settings,
|
||||
Pay { atomic: String, memo: String },
|
||||
Tip { atomic: String, memo: String },
|
||||
Backup { path: String },
|
||||
|
|
@ -808,6 +815,7 @@ pub fn parse_cmd(raw: &str) -> Option<SlashCmd> {
|
|||
return parse_path_cmd(rest).map(|path| SlashCmd::File { path });
|
||||
}
|
||||
match s {
|
||||
"/settings" => return Some(SlashCmd::Settings),
|
||||
"/wallet create" => return Some(SlashCmd::WalletCreate),
|
||||
"/wallet import" => return Some(SlashCmd::WalletImport),
|
||||
_ => {}
|
||||
|
|
@ -1224,6 +1232,12 @@ enum Screen {
|
|||
qr_modal: Option<QrModal>,
|
||||
},
|
||||
WalletSetup(WalletSetup),
|
||||
/// F9 / `/settings`: the WALLETS & SETTINGS discovery menu. Holds the
|
||||
/// snapshot, not a pre-rendered body, so a resize re-fits and nothing stale
|
||||
/// survives a repaint.
|
||||
WalletsSettings {
|
||||
state: WalletMenuState,
|
||||
},
|
||||
Quit {
|
||||
prompt: QuitPrompt,
|
||||
},
|
||||
|
|
@ -1312,6 +1326,7 @@ impl App {
|
|||
|
||||
let mut wipe_confirm = None;
|
||||
let mut quit_clear = None;
|
||||
let mut copy_addr = false;
|
||||
let mut profile_save = None;
|
||||
let mut open_profile = false;
|
||||
let mut pay_cmd = None;
|
||||
|
|
@ -1319,31 +1334,59 @@ impl App {
|
|||
let mut file_cmd = None;
|
||||
let mut chat_send = None;
|
||||
let mut pass_submit = None;
|
||||
|
||||
// The function-key shortcuts stay live on the WALLETS & SETTINGS screen
|
||||
// too: that screen's whole point is naming the key that fires each row,
|
||||
// so a key it names has to work while it is open.
|
||||
if matches!(self.screen, Screen::Main | Screen::WalletsSettings { .. }) {
|
||||
match key.code {
|
||||
KeyCode::F(2) => {
|
||||
self.open_share()?;
|
||||
return Ok(None);
|
||||
}
|
||||
KeyCode::F(3) => {
|
||||
self.screen = Screen::Paste {
|
||||
buf: String::new(),
|
||||
err: None,
|
||||
};
|
||||
return Ok(None);
|
||||
}
|
||||
KeyCode::F(4) => {
|
||||
self.screen = Screen::Rotate {
|
||||
prompt: RotatePrompt::new(),
|
||||
};
|
||||
return Ok(None);
|
||||
}
|
||||
KeyCode::F(5) => {
|
||||
self.who_open = true;
|
||||
return Ok(None);
|
||||
}
|
||||
KeyCode::F(6) => {
|
||||
self.open_wallet()?;
|
||||
return Ok(None);
|
||||
}
|
||||
KeyCode::F(8) => {
|
||||
self.screen = Screen::RotatePrekey {
|
||||
prompt: RotatePrompt::new(),
|
||||
};
|
||||
return Ok(None);
|
||||
}
|
||||
KeyCode::F(9) => {
|
||||
if matches!(self.screen, Screen::Main) {
|
||||
self.open_wallets_settings()?;
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
match &mut self.screen {
|
||||
Screen::Main => match key.code {
|
||||
KeyCode::Tab => self.focus = self.focus.next(),
|
||||
KeyCode::BackTab => self.focus = self.focus.prev(),
|
||||
KeyCode::Up => self.nav_up(),
|
||||
KeyCode::Down => self.nav_down(),
|
||||
KeyCode::F(2) => self.open_share()?,
|
||||
KeyCode::F(3) => {
|
||||
self.screen = Screen::Paste {
|
||||
buf: String::new(),
|
||||
err: None,
|
||||
};
|
||||
}
|
||||
KeyCode::F(4) => {
|
||||
self.screen = Screen::Rotate {
|
||||
prompt: RotatePrompt::new(),
|
||||
};
|
||||
}
|
||||
KeyCode::F(5) => self.who_open = true,
|
||||
KeyCode::F(6) => self.open_wallet()?,
|
||||
KeyCode::F(8) => {
|
||||
self.screen = Screen::RotatePrekey {
|
||||
prompt: RotatePrompt::new(),
|
||||
};
|
||||
}
|
||||
KeyCode::Esc => self.composer.clear(),
|
||||
KeyCode::Backspace => {
|
||||
if self.focus == Pane::Composer {
|
||||
|
|
@ -1367,6 +1410,10 @@ impl App {
|
|||
self.composer.clear();
|
||||
self.who_open = true;
|
||||
}
|
||||
Some(ComposerAction::Cmd(SlashCmd::Settings)) => {
|
||||
self.composer.clear();
|
||||
self.open_wallets_settings()?;
|
||||
}
|
||||
Some(ComposerAction::Cmd(SlashCmd::Pay { atomic, memo })) => {
|
||||
self.composer.clear();
|
||||
pay_cmd = Some((atomic, memo));
|
||||
|
|
@ -1553,6 +1600,11 @@ impl App {
|
|||
_ => {}
|
||||
},
|
||||
Screen::WalletSetup(_) => self.handle_wallet_setup(key)?,
|
||||
Screen::WalletsSettings { .. } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
KeyCode::Char('c') => copy_addr = true,
|
||||
_ => {}
|
||||
},
|
||||
Screen::Quit { prompt } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
KeyCode::Enter => match prompt.on_char('\n') {
|
||||
|
|
@ -1572,6 +1624,9 @@ impl App {
|
|||
if let Some(kind) = wipe_confirm {
|
||||
return self.confirm_wipe(kind);
|
||||
}
|
||||
if copy_addr {
|
||||
self.copy_receive_address();
|
||||
}
|
||||
if let Some(clear) = quit_clear {
|
||||
if clear {
|
||||
self.node.wipe_messages()?;
|
||||
|
|
@ -1787,6 +1842,78 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// F9 / `/settings`: snapshot the state the WALLETS & SETTINGS menu shows.
|
||||
///
|
||||
/// Credential-free by construction: it reads `Node`'s status/label getters
|
||||
/// only — never `WalletConfig::rpc_login`, `secret()`, a seed, or a
|
||||
/// passphrase — so nothing on the screen can leak one.
|
||||
///
|
||||
/// It blocks on the same three wallet calls the F6 screen already blocks on
|
||||
/// (address, balance, recent transfers); `wallet_status` and
|
||||
/// `wallet_child_status` are lock-only reads and never dial.
|
||||
fn open_wallets_settings(&mut self) -> Result<(), String> {
|
||||
let wstat = self.node.wallet_status();
|
||||
let child = self.node.wallet_child_status();
|
||||
let balance = self.rt.block_on(self.node.wallet_balance());
|
||||
let receive_addr = self
|
||||
.rt
|
||||
.block_on(self.node.wallet_receive_address())
|
||||
.unwrap_or_default();
|
||||
let transfers = self
|
||||
.rt
|
||||
.block_on(self.node.wallet_recent_transfers(8))
|
||||
.map(|rows| rows.len())
|
||||
.unwrap_or(0);
|
||||
let profile = self.node.self_profile().ok();
|
||||
let nickname = profile
|
||||
.as_ref()
|
||||
.and_then(|p| (!p.display_name.is_empty()).then(|| p.display_name.clone()));
|
||||
let bio_set = profile.as_ref().is_some_and(|p| !p.bio.is_empty());
|
||||
let xmr_set = profile.as_ref().is_some_and(|p| !p.xmr_addr.is_empty());
|
||||
self.screen = Screen::WalletsSettings {
|
||||
state: WalletMenuState {
|
||||
configured: wstat.configured,
|
||||
connected: wstat.connected,
|
||||
wallet_error: wstat.last_error,
|
||||
receive_addr,
|
||||
balance,
|
||||
transfers,
|
||||
child_state: child.state.as_str().to_string(),
|
||||
child_source: child.chain_source,
|
||||
child_error: child.last_error,
|
||||
nickname,
|
||||
bio_set,
|
||||
xmr_set,
|
||||
me_fp: self.me_fp.clone(),
|
||||
},
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `c` on the WALLETS & SETTINGS menu: copy the receive address through the
|
||||
/// terminal's own clipboard (OSC 52 — no crate, and it survives SSH). The
|
||||
/// address never touches a file.
|
||||
fn copy_receive_address(&mut self) {
|
||||
let addr = match &self.screen {
|
||||
Screen::WalletsSettings { state } => state.receive_addr.clone(),
|
||||
_ => return,
|
||||
};
|
||||
if addr.is_empty() {
|
||||
self.status_note = Some("no receive address to copy".into());
|
||||
return;
|
||||
}
|
||||
let seq = osc52_copy_sequence(&addr);
|
||||
let wrote = {
|
||||
let mut out = io::stdout();
|
||||
out.write_all(seq.as_bytes()).is_ok() && out.flush().is_ok()
|
||||
};
|
||||
self.status_note = Some(if wrote {
|
||||
"copied receive address".into()
|
||||
} else {
|
||||
"could not write the clipboard sequence".into()
|
||||
});
|
||||
}
|
||||
|
||||
/// The core's pay/tip readiness guard, refused before any dial when the
|
||||
/// wallet is unconfigured, view-only (for a tip), or not answering. `true`
|
||||
/// when the send may proceed; the reason is already in the status note when
|
||||
|
|
@ -2250,6 +2377,19 @@ impl App {
|
|||
)
|
||||
}
|
||||
Screen::WalletSetup(setup) => draw_wallet_setup(f, setup),
|
||||
Screen::WalletsSettings { state } => {
|
||||
// The one status line the screen carries: same `status_footer`
|
||||
// shape as Main, so TOR / identity / the copy confirmation read
|
||||
// in the same place on every screen.
|
||||
let footer = status_footer(
|
||||
f.area().width,
|
||||
&self.me_fp,
|
||||
&self.me_onion,
|
||||
self.status_note.as_deref(),
|
||||
footer_hints(&self.screen),
|
||||
);
|
||||
draw_wallets_settings(f, state, &footer)
|
||||
}
|
||||
}
|
||||
if self.help_open {
|
||||
draw_text_overlay(f, "? help", help_overlay_text());
|
||||
|
|
@ -2545,9 +2685,12 @@ fn footer_fits(parts: &[String], extra: &[&str], help: &str, gap: &str, w: usize
|
|||
char_len(&all.join(gap)) <= w
|
||||
}
|
||||
|
||||
/// Main-screen key hints. Kept short so width 80 still shows TOR + identity + `? help`.
|
||||
/// Main-screen key hints. `F6` (wallet) and `F9` (wallets & settings) are named
|
||||
/// here on purpose: the menu is the discoverable surface, and the footer is how
|
||||
/// a user finds the menu in the first place. Kept short so width 80 still shows
|
||||
/// TOR + identity + `? help`.
|
||||
pub fn main_footer_hints() -> &'static str {
|
||||
"Tab F2 F3 F4 F5 ? help Ctrl-Q"
|
||||
"Tab F2 F3 F4 F5 F6 F9 ? help Ctrl-Q"
|
||||
}
|
||||
|
||||
fn footer_hints(screen: &Screen) -> &'static str {
|
||||
|
|
@ -2575,6 +2718,7 @@ match screen {
|
|||
}
|
||||
Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help",
|
||||
Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help",
|
||||
Screen::WalletsSettings { .. } => "Esc back c copy ? help",
|
||||
Screen::Quit { .. } => "CLEAR or QUIT then Enter Esc cancel ? help",
|
||||
}
|
||||
}
|
||||
|
|
@ -2789,6 +2933,443 @@ pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) {
|
|||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WALLETS & SETTINGS menu (F9 / `/settings`)
|
||||
//
|
||||
// One screen that names every wallet and settings capability the TUI can
|
||||
// actually reach, together with the key or command that fires each one. It is a
|
||||
// discoverability layer over the existing shortcuts, not a replacement: F2, F3,
|
||||
// F4, F5, F6 and F8 keep working, and they stay live *on this screen* so no row
|
||||
// can name a key that does nothing here.
|
||||
//
|
||||
// Copy, never credentials. `WalletMenuState` carries booleans, labels and
|
||||
// display-ready error strings from `Node`'s getters; it has no field that can
|
||||
// hold `WalletConfig::rpc_login`, `secret()`, a seed, or a passphrase.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Label column in cells. Every label is short ASCII, so this is also its
|
||||
/// character count.
|
||||
const MENU_LABEL_W: usize = 9;
|
||||
/// Key column in cells: the widest key string the menu emits.
|
||||
const MENU_KEYS_W: usize = 12;
|
||||
|
||||
/// State the WALLETS & SETTINGS menu draws. Built once by the caller from
|
||||
/// `Node`'s getters and carried raw (un-sanitized) — the render path strips
|
||||
/// control/bidi characters and truncates in cells.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct WalletMenuState {
|
||||
/// A wallet endpoint resolved to a usable wallet (stored or env config).
|
||||
pub configured: bool,
|
||||
/// The last probe answered. Never inferred from `configured`.
|
||||
pub connected: bool,
|
||||
/// `WalletStatus::last_error`, display-ready.
|
||||
pub wallet_error: Option<String>,
|
||||
/// Receive address; empty when the wallet is unreachable.
|
||||
pub receive_addr: String,
|
||||
/// Human-readable balance, or `off` / `err` from `Node::wallet_balance`.
|
||||
pub balance: String,
|
||||
/// How many recent transfers `Node::wallet_recent_transfers` returned.
|
||||
pub transfers: usize,
|
||||
/// `WalletChildState` display word: off / connecting / syncing / ready /
|
||||
/// exited.
|
||||
pub child_state: String,
|
||||
/// Chain-source label: `receive-only` / `local node` / `remote daemon`.
|
||||
pub child_source: String,
|
||||
/// `WalletChildStatus::last_error`, display-ready.
|
||||
pub child_error: Option<String>,
|
||||
/// Self-profile display name, if one is set.
|
||||
pub nickname: Option<String>,
|
||||
pub bio_set: bool,
|
||||
pub xmr_set: bool,
|
||||
/// Our own fingerprint (identity = pubkey), full hex.
|
||||
pub me_fp: String,
|
||||
}
|
||||
|
||||
/// Width of `s` in terminal **cells**, measured by ratatui's own text type.
|
||||
///
|
||||
/// `unicode-width` is not a direct dependency of this crate, so this goes
|
||||
/// through `Span::width` — the same measurement the renderer truncates with —
|
||||
/// rather than `chars().count()`: CJK and emoji are double-width, combining
|
||||
/// marks zero-width, and a char count gets both wrong.
|
||||
pub fn cell_width(s: &str) -> usize {
|
||||
ratatui::text::Span::raw(s).width()
|
||||
}
|
||||
|
||||
/// Truncate `s` to at most `max` cells, closed with the chrome's ellipsis.
|
||||
pub fn fit_cells(s: &str, max: usize) -> String {
|
||||
if cell_width(s) <= max {
|
||||
return s.to_string();
|
||||
}
|
||||
let e = ellipsis();
|
||||
let el = cell_width(e);
|
||||
if max <= el {
|
||||
return e.chars().take(max).collect();
|
||||
}
|
||||
let budget = max - el;
|
||||
let mut out = String::new();
|
||||
let mut used = 0;
|
||||
for ch in s.chars() {
|
||||
let w = cell_width(&ch.to_string());
|
||||
if used + w > budget {
|
||||
break;
|
||||
}
|
||||
used += w;
|
||||
out.push(ch);
|
||||
}
|
||||
format!("{out}{e}")
|
||||
}
|
||||
|
||||
/// One row of untrusted text, made safe to place in a single line: control and
|
||||
/// bidi characters stripped (newlines and tabs included, or they would break
|
||||
/// the row) and the rest left to `fit_cells`.
|
||||
fn menu_cell_text(raw: &str) -> String {
|
||||
sanitize::display_text(raw.as_bytes())
|
||||
.chars()
|
||||
.filter(|c| !matches!(c, '\n' | '\r' | '\t'))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn menu_yn(set: bool) -> &'static str {
|
||||
if set { "set" } else { "unset" }
|
||||
}
|
||||
|
||||
/// Which `style_*` token a row's value carries. Colour is never the only
|
||||
/// signal: every value also spells its state out in words.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum MenuTone {
|
||||
Normal,
|
||||
Dim,
|
||||
Alert,
|
||||
Stale,
|
||||
}
|
||||
|
||||
struct MenuRow {
|
||||
label: &'static str,
|
||||
value: String,
|
||||
keys: &'static str,
|
||||
tone: MenuTone,
|
||||
}
|
||||
|
||||
impl MenuRow {
|
||||
fn new(label: &'static str, value: String, keys: &'static str, tone: MenuTone) -> Self {
|
||||
Self {
|
||||
label,
|
||||
value,
|
||||
keys,
|
||||
tone,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The two groups, in the order the card fixes: WALLET, then SETTINGS.
|
||||
///
|
||||
/// Payment history here is the wallet's own transfer list (F6), which is the
|
||||
/// only history `Node` exposes to the TUI. The peer `payments` table has no
|
||||
/// `Node` accessor (see the card's gap list).
|
||||
fn menu_groups(s: &WalletMenuState) -> (Vec<MenuRow>, Vec<MenuRow>) {
|
||||
let endpoint_word = if !s.configured {
|
||||
"not configured · receive-only"
|
||||
} else if s.connected {
|
||||
"configured · connected"
|
||||
} else {
|
||||
"configured · not connected"
|
||||
};
|
||||
let endpoint_tone = if s.wallet_error.is_some() {
|
||||
MenuTone::Alert
|
||||
} else if !s.configured {
|
||||
MenuTone::Dim
|
||||
} else if s.connected {
|
||||
MenuTone::Normal
|
||||
} else {
|
||||
MenuTone::Stale
|
||||
};
|
||||
let endpoint_value = match &s.wallet_error {
|
||||
Some(e) => format!("{endpoint_word} · {}", menu_cell_text(e)),
|
||||
None => endpoint_word.to_string(),
|
||||
};
|
||||
|
||||
let running = matches!(s.child_state.as_str(), "connecting" | "syncing" | "ready");
|
||||
let child_value = format!(
|
||||
"{} · {}",
|
||||
menu_cell_text(&s.child_source),
|
||||
if running { "running" } else { "not started" }
|
||||
);
|
||||
let (sync_word, sync_tone) = match s.child_state.as_str() {
|
||||
"ready" => ("chain at tip · wallet answering", MenuTone::Normal),
|
||||
"syncing" => ("wallet answering · chain not at tip", MenuTone::Stale),
|
||||
"connecting" => ("wallet RPC not answering yet", MenuTone::Stale),
|
||||
"exited" => ("child exited", MenuTone::Alert),
|
||||
_ => ("not probing · no chain source", MenuTone::Dim),
|
||||
};
|
||||
let sync_value = match &s.child_error {
|
||||
Some(e) => format!("{sync_word} · {}", menu_cell_text(e)),
|
||||
None => sync_word.to_string(),
|
||||
};
|
||||
|
||||
let receive_empty = s.receive_addr.is_empty();
|
||||
let wallet = vec![
|
||||
MenuRow::new("endpoint", endpoint_value, "", endpoint_tone),
|
||||
MenuRow::new("child", child_value, "F6 s/x", MenuTone::Normal),
|
||||
MenuRow::new("sync", sync_value, "F6 p", sync_tone),
|
||||
MenuRow::new(
|
||||
"receive",
|
||||
if receive_empty {
|
||||
"no address yet · wallet unreachable".to_string()
|
||||
} else {
|
||||
menu_cell_text(&s.receive_addr)
|
||||
},
|
||||
if receive_empty { "" } else { "c copy F6 r" },
|
||||
if receive_empty {
|
||||
MenuTone::Dim
|
||||
} else {
|
||||
MenuTone::Normal
|
||||
},
|
||||
),
|
||||
MenuRow::new(
|
||||
"balance",
|
||||
menu_cell_text(&s.balance),
|
||||
"F6",
|
||||
match s.balance.as_str() {
|
||||
"err" => MenuTone::Alert,
|
||||
"off" | "" => MenuTone::Dim,
|
||||
_ => MenuTone::Normal,
|
||||
},
|
||||
),
|
||||
MenuRow::new(
|
||||
"payments",
|
||||
if s.transfers == 0 {
|
||||
"no transfers yet".to_string()
|
||||
} else {
|
||||
format!("{} recent", s.transfers)
|
||||
},
|
||||
"F6",
|
||||
if s.transfers == 0 {
|
||||
MenuTone::Dim
|
||||
} else {
|
||||
MenuTone::Normal
|
||||
},
|
||||
),
|
||||
MenuRow::new(
|
||||
"create",
|
||||
"/wallet create · seed shown once".to_string(),
|
||||
"F6 c",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
MenuRow::new(
|
||||
"import",
|
||||
"/wallet import · 25-word seed".to_string(),
|
||||
"F6 i",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
];
|
||||
|
||||
let settings = vec![
|
||||
MenuRow::new(
|
||||
"nickname",
|
||||
match &s.nickname {
|
||||
Some(n) => menu_cell_text(n),
|
||||
None => "(none)".to_string(),
|
||||
},
|
||||
"/profile",
|
||||
if s.nickname.is_some() {
|
||||
MenuTone::Normal
|
||||
} else {
|
||||
MenuTone::Dim
|
||||
},
|
||||
),
|
||||
MenuRow::new(
|
||||
"profile",
|
||||
format!("bio {} · xmr {}", menu_yn(s.bio_set), menu_yn(s.xmr_set)),
|
||||
"/profile",
|
||||
if s.bio_set || s.xmr_set {
|
||||
MenuTone::Normal
|
||||
} else {
|
||||
MenuTone::Dim
|
||||
},
|
||||
),
|
||||
MenuRow::new(
|
||||
"identity",
|
||||
format!("{} · identity = pubkey", truncate_fp(&s.me_fp)),
|
||||
"F2",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
MenuRow::new(
|
||||
"colour",
|
||||
"auto · follows NO_COLOR / TERM".to_string(),
|
||||
"",
|
||||
MenuTone::Dim,
|
||||
),
|
||||
MenuRow::new(
|
||||
"backup",
|
||||
"encrypted identity export".to_string(),
|
||||
"/backup",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
MenuRow::new(
|
||||
"restore",
|
||||
"overwrite self keys from a backup".to_string(),
|
||||
"/restore",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
MenuRow::new(
|
||||
"wipe",
|
||||
"messages · identity and friends stay".to_string(),
|
||||
"/wipe",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
MenuRow::new(
|
||||
"wipe-all",
|
||||
"deletes your identity key · new person".to_string(),
|
||||
"/wipe-all",
|
||||
MenuTone::Normal,
|
||||
),
|
||||
];
|
||||
(wallet, settings)
|
||||
}
|
||||
|
||||
fn menu_tone_style(tone: MenuTone) -> Style {
|
||||
match tone {
|
||||
MenuTone::Normal => style_text(),
|
||||
MenuTone::Dim => style_dim(),
|
||||
MenuTone::Alert => style_alert(),
|
||||
MenuTone::Stale => style_stale(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Section header: the title in the accent, ruled off in the dim tone. The rule
|
||||
/// glyph degrades to `-` under `ONIONWIRE_ASCII` / `NO_COLOR`.
|
||||
fn menu_section_line(width: usize, title: &str) -> Line<'static> {
|
||||
let used = cell_width(title) + 1;
|
||||
let rule = if ascii_chrome() { "-" } else { "─" };
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
format!("{title} "),
|
||||
style_accent().add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(rule.repeat(width.saturating_sub(used)), style_dim()),
|
||||
])
|
||||
}
|
||||
|
||||
/// One row, padded out to exactly `width` cells: ` label value … keys`.
|
||||
///
|
||||
/// The key column is right-aligned so the eye can run down it, and the value is
|
||||
/// truncated (never allowed to push the key off the row) so no row can wrap,
|
||||
/// clip or scroll at 80 columns.
|
||||
fn menu_row_line(width: usize, row: &MenuRow) -> Line<'static> {
|
||||
let head = format!(" {:<w$} ", row.label, w = MENU_LABEL_W);
|
||||
let head_w = cell_width(&head);
|
||||
let keys = fit_cells(row.keys, MENU_KEYS_W);
|
||||
// A terminal narrower than the fixed columns drops the key column instead of
|
||||
// wrapping the row; 80 columns is the floor anyway, and 200x60 must not
|
||||
// break above it.
|
||||
let keys_w = cell_width(&keys);
|
||||
let keys = if width < head_w + keys_w + 2 {
|
||||
String::new()
|
||||
} else {
|
||||
keys
|
||||
};
|
||||
let keys_w = cell_width(&keys);
|
||||
let tail = if keys_w == 0 { 0 } else { keys_w + 1 };
|
||||
let value = fit_cells(
|
||||
&menu_cell_text(&row.value),
|
||||
width.saturating_sub(head_w + tail).max(1),
|
||||
);
|
||||
let used = head_w + cell_width(&value) + tail;
|
||||
let pad = " ".repeat(width.saturating_sub(used));
|
||||
let mut spans = vec![
|
||||
Span::styled(head, style_dim()),
|
||||
Span::styled(value, menu_tone_style(row.tone)),
|
||||
];
|
||||
if keys_w == 0 {
|
||||
spans.push(Span::raw(pad));
|
||||
} else {
|
||||
spans.push(Span::raw(format!("{pad} ")));
|
||||
spans.push(Span::styled(keys, style_accent()));
|
||||
}
|
||||
Line::from(spans)
|
||||
}
|
||||
|
||||
/// The menu body as styled lines sized for `width` **inner** cells (the width
|
||||
/// inside the block's borders).
|
||||
pub fn wallets_settings_menu_lines(width: u16, s: &WalletMenuState) -> Vec<Line<'static>> {
|
||||
let w = width as usize;
|
||||
let (wallet, settings) = menu_groups(s);
|
||||
let mut out = vec![menu_section_line(w, "WALLET")];
|
||||
out.extend(wallet.iter().map(|row| menu_row_line(w, row)));
|
||||
out.push(Line::default());
|
||||
out.push(menu_section_line(w, "SETTINGS"));
|
||||
out.extend(settings.iter().map(|row| menu_row_line(w, row)));
|
||||
out
|
||||
}
|
||||
|
||||
/// The menu body as plain text, for width/needle assertions.
|
||||
pub fn wallets_settings_menu_text(width: u16, s: &WalletMenuState) -> String {
|
||||
wallets_settings_menu_lines(width, s)
|
||||
.iter()
|
||||
.map(|line| {
|
||||
line.spans
|
||||
.iter()
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
/// WALLETS & SETTINGS: a full screen, never a popup — body plus the one status
|
||||
/// line every other screen shares. `footer` is an already-built `status_footer`
|
||||
/// line, so the caller owns TOR / identity / the transient note.
|
||||
pub fn draw_wallets_settings(f: &mut Frame, state: &WalletMenuState, footer: &str) {
|
||||
let area = f.area();
|
||||
let rows = Layout::vertical([Constraint::Min(3), Constraint::Length(1)]).split(area);
|
||||
let inner = rows[0].width.saturating_sub(2);
|
||||
f.render_widget(
|
||||
Paragraph::new(wallets_settings_menu_lines(inner, state))
|
||||
.block(themed_block("(o) wallets & settings")),
|
||||
rows[0],
|
||||
);
|
||||
f.render_widget(
|
||||
Paragraph::new(fit_cells(footer, area.width as usize)).style(style_dim()),
|
||||
rows[1],
|
||||
);
|
||||
}
|
||||
|
||||
/// OSC 52 clipboard write for `text`: the terminal copies it, so no crate and
|
||||
/// no clipboard daemon are involved and it still works over SSH. A terminal
|
||||
/// that does not implement OSC 52 ignores the sequence.
|
||||
pub fn osc52_copy_sequence(text: &str) -> String {
|
||||
let clean = menu_cell_text(text);
|
||||
let trimmed = clean.trim();
|
||||
format!("\x1b]52;c;{}\x07", base64_encode(trimmed.as_bytes()))
|
||||
}
|
||||
|
||||
/// Plain RFC 4648 base64 (standard alphabet, `=` padded). Hand-rolled because
|
||||
/// this crate has no base64 dependency and the menu needs exactly one call site.
|
||||
fn base64_encode(bytes: &[u8]) -> String {
|
||||
const ALPHABET: &[u8; 64] =
|
||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
let mut out = String::with_capacity(bytes.len().div_ceil(3) * 4);
|
||||
for chunk in bytes.chunks(3) {
|
||||
let b0 = chunk[0] as u32;
|
||||
let b1 = *chunk.get(1).unwrap_or(&0) as u32;
|
||||
let b2 = *chunk.get(2).unwrap_or(&0) as u32;
|
||||
let n = (b0 << 16) | (b1 << 8) | b2;
|
||||
out.push(ALPHABET[((n >> 18) & 63) as usize] as char);
|
||||
out.push(ALPHABET[((n >> 12) & 63) as usize] as char);
|
||||
out.push(if chunk.len() > 1 {
|
||||
ALPHABET[((n >> 6) & 63) as usize] as char
|
||||
} else {
|
||||
'='
|
||||
});
|
||||
out.push(if chunk.len() > 2 {
|
||||
ALPHABET[(n & 63) as usize] as char
|
||||
} else {
|
||||
'='
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn truncate_fp(fp: &str) -> String {
|
||||
let s: String = fp.chars().take(8).collect();
|
||||
format!("{s}{}", ellipsis())
|
||||
|
|
|
|||
Loading…
Reference in a new issue