(53ffb94) Run the command the prompt parsed, and redraw the board on what it wrote, and bump to 0.32.16
The prompt parsed a line and named what it resolved to. This is the half that does it: the parsed command goes to the same cmd_* handler main.rs hands it to, against the selected tab's own .worklane, with a Sink over a buffer collecting what the handler says instead of stdout. One dispatch table, not two. main.rs's match on Command is lifted into `dispatch`, over the command, the start path and the sink, and both callers go through it. A second copy in tui.rs would drift the first time a command was added and would drift silently, since both halves go on compiling; the match is exhaustive so a new verb cannot fall into an `_` arm either. Only `tui` is matched outside it, in main, because the board is that table's caller rather than an entry in it, and reached from the prompt it is refused in those words. Two things the board has to do that the CLI never had to. It reloads unconditionally after a command returns rather than waiting for the digest, so a reader does not watch their own mv take up to a poll interval to appear, and either way, since a handler that failed part way through has still written. And the selection is restored by uuid across that reload: mv puts the card in another column, set --title renames its file, and a filter can drop it out of view, so the slot is not the ticket. Where the board cannot follow it, the notice says so and which key shows it. What the handler says is what the board reports, word for word. Notice therefore holds as many lines as the command used, and notice_on_row is the one rule for where they go: one line on the footer row where a copy's notice has always gone, anything else as a box at the foot of the columns. A box rather than more rows of footer, because a footer that grew and shrank as notices came and went would reflow the columns on every keypress. A handler that errors leaves the prompt open with the line intact, the usual cause being an ambiguous id. `without_escapes` in util.rs is the guard at the seam. A handler's own output is plain because the sink is, but an error message is built with color_text, which asks the process about its stdout and under the board answers yes about a terminal the message is not going to; a ratatui paragraph prints an escape rather than obeying it. That is 6d327df's fault on a new path. The merge tab is refused for now, resolved by index rather than by the tab's name, which is a label two projects can share. Routing by the card a command names is ebc5755. Not done here, and both tracked: check with no criterion still reaches ask_which_criterion and reads a raw-mode stdin, which is 6d37042's criterion 4 and commented there; and check_blockers warns about a dangling blocker with eprintln!, which reaches the alternate screen because it never passes through dispatch's result, filed as c680e24.
This commit is contained in:
+40
-1
@@ -303,6 +303,42 @@ pub fn color_text(text: &str, color: Color) -> String {
|
||||
paint(text, color, should_use_colors())
|
||||
}
|
||||
|
||||
/// `text` with every ANSI escape sequence taken out of it.
|
||||
///
|
||||
/// The inverse of what [`paint`] writes, and the guard at the seam where a handler's
|
||||
/// words become something the board draws: ratatui prints an escape as literal bytes
|
||||
/// rather than obeying it, so a painted status reaches the screen as `\x1b[33m` and
|
||||
/// the word after it.
|
||||
///
|
||||
/// A [`Sink`] the board owns is plain, so this is not about a handler's ordinary
|
||||
/// output. It is about the strings that never go through one: an error message is
|
||||
/// built with `color_text`, which asks the *process* about its stdout, and under the
|
||||
/// board that answers yes about a terminal the message is not going to.
|
||||
pub fn without_escapes(text: &str) -> String {
|
||||
let mut out = String::with_capacity(text.len());
|
||||
let mut chars = text.chars();
|
||||
|
||||
while let Some(c) = chars.next() {
|
||||
if c != '\x1b' {
|
||||
out.push(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
// A CSI sequence is `\x1b[`, then parameter bytes, closed by a final byte in
|
||||
// `@` to `~`. That is every sequence `Color` writes. Anything else is a short
|
||||
// escape whose one following character goes with it, which `next` has taken.
|
||||
if chars.next() == Some('[') {
|
||||
for c in chars.by_ref() {
|
||||
if ('\x40'..='\x7e').contains(&c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// A destination for a command's output, chosen by the caller.
|
||||
///
|
||||
/// `main` hands a handler its own stdout and nothing about the CLI changes; the
|
||||
@@ -332,7 +368,10 @@ impl<'a> Sink<'a> {
|
||||
|
||||
/// An in-memory buffer, plain, for a test or a caller that colours the text
|
||||
/// itself.
|
||||
#[allow(dead_code)]
|
||||
///
|
||||
/// What the board's command prompt passes: the handler's words come back as text
|
||||
/// and the board styles them with ratatui, which is also why it must not be handed
|
||||
/// a coloured one — a paragraph prints an escape rather than obeying it.
|
||||
pub fn buffer(target: &'a mut Vec<u8>) -> Sink<'a> {
|
||||
Sink {
|
||||
writer: Box::new(target),
|
||||
|
||||
Reference in New Issue
Block a user