(00a14e7) Suggest the selected ticket where a ticket argument goes, and accept it with tab, and bump to 0.33.3

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 in grey and
tab takes it into the line.

Where a ticket goes is completions.rs's answer, through a new
`ticket_argument` over the three tables the fish half is generated from. A
copy of the positions on the board would go wrong the next time a command
grew a ticket argument, and silently, since the tests guarding the first
copy would not read the second.

TICKET_FLAGS holds (command, flag) pairs now, the shape TAG_FLAGS already
had, and the `chown --clear` rule the fish block wrote out by hand is
generated from it. Only chown's --clear names a ticket: relate's takes a
kind and set's a field, and the flag alone cannot tell the three apart.

The suggestion is derived on every call rather than held on the Prompt, so
what the row draws and what tab takes are one answer, and it is offered
only with the cursor at the end of the line, while a card is selected, and
while the id still starts with what is typed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-09-15 15:01:15 +02:00
co-authored by Claude Opus 5
parent a017f9002e
commit c714c73a75
6 changed files with 472 additions and 49 deletions
+168 -33
View File
@@ -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}"
);
}
}
+285 -12
View File
@@ -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.
///
@@ -4554,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;
}
@@ -4760,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()
@@ -4775,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}"),
@@ -9047,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.