Let check and uncheck take several criteria, and bump to 0.16.0
Finishing a ticket means ticking every box, and that was one invocation per box: each one resolved the ticket, spliced one line and rewrote the file. The criterion positional is now variadic, so numbers and substrings mix in a single call, and `all` stands for every criterion on the ticket. `all` is a keyword checked before the text, the way the index already is, so a criterion whose own words include "all" is reached by its number or by a longer substring. `is_all_criteria` sits beside `is_index` for that reason. `resolve_criteria` resolves every term before a byte is written and refuses the whole batch on the first term it cannot place, naming it. A call that ticked what it understood and then failed would leave the ticket half-marked with nothing in the file to say which half was meant. The offsets are sorted and deduped, so the report reads in `show`'s order and a criterion named twice, or by both `all` and its number, is marked once. `set_criterion` becomes `set_criteria` and takes every line in one pass. Each named criterion gets a line, printed after the write. One already in the target state reads `Already checked 2: text` and does not count towards the write, so a batch where every box is already ticked writes nothing. The opencode wrapper takes the terms one per line, like the other list arguments. REVIEW.md gains the one thing a reviewer must not do with this: reach for `all`, which would erase the implementer's claim on the criteria the review agreed with. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
ae3ee1bb9e
commit
6784d80324
+20
-3
@@ -2071,6 +2071,19 @@ pub fn is_index(search: &str) -> bool {
|
||||
search.trim().parse::<usize>().is_ok()
|
||||
}
|
||||
|
||||
/// Whether `search` is the keyword standing for every criterion.
|
||||
///
|
||||
/// Checked before `find_criteria`, the way the index is checked before the substring,
|
||||
/// so a criterion whose text contains "all" is reachable only by its number or by a
|
||||
/// different substring. The keyword wins because ticking every box is the reason the
|
||||
/// word is typed, and a board where `all` sometimes means one criterion and sometimes
|
||||
/// means the lot would be worse than one that can be addressed another way.
|
||||
///
|
||||
/// Case-insensitive, like the substring match it stands beside.
|
||||
pub fn is_all_criteria(search: &str) -> bool {
|
||||
search.trim().eq_ignore_ascii_case("all")
|
||||
}
|
||||
|
||||
/// Which criterion `search` names: a one-based index as `show` prints, or a
|
||||
/// case-insensitive substring of the text.
|
||||
///
|
||||
@@ -2096,16 +2109,20 @@ pub fn find_criteria(criteria: &[Criterion], search: &str) -> Vec<usize> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Tick or untick the criterion on `line`, leaving every other byte alone.
|
||||
/// Tick or untick the criteria on `lines`, leaving every other byte alone.
|
||||
///
|
||||
/// Only the character between the brackets is spliced. Rebuilding the line would
|
||||
/// normalise its indentation and whatever spacing it carried after the checkbox.
|
||||
pub fn set_criterion(content: &str, line: usize, checked: bool) -> String {
|
||||
///
|
||||
/// Every line in one pass, so a batch is one rewrite and one save rather than one of
|
||||
/// each per criterion. `lines` is searched rather than indexed because a ticket holds
|
||||
/// a handful of criteria, and a set would only move the cost somewhere else.
|
||||
pub fn set_criteria(content: &str, lines: &[usize], checked: bool) -> String {
|
||||
let mark = if checked { 'x' } else { ' ' };
|
||||
let mut out = String::with_capacity(content.len());
|
||||
|
||||
for (index, current) in content.lines().enumerate() {
|
||||
match (index == line, current.find("- [")) {
|
||||
match (lines.contains(&index), current.find("- [")) {
|
||||
(true, Some(at)) => {
|
||||
let opens = at + "- [".len();
|
||||
out.push_str(¤t[..opens]);
|
||||
|
||||
Reference in New Issue
Block a user