Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c714c73a75 | ||
|
|
a017f9002e |
Generated
+1
-1
@@ -1563,7 +1563,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.33.1"
|
||||
version = "0.33.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.33.1"
|
||||
version = "0.33.3"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+3
-1
@@ -10,8 +10,10 @@ The generated half, the fish half, and what keeps the two honest.
|
||||
- **The strongest completion check loads the script into fish and asks it for candidates.** `fish_offers_the_commands_the_statuses_and_the_values` in `tests/cmd_completions.rs` sources the generated script into a throwaway shell standing in a real board, with this build's directory on the front of PATH, and compares `complete -C` against the ticket and the tag it put there. Every other test in the file reads the script as text, which cannot tell a rule that fires from one whose condition stopped matching, and that is how a completion actually breaks. **Assert the values, not the flag names**: clap emits every option's name on its own, so `--tags` and `--blocked-by` are offered with every hand-written rule deleted; what the dynamic half adds is what comes *after* the flag. Two traps, both paid for once: the shell must have `fish_complete_path` emptied, or `complete -C` autoloads `~/.config/fish/completions/worklane.fish` and answers from whatever version wrote that, which is a guard that cannot fail; and the script is written beside the board rather than in it, since a rule that fires nothing falls back to listing the directory
|
||||
- **`fish --no-execute` is the floor under that, not an oracle.** It catches a script that does not parse, quotes still open at the end of the file or an unclosed block. Measured, not assumed: an apostrophe interpolated into a `-d` description partway down re-balances against the next quote and parses, corrupting every rule in between while the check passes; the same apostrophe in the last rule reaches the end unbalanced and is caught. Only fish gets this, because only fish gets a hand-written half
|
||||
- **The rule counts in the completion tests are hardcoded on purpose.** The walkers go clap → list and never see an entry naming something that does not exist, so a bogus pair in `TAG_FLAGS` is caught by `every_tag_rule_takes_the_annotation_as_its_description` counting one rule too many. Deriving that number from the lists it checks would grow with the bogus entry and pass. The `seen` totals in the walkers are hardcoded for the mirror reason, and both carry the note
|
||||
- **The five completion lists are kept honest by tests** that walk the clap definition and fail on an argument left out of them. `TICKET_COMMANDS` and `TICKET_SECOND_COMMANDS` by position, `TICKET_FLAGS`, `CAMPAIGN_COMMANDS`, `CAMPAIGN_NESTED_COMMANDS`, `CAMPAIGN_FLAGS` and `TAG_FLAGS` likewise, the last against the test-local `TAG_LIST_FLAGS` and `TAG_NEW_COMMANDS` for the tag arguments that deliberately get no rule. The walk is one function, `every_argument`, since the tests differ only in the id they look for. Each also asserts *how many* it found, so a walker that stopped finding arguments fails rather than passing every assertion by never running them
|
||||
- **The completion lists are kept honest by tests** that walk the clap definition and fail on an argument left out of them. `TICKET_COMMANDS` and `TICKET_SECOND_COMMANDS` by position, `TICKET_FLAGS`, `CAMPAIGN_COMMANDS`, `CAMPAIGN_NESTED_COMMANDS`, `CAMPAIGN_FLAGS` and `TAG_FLAGS` likewise, the last against the test-local `TAG_LIST_FLAGS` and `TAG_NEW_COMMANDS` for the tag arguments that deliberately get no rule. The walk is one function, `every_argument`, since the tests differ only in the id they look for. Each also asserts *how many* it found, so a walker that stopped finding arguments fails rather than passing every assertion by never running them
|
||||
- **A campaign is named in three shapes and a tag in one**, which is why the lists are not one list: a campaign is `assign`'s first positional, the first argument of `campaign show` and `campaign set`, and `ls --campaign`'s value, and each needs a different fish rule. A tag is only ever an option value, and its values come from a different command
|
||||
- **`TICKET_FLAGS` holds pairs, the command and the flag, and every ticket rule in the fish half is generated from it.** Three commands carry a `--clear` and each takes something different: `chown`'s names the ticket, since with no user to give there is no positional for it; `relate`'s takes the kind and then the target; `set`'s takes a field name clap already offers. So the command is half of the fact, and a list of bare flag names could only be scoped by hand, which is what the `chown --clear` rule used to be. `every_ticket_flag_is_a_real_option` walks each pair against the command it names, which a flat list could not do
|
||||
- **The lists answer the board as well as the shell.** `ticket_argument` reads the three ticket lists to say whether the argument at a given index of a typed line is a ticket, which is what the command prompt's suggestion is built on, see [tui-prompts.md](tui-prompts.md). Position is counted there exactly as it is counted here, so the two cannot come to disagree about `mv --status done <ticket>`; a second table on the board would be a copy the tests above never read
|
||||
- **`TAG_FLAGS` holds pairs where the others hold names**, because the two options that take one tag are spelled differently: `ls --tag` filters on one and `append --tags` adds them, so a single rule naming both would tell fish that each command accepts the other's flag. One rule per pair, generated in `fish_dynamic`. `add --tags` and `set --tags` are in the test's `TAG_LIST_FLAGS` instead and get no rule: they take the *whole* list, so the token at the cursor is `bug,tui` and fish replaces a token entire, which would throw away what is already typed. The test walks both `tag` and `tags`, so the next one has to say which of the two it is
|
||||
- **`ls --ids` is the machine-readable listing**, and one of the three outputs in the tree meant to be parsed: the short id, a tab, the title, unstyled. Two fields because fish reads what follows a tab as the description and a script reads `cut -f1`. It includes done, which the decorated listing leaves out, because a completion has to be able to name a finished ticket, and it skips a missing status directory rather than refusing, because an error printed over a shell prompt is worse than no candidates. The filters still apply, and an unknown `--campaign` is still refused
|
||||
- **`campaign ls --ids` is the same flag and the same two fields for the other object**, and it deliberately skips the member counting the decorated listing does: `members()` reads every ticket on the board, and the caller here is a shell filling in candidates on a keypress. It also prints nothing on an empty board, where the decorated listing prints a sentence, because a sentence offered as a candidate is worse than no candidates
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ Recording an edge between two tickets, and drawing the block that reports them.
|
||||
- **A dependent may stand level with its blocker but never ahead of it.** `blocks_move` is the rule: the move is refused exactly when the status moved into is further down `Status::ALL` than the blocker's own, so a blocker in reviewing lets the dependent be committed and reviewed and gates only done. The first shape of this refused every move while a blocker was not done, which read as one rule rather than a table of transitions but stopped the work it was meant to order: a pair is usually built and reviewed together, and waiting for the blocker to land cost a `-f` on every move and left the rule enforcing nothing
|
||||
- **A finished blocker is answered by `is_open`, and a discard target by name.** Done landed and discarded never will, so neither holds anything up, and that is the one place the board decides what finished means. Discarded is last in `Status::ALL` for the stamp rule's sake, so a comparison of positions alone would read a discard as the furthest move of all: `blocks_move` returns false for it outright, since abandoning a ticket is not carrying it along the flow and owes nothing to what it waits on. A status that is not one of the five holds up every move, the direction `is_open` already takes with such a value: a fault surfaces rather than quietly letting a dependent past
|
||||
- **The blocker check runs on every move**, after the already-in-that-status return and behind `force`, with the target status passed in as what decides the answer. A move to the status the ticket is already in is not a move, so it is not refused. A backward move never is either, being at or behind everything, and it needs `-f` for its own reason anyway. `-f` bypasses three rules, which is the right home for it: each one is a deliberate override of something the board would otherwise keep true
|
||||
- **A blocker that is not on the board warns and allows the move.** Refusing would wedge the ticket with no way out but `-f`, and a uuid nothing carries is a bookkeeping fault rather than a dependency. The refusal names **every** blocker still behind the move and the status it was for, since advancing the one that happened to be printed would leave the ticket held up, and a ticket refused the next stage after moving once is otherwise told nothing about what changed. A blocker further along than the move is left out of the list entirely: a dependent told to wait for work already ahead of it has nothing to act on
|
||||
- **A blocker that is not on the board warns and allows the move.** Refusing would wedge the ticket with no way out but `-f`, and a uuid nothing carries is a bookkeeping fault rather than a dependency. The warning goes through the sink `check_blockers` is handed, which is why a guard that says nothing on the happy path takes one at all: the same helper runs from the board's command prompt, where the process's stderr is the alternate screen. See [The Command Prompt](tui-prompts.md). The refusal names **every** blocker still behind the move and the status it was for, since advancing the one that happened to be printed would leave the ticket held up, and a ticket refused the next stage after moving once is otherwise told nothing about what changed. A blocker further along than the move is left out of the list entirely: a dependent told to wait for work already ahead of it has nothing to act on
|
||||
- Left out on purpose: removing a relation, which 4179958 assigns to 74904dc. The blocked marker on the card landed in b8ce18c, and it cost no scan of the board: the blockers ride along on the read that already builds the cards. It asks `blocks_move` about the status one stage ahead of the column the card is in, so the mark means the card cannot advance and not that a dependency was ever recorded. See [The Board View](tui-board.md)
|
||||
|
||||
## The Relations Block
|
||||
|
||||
+15
-1
@@ -19,13 +19,14 @@ The three input modes on the board and the key that copies an id off it.
|
||||
## The Command Prompt
|
||||
- **`prompt: Option<Prompt>` is the whole mode**, the shape `search` and `detail` use: open and content cannot disagree, and closing it leaves nothing to reset. `Prompt` carries the line, the cursor as a byte offset into it, and `refused`, which is `Search::missed` with something to say
|
||||
- **`Board::prompt_key` is third in the pre-dispatch**, beside `search_key` and `picker_key` and on the same contract: while a command is being typed `q` is a letter, `d` leaves the columns alone and `tab` stays out of the project tabs, and `ctrl-c` is the one key declined. It takes a `Size` for enter's sake: running a command reloads the board and then has to bring the ticket it moved back into view, which is the measurement `follow_selection` takes. Only one of the two prompts can be open at once: `:` is reachable from the action arms alone, and while either has the keyboard the other's key is a character in a line
|
||||
- **`esc` and `enter` are the mode's own keys and are answered in `prompt_key`; everything else belongs to the line and goes to `Prompt::key`.** That is also what keeps the borrow straight, since closing the prompt takes the whole board and editing takes only the prompt. Left, right, home, end, backspace and `ctrl-w` behave as they do in a shell, and `ctrl-w` eats the separators behind the cursor before the word behind those, so one press at the end of `mv 1b78a24 ` takes the id. There is deliberately no `tab`: suggesting the selected ticket is 00a14e7, and until then it is a key that must not reach the tabs
|
||||
- **`esc` and `enter` are the mode's own keys and are answered in `prompt_key`; everything else belongs to the line and goes to `Prompt::key`.** That is also what keeps the borrow straight, since closing the prompt takes the whole board and editing takes only the prompt. Left, right, home, end, backspace and `ctrl-w` behave as they do in a shell, and `ctrl-w` eats the separators behind the cursor before the word behind those, so one press at the end of `mv 1b78a24 ` takes the id. `tab` is the mode's too, for the reason the recall walk is: what it takes is made of the selected card and the line is only where it lands
|
||||
- **The grammar is clap's, with nothing restated.** The line is tokenised by `split_line`, the binary's own name goes in front, and the arguments go to the same `Cli` definition the shell reaches, so a flag added to a command is typeable here the day it is added. Through `Cli::command().try_get_matches_from_mut` rather than `try_parse_from`, for what the matches give back: `command_name` walks the subcommands to name what resolved (`campaign show`, not `campaign`) instead of a `match` over every variant, which would be a second list of every verb the CLI has and one that goes stale silently
|
||||
- **`refused` is cleared by an edit and not by a movement.** The message is about the line, and moving the cursor does not change the line. `Prompt::key` clears it in the three arms that write to the line
|
||||
- **A line that ends inside a quote never reaches clap.** That is what `Unclosed` is for: a grammar complaint about a sentence nobody finished describes the wrong thing. Enter on an empty line, or one of nothing but separators, closes the prompt with nothing said, the way `esc` does — the bare form of the CLI opens a board and there is one on the screen
|
||||
- **Enter runs it, through `main.rs`'s `dispatch` and never through a handler this file names.** That match is the one mapping from a parsed command to the function that performs it: `main` calls it with its own stdout and the working directory, `Board::run` calls it with a buffer and the selected tab's root. A second copy inside `tui.rs` would drift the first time a command was added, and it would drift *silently*, since both halves go on compiling. The match is exhaustive so a new verb cannot fall into an `_` arm and do nothing, and `main_and_the_prompt_run_one_dispatch_table` reads both files as text to pin it. Only `tui` is matched outside the table, in `main`, because the board is that table's caller rather than an entry in it; reached from the prompt it is refused in those words
|
||||
- **`from_arg_matches` on the same matches gives `run` the typed values.** One parse, two readings: `command_name` walks the subcommands to name what resolved and `from_arg_matches` reconstructs the `Cli`. A `match` over every `Command` variant to get one or the other would be a second list of every verb the CLI has
|
||||
- **The handler's own words are what the board reports, word for word.** Those messages are written for a person already, and a second set kept here would go stale the first time one of them changed. The sink is a buffer, so the words come back as text and the board styles them; it is plain for the same reason `Detail` holds spans, since a ratatui paragraph prints an escape rather than obeying it. An error never goes through a sink at all — `color_text` asks the *process* about its stdout, which under the board answers yes about a terminal the message is not going to — so `error_lines` runs `without_escapes` over it and puts each cause on a line of its own
|
||||
- **A warning goes through the sink's second stream, and never through `eprintln!`.** `Sink` carries two writers because the CLI's two streams are two: `Sink::std` hands the answer to stdout and an aside to stderr, and a shell has to go on reading the same line on the same stream. Under the board neither is a stream at all — stderr is the alternate screen with the columns on it — so `Sink::buffer` *holds* its warnings and `Board::run` reads them back with `Sink::warnings` and puts them above the answer, on both outcomes: a `mv` that warns about a dangling blocker and is then refused by a real one wrote the aside first, and it is the half that says why the refusal names one blocker and the ticket records two. That is c680e24: one `eprintln!` in `check_blockers` outlived fa5662a because a helper had no sink to reach, and ratatui does not repaint a cell it believes is unchanged, so the fragment stayed on the columns until something else redrew them. `no_handler_or_helper_reaches_a_print_macro` walks `src` for the next one, each file cut at its test module, so a print site in a module added tomorrow is caught the day it is added
|
||||
- **A handler that errors leaves the prompt open with the line intact.** The usual cause is an ambiguous id, and the fix is two more characters rather than the whole line retyped from `:`. Ambiguity is an `Err` carrying the candidates, not a print and an `exit`, which is what makes it safe to reach from here at all
|
||||
- **The reload after a command is unconditional, and runs whether it failed or not.** `tick` reloads on the digest, which is right for a change made in another pane and needless latency for one the board just made: the reader would watch their own `mv` take up to a poll interval to appear. Either way, because a handler that failed part way through has still written
|
||||
- **The selection is restored by uuid across that reload, never by index.** `mv` puts the card in another column, `set --title` renames its file, and a filter can drop it out of view entirely, so the slot is not the ticket. `Board::reselect` has three answers: the card is in a drawn column and the selection goes to it; it is on the board but in a column the rotation is hiding, which is where `--status done` lands by default, so the notice says where it went and which key shows it; or the filter no longer holds it, which is said too, since a card vanishing from under the highlight reads as a bug in the board
|
||||
@@ -45,6 +46,19 @@ The three input modes on the board and the key that copies an id off it.
|
||||
- **A failed write is silent, and an unreadable file is an empty recall.** The line is in memory either way, so the walk works for the run on a board whose folder cannot be written, and a board with no history yet is the ordinary case rather than something to say. A notice about a history file would be about the one thing the reader did not ask for
|
||||
- **`.wlhistory` is not in `digest`.** Appending to it must not read as the tree moving, or every command typed would provoke a reload of every board on top of the one `run` already does
|
||||
|
||||
## The Prompt's Suggestion
|
||||
- **The reader has the ticket selected, which is the whole reason to type a command on the board rather than in a shell.** So where the line is naming a ticket, the selected card's short id is drawn after the cursor and `tab` takes it into the line. Retyping seven characters off the card in front of you is the friction the prompt exists to remove
|
||||
- **Where a ticket goes is `completions.rs`'s answer, not a table written here.** `ticket_argument` reads `TICKET_COMMANDS`, `TICKET_SECOND_COMMANDS` and `TICKET_FLAGS`, which `no_ticket_taking_subcommand_is_missing` and `every_ticket_flag_is_a_real_option` keep honest against clap's own definition. A second copy of the positions on the board would go wrong the next time a command grew a ticket argument, and it would go wrong *silently*, since the test guarding the first copy would not read the second
|
||||
- **The ticket is not always the first argument, which is what a naive version gets wrong.** `chown alice <ticket>` and `assign v1 <ticket>` put it second on purpose, `relate x --blocked-by <ticket>` puts it in a flag, and `chown --clear <ticket>` does too, since with no user to give there is no positional for it. Nothing is offered where the argument is something else: `relate --clear` wants a kind, `set --clear` wants a field name, and `chown`'s first argument is a user
|
||||
- **Position is counted, exactly as the fish half counts it**, so `mv --status done <ticket>` is not recognised: the ticket is `mv`'s first positional and the third argument on the line. That is the fish rules' limit as well, and one table answering both is worth more than two tables disagreeing about the corner
|
||||
- **`TICKET_FLAGS` holds pairs, command and flag, where it used to hold bare flag names.** Three commands carry a `--clear` and only `chown`'s names a ticket, so the command is half of the fact. It also took the last hand-written ticket rule out of the fish block: every one of them is generated from the table now, and `every_ticket_flag_is_a_real_option` walks each pair against the command it names
|
||||
- **It is derived on every call and held nowhere.** `Board::suggestion` is asked once by the draw and once by `tab`, so what is on the row and what the key takes cannot disagree, and there is no field to go stale when the line is edited or the selection moves. That is also what "any other key drops it" means: nothing is dropped, because nothing was kept
|
||||
- **Only with the cursor at the end of the line.** The suggestion is drawn after the cursor and `tab` inserts it there, so with a command continuing past the cursor both would land in the middle of something already typed. A shell's own suggestion keeps the same rule
|
||||
- **Only while the selected id still starts with what is typed**, and what is drawn is the rest of it rather than the whole. A suggestion that no longer matches the argument under it describes nothing, and once the whole id is typed there is nothing left to add, so a second `tab` cannot double it
|
||||
- **Nothing with no card under the selection.** On the frame the selection is on a campaign or a tag, and neither is a ticket: `y` copies what the frame names there, and this deliberately does not
|
||||
- **Grey, which is what the palette already spends on a value that is not one.** It is not in the line until `tab` puts it there, and the reader has to tell the two apart at a glance. It takes what the line leaves of the field rather than a field of its own, so a long command loses the offer instead of pushing `esc` and `enter` off the row. The terminal cursor sits on its first cell, which is where the cursor already was
|
||||
- **The row does not name `tab`.** The prompt names its two mode keys and no more — `ctrl-w`, the arrows and home and end are unnamed there as well — and the suggestion under the cursor is its own affordance
|
||||
|
||||
## Splitting a Typed Line
|
||||
- **`split_line` is the whole module, and it knows nothing about `Board`.** The command prompt reads one string and clap reads an argv, so `comment 1b78a24 the offset was never passed` has to be tokenised before anything can parse it: split on whitespace it is five arguments and `comment` takes two. A pure function over the line and the cursor is what makes every rule reachable from a unit test, and it is in a file of its own rather than in `tui.rs`, which is eleven thousand lines already
|
||||
- **The rules are the shell's, because that is what the prompt promises**: the line is spelled there exactly as it is spelled in the shell. Runs of whitespace separate arguments, single and double quotes group one, a backslash escapes the next character *except* inside single quotes where it is a backslash, and an explicitly empty `''` is an argument that exists and is empty — which is what `--title ""` being a usage error rather than a silent clear depends on. A leading hyphen is not special here: whether `--foo` is a flag or the text of a criterion is clap's question, and `PROSE` already answers it
|
||||
|
||||
+168
-33
@@ -39,8 +39,54 @@ pub const TICKET_COMMANDS: [&str; 8] = [
|
||||
/// campaign, and neither is completed.
|
||||
pub const TICKET_SECOND_COMMANDS: [&str; 2] = ["chown", "assign"];
|
||||
|
||||
/// Options whose value is a ticket, as `relate` takes three of.
|
||||
pub const TICKET_FLAGS: [&str; 3] = ["blocked-by", "regression-of", "relates-to"];
|
||||
/// Options whose value is a ticket, as the command that takes it and the flag's long name.
|
||||
///
|
||||
/// Pairs rather than the flat list this was, for the reason [`TAG_FLAGS`] holds pairs: the
|
||||
/// commands spell their flags differently and one of the spellings is shared. `relate`'s
|
||||
/// three take a ticket, `chown --clear` takes one because there is no user to give it, and
|
||||
/// `set --clear` takes a field name and `relate --clear` a relation kind — so a list of
|
||||
/// bare flag names would offer tickets to those two as well.
|
||||
pub const TICKET_FLAGS: [(&str, &str); 4] = [
|
||||
("relate", "blocked-by"),
|
||||
("relate", "regression-of"),
|
||||
("relate", "relates-to"),
|
||||
("chown", "clear"),
|
||||
];
|
||||
|
||||
/// Whether the argument at `index` of a typed line names a ticket, `index` counting from
|
||||
/// the verb at 0.
|
||||
///
|
||||
/// The three tables above read as one question, which is what the board's command prompt
|
||||
/// asks to decide whether to suggest the selected ticket. Here rather than in `tui.rs`
|
||||
/// because the tables are here and the tests that keep them honest against clap are here:
|
||||
/// a second copy of the positions on the board would go wrong the next time a command grew
|
||||
/// a ticket argument, and `no_ticket_taking_subcommand_is_missing` would not notice.
|
||||
///
|
||||
/// Position is counted rather than inferred, exactly as the fish half counts it, so
|
||||
/// `mv --status done <ticket>` is not recognised: the ticket is `mv`'s first *positional*
|
||||
/// and the third argument on the line. That is the fish rules' limit too, and one table
|
||||
/// answering both is worth more than two tables disagreeing about the corner.
|
||||
pub fn ticket_argument(args: &[String], index: usize) -> bool {
|
||||
// The verb is not a ticket, and index 0 read against the tables below would make
|
||||
// `show` its own first argument.
|
||||
if index == 0 {
|
||||
return false;
|
||||
}
|
||||
let Some(verb) = args.first().map(String::as_str) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// A flag's value is the argument after it, which is where the flag sits whether the
|
||||
// value is half typed or has not been started.
|
||||
if let Some(flag) = args.get(index - 1).and_then(|arg| arg.strip_prefix("--"))
|
||||
&& TICKET_FLAGS.contains(&(verb, flag))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
(index == 1 && TICKET_COMMANDS.contains(&verb))
|
||||
|| (index == 2 && TICKET_SECOND_COMMANDS.contains(&verb))
|
||||
}
|
||||
|
||||
/// Subcommands whose first positional is a campaign.
|
||||
///
|
||||
@@ -107,7 +153,16 @@ pub fn generate(shell: Shell, out: &mut dyn io::Write) -> io::Result<()> {
|
||||
fn fish_dynamic() -> String {
|
||||
let ticket_commands = TICKET_COMMANDS.join(" ");
|
||||
let ticket_second_commands = TICKET_SECOND_COMMANDS.join(" ");
|
||||
let ticket_flags = flag_list(&TICKET_FLAGS);
|
||||
let ticket_flags = TICKET_FLAGS
|
||||
.iter()
|
||||
.map(|(command, flag)| {
|
||||
format!(
|
||||
"complete -c worklane -n '__worklane_command_is {command}' -l {flag} \\\n \
|
||||
-x -a '(worklane ls --ids)'"
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let relation_kinds = RelationKind::ALL
|
||||
.iter()
|
||||
.map(|kind| kind.flag())
|
||||
@@ -207,17 +262,19 @@ complete -c worklane \
|
||||
-n '__worklane_first_arg_of {ticket_commands}; or __worklane_second_arg_of {ticket_second_commands}' \
|
||||
-a '(worklane ls --ids)'
|
||||
|
||||
# `relate` takes its targets as option values, so they are completed by flag rather
|
||||
# than by position.
|
||||
complete -c worklane -n '__worklane_command_is relate' {ticket_flags} \
|
||||
-x -a '(worklane ls --ids)'
|
||||
# The options whose value is a ticket, one rule per command so that a flag is offered
|
||||
# only under the command that has it. `relate` takes its three targets this way rather
|
||||
# than by position, and `chown --clear` names the ticket in the flag because with no user
|
||||
# to give there is no second positional to put it in. Its `--clear` is scoped like every
|
||||
# other: `set` has one that takes a field name, which clap already offers.
|
||||
{ticket_flags}
|
||||
|
||||
# `--clear` is the one flag here whose first value is not a ticket, so it is not in
|
||||
# `TICKET_FLAGS`: it takes the kind and then the target, and offering a board listing where
|
||||
# the kind goes would be offering values it refuses. The kinds come from `RelationKind`
|
||||
# rather than being spelled again. The target gets no rule at all, deliberately: fish
|
||||
# completes the value after the flag, and the case this flag exists for is a target whose
|
||||
# ticket is gone, which no listing of the board can offer.
|
||||
# `relate --clear` is the one `--clear` whose first value is not a ticket, which is why
|
||||
# that pair is not in `TICKET_FLAGS`: it takes the kind and then the target, and offering a
|
||||
# board listing where the kind goes would be offering values it refuses. The kinds come
|
||||
# from `RelationKind` rather than being spelled again. The target gets no rule at all,
|
||||
# deliberately: fish completes the value after the flag, and the case this flag exists for
|
||||
# is a target whose ticket is gone, which no listing of the board can offer.
|
||||
complete -c worklane -n '__worklane_command_is relate' -l clear -x -a '{relation_kinds}'
|
||||
|
||||
# Campaigns, from `campaign ls --ids`, in the three places one is named: `assign`'s first
|
||||
@@ -247,11 +304,6 @@ complete -c worklane -n '__worklane_command_is ls' {campaign_flags} \
|
||||
# here are the values it refuses.
|
||||
complete -c worklane -n '{tag_nested}' -a '(worklane tags | cut -f1,3)'
|
||||
|
||||
# `chown --clear` names the ticket in the flag too, since with no user to give there is
|
||||
# no second positional to put it in. Scoped to `chown`, unlike the rule above: `set`
|
||||
# has a `--clear` of its own that takes a field name, and clap already offers those.
|
||||
complete -c worklane -n '__worklane_command_is chown' -l clear -x -a '(worklane ls --ids)'
|
||||
|
||||
# clap emits the statuses for `mv --status`, which is an option, but the fish generator
|
||||
# emits nothing for the possible values of a positional. So the one place a status is
|
||||
# positional needs them listed, and the same goes for the shell below.
|
||||
@@ -489,6 +541,70 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// One line, split the way the prompt splits it, and the argument the cursor is in.
|
||||
///
|
||||
/// The splitter is the prompt's own, so a row here states a line as a reader types it
|
||||
/// rather than as a hand-written argument vector, and the two cannot come apart.
|
||||
fn at_cursor(line: &str) -> bool {
|
||||
let split = crate::split::split_line(line, line.len());
|
||||
ticket_argument(&split.args, split.cursor_arg)
|
||||
}
|
||||
|
||||
/// Every position a ticket is taken in, as the line that reaches it.
|
||||
#[test]
|
||||
fn a_ticket_is_recognised_in_every_position_a_command_takes_one() {
|
||||
for line in [
|
||||
// The first positional, begun and half typed.
|
||||
"show ",
|
||||
"mv 1b7",
|
||||
"comment ",
|
||||
"check ",
|
||||
// The second, where the first argument is a user or a campaign.
|
||||
"chown alice ",
|
||||
"assign v1 1b7",
|
||||
// The three of `relate`'s flags, and `chown --clear`, which names the ticket
|
||||
// in the flag because there is no user to give.
|
||||
"relate 1b78a24 --blocked-by ",
|
||||
"relate 1b78a24 --regression-of 417",
|
||||
"relate 1b78a24 --relates-to ",
|
||||
"chown --clear ",
|
||||
] {
|
||||
assert!(
|
||||
at_cursor(line),
|
||||
"`{line}` takes a ticket at the cursor and was not offered one"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// And every position that takes something else, which is the half a naive version
|
||||
/// gets wrong.
|
||||
#[test]
|
||||
fn nothing_is_recognised_where_the_argument_is_not_a_ticket() {
|
||||
for line in [
|
||||
// The verb, on an empty line and on a half typed one.
|
||||
"",
|
||||
"m",
|
||||
// `chown`'s first argument is a user and `assign`'s is a campaign.
|
||||
"chown ",
|
||||
"assign ",
|
||||
// `ls` takes a status and `campaign show` a campaign.
|
||||
"ls ",
|
||||
"campaign show ",
|
||||
// The two `--clear` flags that are spelled like `chown`'s and take something
|
||||
// else: a relation kind, and a field name.
|
||||
"relate 1b78a24 --clear ",
|
||||
"set 1b78a24 --clear ",
|
||||
// `relate --clear`'s second value is a ticket the board no longer holds, which
|
||||
// is what the flag exists for, so nothing on the board is offered there.
|
||||
"relate 1b78a24 --clear blocked-by ",
|
||||
// One past the ticket, which is `mv`'s status and `comment`'s body.
|
||||
"mv 1b78a24 ",
|
||||
"comment 1b78a24 the ",
|
||||
] {
|
||||
assert!(!at_cursor(line), "`{line}` was offered a ticket where none goes");
|
||||
}
|
||||
}
|
||||
|
||||
/// **Every rule naming an option has to say which command it belongs to.** A bare
|
||||
/// `complete -c worklane -l tag` tells fish the whole tool takes `--tag`, so
|
||||
/// `worklane init --<TAB>` offered six options that only `relate` and `ls` have. This
|
||||
@@ -522,6 +638,7 @@ mod tests {
|
||||
.chain(TICKET_SECOND_COMMANDS.iter())
|
||||
.chain(CAMPAIGN_COMMANDS.iter())
|
||||
.copied()
|
||||
.chain(TICKET_FLAGS.iter().map(|(command, _)| *command))
|
||||
.chain(TAG_FLAGS.iter().map(|(command, _)| *command));
|
||||
|
||||
for name in top {
|
||||
@@ -545,7 +662,9 @@ mod tests {
|
||||
/// bare search for `-l clear` cannot tell them apart, which is what this used to do.
|
||||
#[test]
|
||||
fn each_clear_flag_is_completed_for_its_own_command() {
|
||||
let script = fish_dynamic();
|
||||
// Continuations joined first: a rule is one logical line, and the generated ones
|
||||
// put the flag and its values on either side of a trailing backslash.
|
||||
let script = fish_dynamic().replace("\\\n", " ");
|
||||
let cli = command();
|
||||
|
||||
let rule_for = |name: &str| {
|
||||
@@ -558,6 +677,7 @@ mod tests {
|
||||
&& line.contains(&scope)
|
||||
})
|
||||
.unwrap_or_else(|| panic!("no --clear rule for {name}:\n{script}"))
|
||||
.to_string()
|
||||
};
|
||||
|
||||
let has_clear = |name: &str| {
|
||||
@@ -584,26 +704,41 @@ mod tests {
|
||||
"tickets offered where the kind goes: {relate}"
|
||||
);
|
||||
|
||||
// `set --clear` takes a field name, which clap already offers, and `relate --clear`
|
||||
// takes a kind. Only `chown`'s names a ticket, so only that pair is in the table.
|
||||
assert!(
|
||||
!TICKET_FLAGS.contains(&"clear"),
|
||||
"--clear in TICKET_FLAGS would offer tickets to `set --clear`, which takes a field"
|
||||
!TICKET_FLAGS.contains(&("set", "clear")),
|
||||
"`set --clear` in TICKET_FLAGS would offer tickets where a field name goes"
|
||||
);
|
||||
assert!(
|
||||
!TICKET_FLAGS.contains(&("relate", "clear")),
|
||||
"`relate --clear` in TICKET_FLAGS would offer tickets where the kind goes"
|
||||
);
|
||||
assert!(
|
||||
TICKET_FLAGS.contains(&("chown", "clear")),
|
||||
"`chown --clear` names the ticket in the flag, so it belongs in TICKET_FLAGS"
|
||||
);
|
||||
}
|
||||
|
||||
/// The flags completed as tickets have to be `relate`'s actual flags, or the rule
|
||||
/// completes an option nothing accepts.
|
||||
/// Each flag completed as a ticket has to be an option its own command actually takes,
|
||||
/// or the rule completes something nothing accepts.
|
||||
///
|
||||
/// The command is half of what is checked, which is what the pairs bought: a flat list
|
||||
/// could only be walked against one command, and `--clear` is spelled the same on three.
|
||||
#[test]
|
||||
fn every_ticket_flag_is_a_real_option() {
|
||||
let relate = command()
|
||||
.find_subcommand("relate")
|
||||
.expect("relate exists")
|
||||
.clone();
|
||||
let known: Vec<String> = relate
|
||||
.get_arguments()
|
||||
.filter_map(|arg| arg.get_long().map(str::to_string))
|
||||
.collect();
|
||||
for flag in TICKET_FLAGS {
|
||||
assert!(known.contains(&flag.to_string()), "`relate` has no --{flag}");
|
||||
let cli = command();
|
||||
|
||||
for (name, flag) in TICKET_FLAGS {
|
||||
let subcommand = cli
|
||||
.find_subcommand(name)
|
||||
.unwrap_or_else(|| panic!("no such subcommand: {name}"));
|
||||
assert!(
|
||||
subcommand
|
||||
.get_arguments()
|
||||
.any(|arg| arg.get_long() == Some(flag)),
|
||||
"`worklane {name}` has no --{flag}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+183
-14
@@ -501,7 +501,18 @@ fn move_ticket_file(
|
||||
/// A target the board does not have warns and allows the move. Refusing there would
|
||||
/// wedge the ticket behind a bookkeeping fault with no way out but `--force`, and a
|
||||
/// dangling uuid is not a dependency.
|
||||
fn check_blockers(worklane_dir: &Path, content: &str, title: &str, target: Status) -> Result<()> {
|
||||
///
|
||||
/// The warning goes through the `sink` rather than through `eprintln!`, which is why a
|
||||
/// helper that says nothing on the happy path takes one at all: this runs from the
|
||||
/// board's command prompt as well as from `main`, and there the process's stderr is the
|
||||
/// alternate screen. The refusal takes its colour from the sink for the same reason.
|
||||
fn check_blockers(
|
||||
worklane_dir: &Path,
|
||||
content: &str,
|
||||
title: &str,
|
||||
target: Status,
|
||||
sink: &mut Sink,
|
||||
) -> Result<()> {
|
||||
let edges: Vec<Relation> = parse_relations(content, title)?
|
||||
.into_iter()
|
||||
.filter(|relation| relation.kind == RelationKind::BlockedBy)
|
||||
@@ -522,15 +533,15 @@ fn check_blockers(worklane_dir: &Path, content: &str, title: &str, target: Statu
|
||||
Some(blocker) if !blocks_move(target, &blocker.status) => {}
|
||||
Some(blocker) => behind.push(format!(
|
||||
" ({}) {} [{}]",
|
||||
color_text(short_id(&blocker.uuid), Color::Red),
|
||||
sink.color(short_id(&blocker.uuid), Color::Red),
|
||||
blocker.title,
|
||||
color_text(&blocker.status, Color::Orange),
|
||||
sink.color(&blocker.status, Color::Orange),
|
||||
)),
|
||||
None => eprintln!(
|
||||
None => sink.warnln(&format!(
|
||||
"Warning: ticket '{}' is blocked by {}, which is not on the board.",
|
||||
title,
|
||||
short_id(&edge.target),
|
||||
),
|
||||
))?,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,8 +555,8 @@ fn check_blockers(worklane_dir: &Path, content: &str, title: &str, target: Statu
|
||||
// next stage is otherwise told nothing about what changed.
|
||||
Err(anyhow!(
|
||||
"Cannot move '{}' to {} while it is blocked by:\n{}\nA ticket cannot move ahead of what it waits on. Use --force (-f) to move it anyway.",
|
||||
color_text(title, Color::Green),
|
||||
color_text(target.as_str(), Color::Orange),
|
||||
sink.color(title, Color::Green),
|
||||
sink.color(target.as_str(), Color::Orange),
|
||||
behind.join("\n"),
|
||||
))
|
||||
}
|
||||
@@ -558,7 +569,11 @@ fn check_blockers(worklane_dir: &Path, content: &str, title: &str, target: Statu
|
||||
///
|
||||
/// Tickets already done or discarded do not hold it up: a dependency that was satisfied
|
||||
/// or abandoned is nobody's plan anymore.
|
||||
fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str) -> Result<()> {
|
||||
///
|
||||
/// The `sink` is here for the colour alone, the rule [`check_blockers`] follows: this
|
||||
/// refusal is drawn by the board as well as printed by the CLI, and a helper that asks
|
||||
/// the process about its stdout answers about a terminal the message is not going to.
|
||||
fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str, sink: &mut Sink) -> Result<()> {
|
||||
let index = RelationIndex::load(worklane_dir)?;
|
||||
|
||||
// Every open dependent, not the first, for the reason `check_blockers` names them
|
||||
@@ -575,9 +590,9 @@ fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str) -> Result<()>
|
||||
.map(|ticket| {
|
||||
format!(
|
||||
" ({}) {} [{}]",
|
||||
color_text(short_id(&ticket.uuid), Color::Red),
|
||||
sink.color(short_id(&ticket.uuid), Color::Red),
|
||||
ticket.title,
|
||||
color_text(&ticket.status, Color::Orange),
|
||||
sink.color(&ticket.status, Color::Orange),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
@@ -588,7 +603,7 @@ fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str) -> Result<()>
|
||||
|
||||
Err(anyhow!(
|
||||
"Cannot discard '{}' while open tickets are blocked by it:\n{}\nUse --force (-f) to discard it anyway.",
|
||||
color_text(title, Color::Green),
|
||||
sink.color(title, Color::Green),
|
||||
waiting.join("\n"),
|
||||
))
|
||||
}
|
||||
@@ -694,8 +709,10 @@ pub fn cmd_mv(args: &MvArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
// it.
|
||||
if !force {
|
||||
match discarding {
|
||||
true => check_dependents(&worklane_dir, &parse_ticket_field(&resolved, "ID"), &title)?,
|
||||
false => check_blockers(&worklane_dir, &resolved, &title, *target)?,
|
||||
true => {
|
||||
check_dependents(&worklane_dir, &parse_ticket_field(&resolved, "ID"), &title, sink)?
|
||||
}
|
||||
false => check_blockers(&worklane_dir, &resolved, &title, *target, sink)?,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2231,6 +2248,12 @@ mod sink_tests {
|
||||
}
|
||||
|
||||
fn ticket(dir: &Path, status: &str, uuid: &str) {
|
||||
ticket_with(dir, status, uuid, "");
|
||||
}
|
||||
|
||||
/// The same ticket with `extra` appended, for a test about a section the plain
|
||||
/// fixture does not carry.
|
||||
fn ticket_with(dir: &Path, status: &str, uuid: &str, extra: &str) {
|
||||
fs::write(
|
||||
dir.join(status).join(format!("{}_ticket.md", uuid)),
|
||||
format!(
|
||||
@@ -2246,14 +2269,31 @@ mod sink_tests {
|
||||
- **Tags**: _None_\n\
|
||||
- **Owner**: alice\n\
|
||||
- **Created At**: 2026-08-21 02:10:17\n\
|
||||
- **Status**: {status}\n",
|
||||
- **Status**: {status}\n\
|
||||
{extra}",
|
||||
u = uuid,
|
||||
status = status,
|
||||
extra = extra,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// A project directory with a real board under it, for a handler that takes the path
|
||||
/// a shell would have been run from and walks up from it. [`temp_worklane`] is the
|
||||
/// board itself, which is what a handler already handed one takes.
|
||||
///
|
||||
/// A [`Fixture`], so the tree goes when the test does whether it passed or not, which
|
||||
/// is the rule for a unit-test fixture in this crate.
|
||||
fn temp_project() -> Fixture {
|
||||
let root = Fixture::new("wl-sink-project").child("project");
|
||||
let dir = root.join(".worklane");
|
||||
for status in status_dirs() {
|
||||
fs::create_dir_all(dir.join(status)).unwrap();
|
||||
}
|
||||
root
|
||||
}
|
||||
|
||||
/// A handler writes through the sink it is handed, and a caller can read the bytes
|
||||
/// back without a terminal or a real stdout.
|
||||
#[test]
|
||||
@@ -2314,4 +2354,133 @@ mod sink_tests {
|
||||
|
||||
fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
/// The aside `check_blockers` writes for a blocker the board does not hold goes to
|
||||
/// the sink's warnings, and not into what the caller collects as the answer.
|
||||
///
|
||||
/// Two destinations because the CLI's two are two: this has always been stderr and
|
||||
/// the answer stdout, and the board reads the answer back to draw it, so a warning
|
||||
/// folded into it would be indistinguishable from what the command said. What it
|
||||
/// must not be is an `eprintln!`, which reaches the process's own stderr — under the
|
||||
/// board that is the alternate screen with the columns on it.
|
||||
#[test]
|
||||
fn a_dangling_blocker_warns_through_the_sink() {
|
||||
let root = temp_project();
|
||||
let dir = root.join(".worklane");
|
||||
ticket_with(
|
||||
&dir,
|
||||
"backlog",
|
||||
"aaaa1111-aaaa-4000-8000-000000000000",
|
||||
"\n## Relations\n\n- blocked by cccc3333-cccc-4000-8000-000000000000\n",
|
||||
);
|
||||
|
||||
let args = MvArgs {
|
||||
ticket: "aaaa1111".to_string(),
|
||||
status: Status::Committed,
|
||||
force: false,
|
||||
actor: None,
|
||||
actor_from_git: false,
|
||||
reason: None,
|
||||
};
|
||||
|
||||
let mut buf = Vec::new();
|
||||
let warned = {
|
||||
let mut sink = Sink::buffer(&mut buf);
|
||||
// A dangling uuid is a bookkeeping fault rather than a dependency, so the
|
||||
// move happens and the warning is the whole of what is said about it.
|
||||
cmd_mv(&args, &root, &mut sink).unwrap();
|
||||
sink.warnings()
|
||||
};
|
||||
|
||||
assert!(
|
||||
warned.contains("not on the board"),
|
||||
"the warning did not reach the sink:\n{warned}"
|
||||
);
|
||||
|
||||
let out = String::from_utf8(buf).unwrap();
|
||||
assert!(out.contains("Moved ticket"), "the move said nothing:\n{out}");
|
||||
assert!(
|
||||
!out.contains("not on the board"),
|
||||
"the warning landed in the answer:\n{out}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A sink whose warnings have a stream of their own holds nothing back: those bytes
|
||||
/// are gone to stderr, which is what [`Sink::std`] is for. Read back as empty rather
|
||||
/// than as a copy, since a caller acting on both would report the warning twice.
|
||||
#[test]
|
||||
fn a_sink_with_a_stream_for_its_warnings_holds_none() {
|
||||
let mut answer = Vec::new();
|
||||
let mut aside = Vec::new();
|
||||
let mut sink = Sink::with_warnings(Box::new(&mut answer), Box::new(&mut aside), false);
|
||||
|
||||
sink.warnln("Warning: a blocker nothing holds").unwrap();
|
||||
sink.writeln("Moved ticket").unwrap();
|
||||
assert_eq!(sink.warnings(), "", "a warning with a stream was held as well as sent");
|
||||
sink.flush().unwrap();
|
||||
drop(sink);
|
||||
|
||||
assert_eq!(String::from_utf8(aside).unwrap(), "Warning: a blocker nothing holds\n");
|
||||
assert_eq!(String::from_utf8(answer).unwrap(), "Moved ticket\n");
|
||||
}
|
||||
|
||||
/// No handler and no helper reaches a print macro. Nowhere in `src`, not only in
|
||||
/// this file.
|
||||
///
|
||||
/// The caller chooses where a command's words go — `main` its own stdout and stderr,
|
||||
/// the board a buffer it reads back and draws — and a `print!` writes to the
|
||||
/// process's streams instead, which under the board is the alternate screen with the
|
||||
/// columns on it. That is c680e24: one `eprintln!` in `check_blockers` outlived
|
||||
/// fa5662a because a helper had no sink to reach, and ratatui does not repaint a cell
|
||||
/// it believes is unchanged, so the fragment stayed on the columns until something
|
||||
/// else redrew them.
|
||||
///
|
||||
/// Over the directory rather than over a list of `include_str!`s, so a module added
|
||||
/// tomorrow is scanned the day it is added: a list is what the fifty-first print site
|
||||
/// hides behind. Each file is cut at its own test module, and comments are dropped,
|
||||
/// because the docs around here name these macros to say why they are not called.
|
||||
#[test]
|
||||
fn no_handler_or_helper_reaches_a_print_macro() {
|
||||
// The one site outside a test module that may, and it is not output: the fixture
|
||||
// guard naming a directory it was told to leave behind, for the person reading the
|
||||
// run rather than for anything collecting an answer.
|
||||
let allowed = "eprintln!(\"kept fixture {}\", self.root.display());";
|
||||
|
||||
let mut printing: Vec<String> = Vec::new();
|
||||
for entry in fs::read_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/src")).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.extension().and_then(|ext| ext.to_str()) != Some("rs") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let source = fs::read_to_string(&path).unwrap();
|
||||
let name = path.file_name().unwrap().to_string_lossy().to_string();
|
||||
printing.extend(
|
||||
body_of(&source)
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.starts_with("//") && *line != allowed)
|
||||
.filter(|line| {
|
||||
["print!(", "println!(", "eprint!(", "eprintln!("]
|
||||
.iter()
|
||||
.any(|macro_call| line.contains(macro_call))
|
||||
})
|
||||
.map(|line| format!("{name}: {line}")),
|
||||
);
|
||||
}
|
||||
|
||||
assert!(
|
||||
printing.is_empty(),
|
||||
"a print macro writes to the process's own streams, which under the board is \
|
||||
the alternate screen. Take a `Sink` and use `writeln` for an answer or \
|
||||
`warnln` for an aside:\n{printing:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A file's lines up to its test module, which in this crate is the only inline
|
||||
/// `mod` at column 0. A file's own assertions are allowed to name a macro the file
|
||||
/// may not call, this test's own body first among them.
|
||||
fn body_of(source: &str) -> impl Iterator<Item = &str> {
|
||||
source
|
||||
.lines()
|
||||
.take_while(|line| !(line.starts_with("mod ") && line.ends_with(" {")))
|
||||
}
|
||||
}
|
||||
|
||||
+383
-16
@@ -28,6 +28,7 @@ use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Tabs, Wrap};
|
||||
|
||||
use crate::campaign::{CAMPAIGNS_DIR, CampaignIndex, Standing};
|
||||
use crate::command::{Cli, Command};
|
||||
use crate::completions::ticket_argument;
|
||||
use crate::history::{HistoryPart, history_parts, history_root, read_history};
|
||||
use crate::split::{Unclosed, split_line};
|
||||
use crate::tag::{NO_ANNOTATION, TAGS_FILE, TagIndex};
|
||||
@@ -748,11 +749,11 @@ impl Prompt {
|
||||
/// `esc` and `enter`: those two are the mode's rather than the line's, and they are
|
||||
/// answered by [`Board::prompt_key`] before it gets here.
|
||||
///
|
||||
/// Left, right, home, end, backspace and `ctrl-w` behave as they do in a shell. There
|
||||
/// is no `tab`: suggesting the selected ticket is 00a14e7, and until then it is a key
|
||||
/// that must not reach the project tabs. Every other control combination lands on the
|
||||
/// last arm and does nothing, which is what stops `ctrl-d` reaching the action bound
|
||||
/// to `d`.
|
||||
/// Left, right, home, end, backspace and `ctrl-w` behave as they do in a shell. `tab`
|
||||
/// is not here either: it takes the suggestion, which is the board's rather than the
|
||||
/// line's, since the selected card is what it is made of. Every other control
|
||||
/// combination lands on the last arm and does nothing, which is what stops `ctrl-d`
|
||||
/// reaching the action bound to `d`.
|
||||
fn key(&mut self, key: KeyEvent, control: bool) {
|
||||
match key.code {
|
||||
KeyCode::Left if !control => self.cursor = self.left_of(),
|
||||
@@ -763,15 +764,22 @@ impl Prompt {
|
||||
// with it. Movement above deliberately does not clear it.
|
||||
KeyCode::Backspace if !control => self.cut(self.left_of()),
|
||||
KeyCode::Char('w') if control => self.cut(self.word_start()),
|
||||
KeyCode::Char(typed) if !control => {
|
||||
self.line.insert(self.cursor, typed);
|
||||
self.cursor += typed.len_utf8();
|
||||
self.refused = None;
|
||||
}
|
||||
KeyCode::Char(typed) if !control => self.insert(typed.encode_utf8(&mut [0; 4])),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Put `text` into the line at the cursor and leave the cursor after it, which is what
|
||||
/// typing it would have done.
|
||||
///
|
||||
/// The message about the last enter goes with it, for the reason every other edit takes
|
||||
/// it away: it was about a line that is no longer on the row.
|
||||
fn insert(&mut self, text: &str) {
|
||||
self.line.insert_str(self.cursor, text);
|
||||
self.cursor += text.len();
|
||||
self.refused = None;
|
||||
}
|
||||
|
||||
/// The offset one character to the left of the cursor, or the cursor itself at the
|
||||
/// start of the line. By characters, so a cursor never lands inside one.
|
||||
fn left_of(&self) -> usize {
|
||||
@@ -2355,6 +2363,9 @@ impl Board {
|
||||
// the whole board rather than the prompt alone.
|
||||
KeyCode::Up if !control => self.recall_back(),
|
||||
KeyCode::Down if !control => self.recall_forward(),
|
||||
// The mode's too, and never the tabs': every key belongs to the prompt while it
|
||||
// is open, and what this one takes is made of the selected card.
|
||||
KeyCode::Tab if !control => self.accept_suggestion(),
|
||||
_ => {
|
||||
if let Some(prompt) = &mut self.prompt {
|
||||
prompt.key(key, control);
|
||||
@@ -2365,6 +2376,64 @@ impl Board {
|
||||
true
|
||||
}
|
||||
|
||||
/// The rest of the selected card's short id where the line is naming a ticket, or
|
||||
/// nothing anywhere else.
|
||||
///
|
||||
/// Derived on every call rather than held on the [`Prompt`], so it cannot come to
|
||||
/// describe a line that has since been edited or a card the selection has left: what
|
||||
/// the row draws and what `tab` takes are one answer, asked twice.
|
||||
///
|
||||
/// Where a ticket goes is [`ticket_argument`]'s, off the tables the fish completions
|
||||
/// are generated from. A copy of those positions here would go wrong the next time a
|
||||
/// command grew a ticket argument, and the test that keeps them honest against clap
|
||||
/// would not notice.
|
||||
///
|
||||
/// Three things have to hold, and each is its own answer to the reader:
|
||||
///
|
||||
/// - **The cursor is at the end of the line.** The suggestion is drawn after it and
|
||||
/// `tab` inserts it there, so with the line continuing past the cursor both would be
|
||||
/// in the middle of something already typed. That is the rule a shell's own
|
||||
/// suggestion keeps.
|
||||
/// - **A card is selected.** On the frame there is none, and the frame's own id is a
|
||||
/// campaign or a tag rather than a ticket.
|
||||
/// - **What is already typed is still a prefix of the id.** A suggestion that no longer
|
||||
/// matches the argument under it describes nothing, and what is left is empty once
|
||||
/// the whole id is typed.
|
||||
pub fn suggestion(&self) -> Option<&str> {
|
||||
let prompt = self.prompt.as_ref()?;
|
||||
if prompt.cursor != prompt.line.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let id = self.current().selected()?.ticket.id.as_str();
|
||||
let split = split_line(&prompt.line, prompt.cursor);
|
||||
if !ticket_argument(&split.args, split.cursor_arg) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Empty where the argument has been opened and nothing of it is behind the cursor,
|
||||
// which is the whole id offered.
|
||||
let typed = match split.at_new_arg {
|
||||
true => "",
|
||||
false => split.args[split.cursor_arg].as_str(),
|
||||
};
|
||||
|
||||
id.strip_prefix(typed).filter(|rest| !rest.is_empty())
|
||||
}
|
||||
|
||||
/// `tab`: take the suggestion into the line, or do nothing where there is none.
|
||||
///
|
||||
/// The whole board rather than the prompt alone, for the reason the recall walk is:
|
||||
/// the suggestion is made of the selected card and the line is only where it lands.
|
||||
fn accept_suggestion(&mut self) {
|
||||
let Some(rest) = self.suggestion().map(str::to_string) else {
|
||||
return;
|
||||
};
|
||||
if let Some(prompt) = &mut self.prompt {
|
||||
prompt.insert(&rest);
|
||||
}
|
||||
}
|
||||
|
||||
/// `up`: one line further back, or the newest line when the reader is still on their
|
||||
/// own.
|
||||
///
|
||||
@@ -2535,14 +2604,22 @@ impl Board {
|
||||
.filter(|(uuid, _)| !is_unknown_value(uuid));
|
||||
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
let outcome = {
|
||||
let (outcome, warned) = {
|
||||
let mut sink = Sink::buffer(&mut buffer);
|
||||
crate::dispatch(command, &root, &mut sink).and_then(|()| sink.flush())
|
||||
let outcome = crate::dispatch(command, &root, &mut sink).and_then(|()| sink.flush());
|
||||
// Read on both outcomes and reported on both: a `mv` that warns about a
|
||||
// dangling blocker and is then refused by a real one wrote the warning
|
||||
// first, and dropping it there would lose the half that says why the
|
||||
// refusal names one blocker and the ticket records two.
|
||||
(outcome, sink.warnings())
|
||||
};
|
||||
// The warning ahead of the answer, the order the handler wrote them in and the
|
||||
// order a shell shows the two streams in.
|
||||
//
|
||||
// Plain by construction, since the sink is: stripped anyway, because an escape
|
||||
// drawn into a ratatui paragraph is printed rather than obeyed, and this is the
|
||||
// one seam where a handler's bytes become a frame.
|
||||
let said = without_escapes(&String::from_utf8_lossy(&buffer))
|
||||
let said = without_escapes(&format!("{warned}{}", String::from_utf8_lossy(&buffer)))
|
||||
.trim_end()
|
||||
.to_string();
|
||||
|
||||
@@ -2556,7 +2633,14 @@ impl Board {
|
||||
let moved = held.and_then(|(uuid, id)| self.reselect(&uuid, &id, screen));
|
||||
|
||||
match outcome {
|
||||
Err(err) => self.notice = Some(Notice::failed(error_lines(&err))),
|
||||
// The warning above the refusal, the order they were written in.
|
||||
Err(err) => {
|
||||
let failure = match said.is_empty() {
|
||||
true => error_lines(&err),
|
||||
false => format!("{said}\n{}", error_lines(&err)),
|
||||
};
|
||||
self.notice = Some(Notice::failed(failure));
|
||||
}
|
||||
Ok(()) => {
|
||||
self.prompt = None;
|
||||
let words = match said.is_empty() {
|
||||
@@ -4539,7 +4623,7 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
// and is asked first: an input cannot be covered, and it is the newest of the three
|
||||
// things that can hold the row. Only one of the two prompts can be open at a time.
|
||||
if let Some(prompt) = &board.prompt {
|
||||
draw_prompt(frame, prompt, area);
|
||||
draw_prompt(frame, prompt, board.suggestion(), area);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4745,7 +4829,14 @@ const PROMPT_OPENING: &str = " :";
|
||||
///
|
||||
/// `run` and not `check`: enter hands the line to the same handler the shell reaches, and
|
||||
/// the row has to say which of the two it is about to do.
|
||||
fn draw_prompt(frame: &mut Frame, prompt: &Prompt, area: Rect) {
|
||||
///
|
||||
/// The suggestion is drawn after the line in grey, which is what the palette already spends
|
||||
/// on a value that is not one: it is not in the line until `tab` puts it there, and the
|
||||
/// reader has to be able to tell the two apart at a glance. It takes what the line leaves
|
||||
/// of the field rather than a field of its own, so a long command loses the offer instead
|
||||
/// of pushing the keys off the row. The terminal cursor sits on its first cell, which is
|
||||
/// where the cursor already was: what is under a cursor is still what will be typed over.
|
||||
fn draw_prompt(frame: &mut Frame, prompt: &Prompt, suggestion: Option<&str>, area: Rect) {
|
||||
let keys = key_hints(&[("↵", "run"), ("esc", "cancel")]);
|
||||
let spent: usize = PROMPT_OPENING.chars().count()
|
||||
+ KEY_GAP.chars().count()
|
||||
@@ -4760,6 +4851,18 @@ fn draw_prompt(frame: &mut Frame, prompt: &Prompt, area: Rect) {
|
||||
let (visible, at) = prompt_window(&prompt.line, prompt.cursor, room);
|
||||
|
||||
let mut spans = vec![Span::raw(format!("{PROMPT_OPENING}{visible}"))];
|
||||
|
||||
// Only ever drawn where the cursor is at the end of the line, which is what `visible`
|
||||
// then ends at, so this follows the cursor rather than landing in front of the tail of
|
||||
// a command.
|
||||
if let Some(rest) = suggestion {
|
||||
let left = room.saturating_sub(visible.chars().count());
|
||||
let shown: String = rest.chars().take(left).collect();
|
||||
if !shown.is_empty() {
|
||||
spans.push(Span::styled(shown, Style::default().fg(Color::Grey.into())));
|
||||
}
|
||||
}
|
||||
|
||||
match &prompt.refused {
|
||||
Some(message) => spans.push(Span::styled(
|
||||
format!("{KEY_GAP}{message}"),
|
||||
@@ -8226,6 +8329,85 @@ approach";
|
||||
);
|
||||
}
|
||||
|
||||
/// A warning comes back with the answer instead of going to stderr, which under the
|
||||
/// board is the alternate screen: `eprintln!` drew the line straight onto the
|
||||
/// columns, and ratatui does not repaint a cell it believes is unchanged, so the
|
||||
/// fragment stayed there until something else redrew them. That is c680e24.
|
||||
///
|
||||
/// Asserted on the notice for the reason `the_footer_reports_the_handlers_own_words`
|
||||
/// is: the words being *there* is what says they were collected rather than printed.
|
||||
#[test]
|
||||
fn a_warning_is_reported_with_the_answer_rather_than_printed() {
|
||||
let (root, mut board) = runnable();
|
||||
write_ticket(
|
||||
&root.join(".worklane"),
|
||||
"backlog",
|
||||
WAITER,
|
||||
"The waiter",
|
||||
&blocked_by(ELSEWHERE),
|
||||
);
|
||||
|
||||
// A dangling blocker is a bookkeeping fault rather than a dependency, so the
|
||||
// move happens and the warning is the whole of what is said about it.
|
||||
run_line(&mut board, "mv bbbbbbb --status committed");
|
||||
let notice = board.notice.as_ref().expect("the command said nothing");
|
||||
assert!(!notice.failed, "a dangling blocker refused the move: {}", notice.text);
|
||||
assert_eq!(column_of(&board, "The waiter"), Some("committed"));
|
||||
|
||||
let warning = notice.text.find("not on the board");
|
||||
let answer = notice.text.find("Moved ticket");
|
||||
assert!(warning.is_some(), "the warning never reached the board: {}", notice.text);
|
||||
assert!(
|
||||
warning < answer,
|
||||
"the aside was not put above the answer it came before: {}",
|
||||
notice.text
|
||||
);
|
||||
|
||||
let screen = screen_text(&board);
|
||||
for line in notice.lines() {
|
||||
assert!(screen.contains(line.trim()), "`{line}` never reached the frame:\n{screen}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Warned and then refused, which is one blocker the board does not hold and one it
|
||||
/// does. Both are reported: the refusal names the blocker in the way and the ticket
|
||||
/// records two, so dropping the aside is dropping the answer to why.
|
||||
#[test]
|
||||
fn a_refused_move_keeps_the_warning_that_came_before_it() {
|
||||
let (root, mut board) = runnable();
|
||||
write_ticket(
|
||||
&root.join(".worklane"),
|
||||
"backlog",
|
||||
WAITER,
|
||||
"The waiter",
|
||||
// `Alpha first`, which `runnable` leaves in the backlog: a blocker a ticket
|
||||
// may stand level with and not move ahead of.
|
||||
&format!(
|
||||
"\n## Relations\n\n- blocked by {ELSEWHERE}\n\
|
||||
- blocked by 11111111-0000-4000-8000-000000000000\n"
|
||||
),
|
||||
);
|
||||
|
||||
run_line(&mut board, "mv bbbbbbb --status committed");
|
||||
let notice = board.notice.as_ref().expect("the refusal said nothing");
|
||||
assert!(notice.failed, "a refused move was reported as a success");
|
||||
assert_eq!(
|
||||
column_of(&board, "The waiter"),
|
||||
Some("backlog"),
|
||||
"the move happened anyway"
|
||||
);
|
||||
|
||||
let warning = notice.text.find("not on the board");
|
||||
let refusal = notice.text.find("Cannot move");
|
||||
assert!(
|
||||
warning.is_some(),
|
||||
"the warning was dropped on the error path: {}",
|
||||
notice.text
|
||||
);
|
||||
assert!(refusal.is_some(), "the refusal was dropped: {}", notice.text);
|
||||
assert!(warning < refusal, "the aside came after the refusal: {}", notice.text);
|
||||
}
|
||||
|
||||
/// A handler that errors leaves the prompt open with the line exactly as it was: the
|
||||
/// usual cause is an ambiguous id, and the fix is two more characters rather than the
|
||||
/// whole line retyped from `:`.
|
||||
@@ -8953,6 +9135,191 @@ approach";
|
||||
assert_eq!(prompt_line(&board), Some("ls backlog"), "the walk did not happen");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the suggestion --
|
||||
|
||||
/// The id of the card the selection is on, which is what every suggestion is made of.
|
||||
fn selected_id(board: &Board) -> String {
|
||||
board.selected().expect("a card is selected").ticket.id.clone()
|
||||
}
|
||||
|
||||
/// Open a fresh prompt, type `line` into it, and answer what is suggested at the end
|
||||
/// of it.
|
||||
fn suggested(board: &mut Board, line: &str) -> Option<String> {
|
||||
board.open_prompt();
|
||||
type_line(board, line);
|
||||
let rest = board.suggestion().map(str::to_string);
|
||||
board.prompt = None;
|
||||
rest
|
||||
}
|
||||
|
||||
/// Every position a command takes a ticket in, driven as a line typed at the prompt.
|
||||
///
|
||||
/// The whole id where the argument has been opened and nothing typed into it, which is
|
||||
/// the ordinary case: the reader has the card in front of them and presses tab.
|
||||
#[test]
|
||||
fn the_selected_id_is_suggested_wherever_a_ticket_argument_goes() {
|
||||
let (_root, mut board) = runnable();
|
||||
let id = selected_id(&board);
|
||||
|
||||
for line in [
|
||||
// The first positional.
|
||||
"show ",
|
||||
"mv ",
|
||||
"comment ",
|
||||
// The second, which is where `chown` and `assign` put it on purpose.
|
||||
"chown alice ",
|
||||
"assign v1 ",
|
||||
// `relate`'s three flags, and `chown --clear`, which names the ticket in the
|
||||
// flag since there is no user to give.
|
||||
"relate 2222222 --blocked-by ",
|
||||
"relate 2222222 --regression-of ",
|
||||
"relate 2222222 --relates-to ",
|
||||
"chown --clear ",
|
||||
] {
|
||||
assert_eq!(
|
||||
suggested(&mut board, line).as_deref(),
|
||||
Some(id.as_str()),
|
||||
"`{line}` takes a ticket and was offered nothing"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// And every position that takes something else, which is the half a version counting
|
||||
/// the first argument alone gets wrong.
|
||||
#[test]
|
||||
fn nothing_is_suggested_where_the_argument_is_not_a_ticket() {
|
||||
let (_root, mut board) = runnable();
|
||||
|
||||
for line in [
|
||||
// The verb itself, empty and half typed.
|
||||
"",
|
||||
"sh",
|
||||
// `chown` takes a user first and `assign` a campaign.
|
||||
"chown ",
|
||||
"assign ",
|
||||
// A status, and a campaign under its own command.
|
||||
"ls ",
|
||||
"campaign show ",
|
||||
// The two `--clear` flags spelled like `chown`'s: a relation kind, and a field.
|
||||
"relate 2222222 --clear ",
|
||||
"set 2222222 --clear ",
|
||||
// And `relate --clear`'s second value, which is a target the board may no
|
||||
// longer hold.
|
||||
"relate 2222222 --clear blocked-by ",
|
||||
// One past the ticket, where `mv` wants a status.
|
||||
"mv 2222222 ",
|
||||
] {
|
||||
assert_eq!(
|
||||
suggested(&mut board, line),
|
||||
None,
|
||||
"`{line}` was offered a ticket where none goes"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A partly typed argument is completed rather than restated, and only while the
|
||||
/// selected id still starts with what is on the row.
|
||||
#[test]
|
||||
fn a_half_typed_argument_is_suggested_only_while_the_id_starts_with_it() {
|
||||
let (_root, mut board) = runnable();
|
||||
let id = selected_id(&board);
|
||||
let head = &id[..3];
|
||||
|
||||
assert_eq!(
|
||||
suggested(&mut board, &format!("show {head}")).as_deref(),
|
||||
Some(&id[3..]),
|
||||
"the part already typed was offered a second time"
|
||||
);
|
||||
// The whole id typed leaves nothing to add, which is not a suggestion of nothing.
|
||||
assert_eq!(suggested(&mut board, &format!("show {id}")), None);
|
||||
// And a prefix the selection does not match describes another ticket entirely.
|
||||
assert_eq!(suggested(&mut board, "show 9"), None);
|
||||
}
|
||||
|
||||
/// Nothing is suggested with no card under the selection: on the frame, where the
|
||||
/// selection is on a campaign or a tag rather than a ticket, and on an empty board.
|
||||
#[test]
|
||||
fn nothing_is_suggested_when_no_card_is_selected() {
|
||||
let (_root, mut board) = runnable();
|
||||
board.current_mut().focus = Focus::Frame;
|
||||
assert_eq!(suggested(&mut board, "show "), None, "the frame offered a ticket");
|
||||
|
||||
let empty = board_dir();
|
||||
let mut bare = one_board(&empty);
|
||||
assert_eq!(suggested(&mut bare, "show "), None, "an empty board offered a ticket");
|
||||
}
|
||||
|
||||
/// What the row shows: the suggestion after the cursor, in grey, and not in the line.
|
||||
#[test]
|
||||
fn the_suggestion_is_drawn_after_the_cursor_in_grey_and_is_not_yet_the_line() {
|
||||
let (_root, mut board) = runnable();
|
||||
let id = selected_id(&board);
|
||||
|
||||
board.open_prompt();
|
||||
type_line(&mut board, "show ");
|
||||
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains(&format!(":show {id}")), "the suggestion is not drawn: {row}");
|
||||
assert_eq!(prompt_line(&board), Some("show "), "the suggestion went into the line");
|
||||
|
||||
let (colour, _) = footer_style(&board, SCREEN.width, SCREEN.height, &id);
|
||||
assert_eq!(colour, Color::Grey.into(), "the suggestion is not drawn as a placeholder");
|
||||
|
||||
// The cursor stays where the line ends, which is the first cell of the suggestion.
|
||||
let mut terminal = Terminal::new(TestBackend::new(SCREEN.width, SCREEN.height)).unwrap();
|
||||
terminal.draw(|frame| draw(frame, &board)).unwrap();
|
||||
let at = terminal.get_cursor_position().unwrap();
|
||||
assert_eq!(at.x as usize, PROMPT_OPENING.chars().count() + "show ".len());
|
||||
}
|
||||
|
||||
/// Tab takes it, and any other key leaves the line to say what was typed.
|
||||
#[test]
|
||||
fn tab_takes_the_suggestion_into_the_line_and_another_key_drops_it() {
|
||||
let (_root, mut board) = runnable();
|
||||
let id = selected_id(&board);
|
||||
|
||||
board.open_prompt();
|
||||
type_line(&mut board, "show ");
|
||||
press_prompt(&mut board, KeyCode::Tab);
|
||||
assert_eq!(prompt_line(&board), Some(format!("show {id}").as_str()));
|
||||
|
||||
// Nothing is left to offer once the whole id is on the row, so a second press
|
||||
// cannot double it.
|
||||
press_prompt(&mut board, KeyCode::Tab);
|
||||
assert_eq!(prompt_line(&board), Some(format!("show {id}").as_str()));
|
||||
|
||||
// And a key that takes the line off the id drops the offer rather than holding it.
|
||||
board.prompt = None;
|
||||
board.open_prompt();
|
||||
type_line(&mut board, "show 9");
|
||||
assert_eq!(board.suggestion(), None);
|
||||
press_prompt(&mut board, KeyCode::Tab);
|
||||
assert_eq!(prompt_line(&board), Some("show 9"), "tab typed a suggestion that had gone");
|
||||
}
|
||||
|
||||
/// The swallow contract for the one key this ticket gives the prompt: `tab` is the
|
||||
/// project key on the board and must not be while a command is being typed.
|
||||
#[test]
|
||||
fn tab_in_the_prompt_never_changes_the_project_tab() {
|
||||
let alpha = board_dir();
|
||||
let beta = board_dir();
|
||||
write_ticket(&alpha, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", "");
|
||||
write_ticket(&beta, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", "");
|
||||
|
||||
let mut board = boards(&[("alpha", &alpha), ("beta", &beta)]);
|
||||
assert!(board.tabbed(), "the fixture has nothing to switch between");
|
||||
|
||||
board.open_prompt();
|
||||
// Both with something to take and with nothing, since the arm has to be the
|
||||
// prompt's either way.
|
||||
for line in ["show ", "ls "] {
|
||||
board.prompt = Some(Prompt::default());
|
||||
type_line(&mut board, line);
|
||||
assert!(board.prompt_key(typed(KeyCode::Tab), SCREEN), "tab was not taken");
|
||||
assert_eq!(board.tab, 0, "`{line}` let tab through to the tabs");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ the copy key --
|
||||
|
||||
/// A sink that records what it was handed, standing in for the clipboard.
|
||||
|
||||
+94
-7
@@ -349,12 +349,33 @@ pub fn without_escapes(text: &str) -> String {
|
||||
/// `use_color` is the sink's answer, not a read of [`should_use_colors`]: a process
|
||||
/// whose stdout is a pipe still wants colour when the sink is a buffer a renderer
|
||||
/// will colour itself, and the board wants plain text however the terminal answers.
|
||||
///
|
||||
/// A warning is the second stream, [`Warnings`], for the same reason the first one
|
||||
/// exists: `eprintln!` in a helper reaches the process's stderr, which under the board
|
||||
/// is the alternate screen.
|
||||
pub struct Sink<'a> {
|
||||
writer: Box<dyn Write + 'a>,
|
||||
/// Where a warning goes, which is not where the answer goes.
|
||||
warnings: Warnings<'a>,
|
||||
/// Whether the bytes this sink writes carry colour escapes.
|
||||
pub use_color: bool,
|
||||
}
|
||||
|
||||
/// What a sink does with a warning: the aside a command writes on its way to an
|
||||
/// answer, which the reader wants and no caller parses.
|
||||
///
|
||||
/// Two streams rather than one, because the CLI's two are two: a warning has always
|
||||
/// gone to stderr and the answer to stdout, and [`Sink::std`] cannot fold them
|
||||
/// together without changing what a shell reads. Under the board neither is a stream
|
||||
/// at all — stdout is the alternate screen in raw mode, and so is stderr — so the
|
||||
/// warning is held instead and the board reports it beside the answer.
|
||||
enum Warnings<'a> {
|
||||
/// A writer of its own: `main`'s stderr.
|
||||
Stream(Box<dyn Write + 'a>),
|
||||
/// Kept in memory for a caller that reads it back through [`Sink::warnings`].
|
||||
Held(Vec<u8>),
|
||||
}
|
||||
|
||||
impl<'a> Sink<'a> {
|
||||
/// The process's stdout, coloured by what the terminal wants.
|
||||
///
|
||||
@@ -362,8 +383,14 @@ impl<'a> Sink<'a> {
|
||||
/// command wrote to stdout through `println!`, and this sink writes to the same
|
||||
/// stdout through the same [`paint`].
|
||||
pub fn std() -> Sink<'static> {
|
||||
// Through `new` so the process's stdout is just another writer the sink wraps.
|
||||
Sink::new(Box::new(std::io::stdout()), should_use_colors())
|
||||
// The one sink whose warnings have a stream to go to, and the reason there is a
|
||||
// choice at all: stderr here is a terminal or a pipe the caller is reading, and
|
||||
// holding a warning back would take it off a shell's screen.
|
||||
Sink::with_warnings(
|
||||
Box::new(std::io::stdout()),
|
||||
Box::new(std::io::stderr()),
|
||||
should_use_colors(),
|
||||
)
|
||||
}
|
||||
|
||||
/// An in-memory buffer, plain, for a test or a caller that colours the text
|
||||
@@ -373,15 +400,33 @@ impl<'a> Sink<'a> {
|
||||
/// 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::new(Box::new(target), false)
|
||||
}
|
||||
|
||||
/// Any writer, with the colour decision given. Its warnings are held: a caller
|
||||
/// that named one destination named nowhere for an aside to go, and `main`'s
|
||||
/// stderr is [`Sink::std`]'s alone.
|
||||
pub fn new(writer: Box<dyn Write + 'a>, use_color: bool) -> Sink<'a> {
|
||||
Sink {
|
||||
writer: Box::new(target),
|
||||
use_color: false,
|
||||
writer,
|
||||
warnings: Warnings::Held(Vec::new()),
|
||||
use_color,
|
||||
}
|
||||
}
|
||||
|
||||
/// Any writer, with the colour decision given.
|
||||
pub fn new(writer: Box<dyn Write + 'a>, use_color: bool) -> Sink<'a> {
|
||||
Sink { writer, use_color }
|
||||
/// An answer and the asides that go with it, as two writers, with the colour
|
||||
/// decision given. What [`Sink::std`] is built from, and the only way to a sink
|
||||
/// whose warnings leave it rather than being held.
|
||||
pub fn with_warnings(
|
||||
writer: Box<dyn Write + 'a>,
|
||||
warnings: Box<dyn Write + 'a>,
|
||||
use_color: bool,
|
||||
) -> Sink<'a> {
|
||||
Sink {
|
||||
writer,
|
||||
warnings: Warnings::Stream(warnings),
|
||||
use_color,
|
||||
}
|
||||
}
|
||||
|
||||
/// The writer, for a caller that already knows how to fill it (the completions
|
||||
@@ -404,9 +449,51 @@ impl<'a> Sink<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write `text` and a newline as a warning, the way `eprintln!` did.
|
||||
///
|
||||
/// For the aside a command makes on its way to an answer: something the reader
|
||||
/// should know that does not stop the command and that nothing reading its output
|
||||
/// should have to skip past. A handler reaching `eprintln!` instead wrote straight
|
||||
/// to the process's stderr, which under the board is the alternate screen, and
|
||||
/// ratatui does not repaint a cell it believes is unchanged — so the fragment stayed
|
||||
/// on the columns until something else redrew them.
|
||||
pub fn warnln(&mut self, text: &str) -> Result<()> {
|
||||
match &mut self.warnings {
|
||||
Warnings::Stream(writer) => {
|
||||
writer.write_all(text.as_bytes())?;
|
||||
writer.write_all(b"\n")?;
|
||||
}
|
||||
Warnings::Held(bytes) => {
|
||||
bytes.extend_from_slice(text.as_bytes());
|
||||
bytes.push(b'\n');
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// What this sink held back, for the caller that reads its warnings rather than
|
||||
/// letting them reach a stream.
|
||||
///
|
||||
/// Empty for a sink whose warnings have somewhere of their own to go, since those
|
||||
/// bytes are already gone. Read it after the handler returns and on both outcomes:
|
||||
/// a command that warns and is then refused wrote both, and the warning is the half
|
||||
/// that says why the refusal names one blocker and not two.
|
||||
pub fn warnings(&self) -> String {
|
||||
match &self.warnings {
|
||||
Warnings::Stream(_) => String::new(),
|
||||
Warnings::Held(bytes) => String::from_utf8_lossy(bytes).to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Flush the writer, so a prompt reaches the terminal before a read.
|
||||
///
|
||||
/// Both writers: a warning left in stderr's buffer while the answer reached stdout
|
||||
/// is a warning the reader sees after the sentence it was about, or not at all.
|
||||
pub fn flush(&mut self) -> Result<()> {
|
||||
self.writer.flush()?;
|
||||
if let Warnings::Stream(writer) = &mut self.warnings {
|
||||
writer.flush()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+14
-3
@@ -906,6 +906,11 @@ fn mv_does_not_check_the_blockers_on_a_no_op() {
|
||||
|
||||
/// A dangling target is a bookkeeping fault, not a dependency. Refusing there would
|
||||
/// wedge the ticket with no way out but `--force`.
|
||||
///
|
||||
/// The stderr is asserted whole rather than searched, and that is the point of the
|
||||
/// assertion: c680e24 moved this warning off `eprintln!` and onto the sink's second
|
||||
/// stream so the board could collect it, and a shell has to go on reading the line it
|
||||
/// always read, on the stream it always read it from.
|
||||
#[test]
|
||||
fn mv_warns_and_allows_when_a_blocker_is_not_on_the_board() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
@@ -920,10 +925,16 @@ fn mv_warns_and_allows_when_a_blocker_is_not_on_the_board() {
|
||||
|
||||
let out = move_ticket(&temp, "aaaa1111", "committed", false);
|
||||
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&out.stderr),
|
||||
"Warning: ticket 'Gated Task' is blocked by bbbb222, which is not on the board.\n",
|
||||
"the warning is not the line it was, on the stream it was on"
|
||||
);
|
||||
// And it stays off stdout, which is what a caller reads the answer from.
|
||||
assert!(
|
||||
String::from_utf8_lossy(&out.stderr).contains("not on the board"),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
!String::from_utf8_lossy(&out.stdout).contains("not on the board"),
|
||||
"the warning landed in the answer: {}",
|
||||
String::from_utf8_lossy(&out.stdout)
|
||||
);
|
||||
assert!(worklane.join("committed").join(&filename).exists());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user