fix(tui): invite payload gets a chrome-free region so mouse-copy is exact
Mouse-selecting the invite copied the pane border: draw_share rendered the payload inside themed_block, which is Borders::ALL, so every wrapped row sat between a leading and a trailing glyph. OnionWire enables no mouse capture, so the terminal's own drag-select is the copy path and it picks up chrome. The payload now has its own region — flush at column 0, full frame width, no block, no title, no gutter on any row it occupies — with the block (title, fp, onion, copy hint) above it. Measured in cells, not chars. Also add C: OSC 52 hand the payload to the terminal clipboard (same sequence the F9 menu uses), with the key named on the screen and the mouse selection named as the fallback for terminals that block the sequence. Regression tests reconstruct the payload out of the rendered frame at 80x24, 120x40, 200x60 and 60x20 (they fail on base: the leading border column) and assert no payload row carries a border glyph.
This commit is contained in:
parent
eefa7e5cc6
commit
c3116eb19e
3 changed files with 308 additions and 13 deletions
96
src/tui.rs
96
src/tui.rs
|
|
@ -533,7 +533,7 @@ OnionWire keys\n\
|
|||
g / G jump to top / bottom\n\
|
||||
Enter send chat to selected friend, or a /command\n\
|
||||
Esc close overlay, go back, clear composer\n\
|
||||
F2 share invite\n\
|
||||
F2 share invite (C copies it)\n\
|
||||
F3 paste invite\n\
|
||||
F4 rotate onion locator\n\
|
||||
F5 selected friend's profile (/who)\n\
|
||||
|
|
@ -1513,11 +1513,15 @@ impl App {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
Screen::Share { .. } => {
|
||||
if key.code == KeyCode::Esc {
|
||||
self.screen = Screen::Main;
|
||||
Screen::Share { .. } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
KeyCode::Char('c') | KeyCode::Char('C')
|
||||
if !key.modifiers.contains(KeyModifiers::CONTROL) =>
|
||||
{
|
||||
self.copy_invite();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Screen::Paste { buf, err } => match key.code {
|
||||
KeyCode::Esc => self.screen = Screen::Main,
|
||||
KeyCode::Enter => {
|
||||
|
|
@ -1958,6 +1962,26 @@ impl App {
|
|||
});
|
||||
}
|
||||
|
||||
/// `C` on the invite screen: the same OSC 52 handoff as the receive address,
|
||||
/// so a terminal that blocks the write still leaves the mouse selection as
|
||||
/// the way out. The payload never touches a file.
|
||||
fn copy_invite(&mut self) {
|
||||
let payload = match &self.screen {
|
||||
Screen::Share { payload } => payload.clone(),
|
||||
_ => return,
|
||||
};
|
||||
let seq = osc52_copy_sequence(&payload);
|
||||
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 invite".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
|
||||
|
|
@ -3077,23 +3101,71 @@ fn themed_block(title: &str) -> Block<'_> {
|
|||
.title_style(style_accent().add_modifier(Modifier::BOLD))
|
||||
}
|
||||
|
||||
/// The invite screen: chrome above the payload, nothing beside it.
|
||||
///
|
||||
/// Sharing is a copy job, and OnionWire never turns on mouse capture — no
|
||||
/// `EnableMouseCapture` anywhere in `src/` — so the terminal's own drag-select
|
||||
/// is what copies an invite. A drag copies every cell it crosses, pane borders
|
||||
/// included, so a bordered pane around the payload splices `│` into the string
|
||||
/// the user pastes. The payload therefore gets its own region: flush at column
|
||||
/// 0, the full frame width, no block, no title, no gutter on any row it
|
||||
/// occupies. The title, the identity lines and the copy key sit in a bordered
|
||||
/// block *above* it, and `wrap_invite` breaks on `:` so the payload rows join
|
||||
/// back to the payload byte for byte
|
||||
/// (`tests/tui_chrome.rs::share_payload_rebuilds_from_the_frame_at_80x24_and_120x40`).
|
||||
pub fn draw_share(f: &mut Frame, payload: &str) {
|
||||
let (fp, onion) = match qr::decode(payload) {
|
||||
Ok(p) => (truncate_fp(&to_hex(&p.pubkey)), p.onion),
|
||||
Err(_) => ("?".into(), "?".into()),
|
||||
};
|
||||
let inner = f.area().width.saturating_sub(2) as usize;
|
||||
let invite = wrap_invite(payload, inner.max(1));
|
||||
let body = format!(
|
||||
"give this string to a friend; they F3 paste it\n\nfp {fp}\nonion {onion}\n\n{invite}"
|
||||
);
|
||||
let area = f.area();
|
||||
let body = share_body_lines(&fp, &onion, area.width.saturating_sub(2) as usize);
|
||||
// Border top + body + border bottom. The payload region below gets no
|
||||
// block: it is the selection, so nothing may sit beside it.
|
||||
let header_h = (body.len() as u16).saturating_add(2).min(area.height);
|
||||
let rows = Layout::vertical([Constraint::Length(header_h), Constraint::Min(0)]).split(area);
|
||||
f.render_widget(
|
||||
Paragraph::new(body)
|
||||
.style(style_text())
|
||||
.wrap(Wrap { trim: false })
|
||||
.block(themed_block("(o) invite")),
|
||||
f.area(),
|
||||
rows[0],
|
||||
);
|
||||
|
||||
if rows[1].height == 0 {
|
||||
return;
|
||||
}
|
||||
// Flush at column 0, full frame width, one wrapped row per payload row.
|
||||
let wrapped = wrap_invite(payload, rows[1].width as usize);
|
||||
f.render_widget(Paragraph::new(wrapped).style(style_text()), rows[1]);
|
||||
}
|
||||
|
||||
/// Everything about the invite that is not the invite: why it exists, whose it
|
||||
/// is, and how to copy it. All of it lives in the bordered block *above* the
|
||||
/// payload, so no row of the payload region carries chrome.
|
||||
fn share_body_lines(fp: &str, onion: &str, inner: usize) -> Vec<Line<'static>> {
|
||||
let identity = format!("fp {fp} onion {onion}");
|
||||
let mut lines = vec![Line::from(fit_cells(
|
||||
"give this string to a friend; they F3 paste it",
|
||||
inner,
|
||||
))];
|
||||
if cell_width(&identity) <= inner {
|
||||
lines.push(Line::from(identity));
|
||||
} else {
|
||||
lines.push(Line::from(fit_cells(&format!("fp {fp}"), inner)));
|
||||
lines.push(Line::from(fit_cells(&format!("onion {onion}"), inner)));
|
||||
}
|
||||
// `C` is the escape hatch for terminals that block OSC 52; the mouse is the
|
||||
// path that works everywhere, so both are named.
|
||||
let copy_hint = if inner >= 48 {
|
||||
"select the link below with the mouse, or press C to copy"
|
||||
} else {
|
||||
"press C to copy, or select the link below"
|
||||
};
|
||||
lines.push(Line::from(Span::styled(
|
||||
fit_cells(copy_hint, inner),
|
||||
style_dim(),
|
||||
)));
|
||||
lines
|
||||
}
|
||||
|
||||
fn draw_paste(f: &mut Frame, buf: &str, err: Option<&str>) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue