Files
cadcraft/crates/engine/tests/it/layout_prompts.rs
T
2ez4gcxandClaude Opus 5.5 8de925e1d3 Write option prompts without "or", as AutoCAD does (#2540)
* Write option prompts without "or", as AutoCAD does

AutoCAD writes " or [" only when a prompt asks for something besides its keywords ("Enter block
name or [?]"); a prompt asking for one of them has none ("Enter an option [...]", "Enter layout
option [...]", "New color [Truecolor/COlorbook]"). The 27 messages read without "or" from
AutoCAD 2024's command line are listed in NO_OR and displayed that way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address review: the window's command line drops "or" as the prompt does

The command line in the window draws a prompt's keywords itself and
wrote " or [" after every message, so -LAYER still read "Enter an option
or [?/Make/...]" there, and questions such as AUDIT's had "or" too. Only
the prompt text (the control channel, the state JSON, the tests) had
dropped it.

Prompt::keyword_lead gives what goes before the keywords; display() and
the command line both use it, and the command line translates only
" or [". A render test reads what the command line draws, in English and
German, for -LAYER, LINE and AUDIT. Suggested in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 14:36:32 -07:00

58 lines
2.5 KiB
Rust

//! LAYOUT / -LAYOUT typed at the command line asks for an option and the layout names it needs
//! instead of running the next inputs as commands.
use cadcraft_doc::Space;
use cadcraft_engine::Session;
fn layouts(s: &Session) -> Vec<String> {
let mut ls: Vec<_> = s.doc().unwrap().layouts.iter().map(|l| (l.tab_order, l.name.clone())).collect();
ls.sort();
ls.into_iter().map(|(_, n)| n).collect()
}
#[test]
fn typed_layout_options_prompt_for_names() {
let mut s = Session::new();
assert_eq!(layouts(&s), ["Layout1", "Layout2"]);
s.cmdline("LAYOUT").unwrap();
let p = s.current_prompt().expect("LAYOUT prompts").display();
assert_eq!(p, "Enter layout option [Copy/Delete/New/Template/Rename/SAveas/Set/?] <set>:");
s.cmdline("n").unwrap();
assert_eq!(s.current_prompt().unwrap().display(), "Enter name of new layout <Layout3>:");
s.cmdline("Sheet9").unwrap();
assert!(s.current_prompt().is_none());
assert_eq!(layouts(&s), ["Layout1", "Layout2", "Sheet9"]);
// Script form, names with spaces, and the current layout as the default.
s.script("-LAYOUT S Layout2\n-LAYOUT R\nLayout2\nSheet A\n-LAYOUT C\n\n\n").unwrap();
assert_eq!(s.layout_space(), Space::Paper("Sheet A".into()));
assert_eq!(layouts(&s), ["Layout1", "Sheet A", "Sheet9", "Sheet A (2)"]);
s.script("-LAYOUT D Sheet9\n").unwrap();
assert_eq!(layouts(&s), ["Layout1", "Sheet A", "Sheet A (2)"]);
// An invalid name re-prompts; Enter at the option prompt is Set.
s.cmdline("LAYOUT N").unwrap();
s.cmdline("Layout1").unwrap();
assert!(s.current_prompt().is_some_and(|p| p.message == "Enter name of new layout"));
s.input(cadcraft_engine::Input::Cancel).unwrap();
s.script("LAYOUT\n\nModel\n").unwrap();
assert_eq!(s.layout_space(), Space::Model);
// ? lists; Template reports and ends without taking the next input.
let n = s.log.len();
s.cmdline("LAYOUT ? Sheet*").unwrap();
assert!(s.log[n..].iter().any(|l| l == "Layout: Sheet A (2)"), "{:?}", &s.log[n..]);
assert!(!s.log[n..].iter().any(|l| l == "Layout: Layout1"));
let n = s.log.len();
s.cmdline("LAYOUT T").unwrap();
assert!(s.current_prompt().is_none());
assert!(s.log[n..].iter().any(|l| l.contains("not available yet")), "{:?}", &s.log[n..]);
assert_eq!(layouts(&s), ["Layout1", "Sheet A", "Sheet A (2)"]);
// The whole command is one undo step.
s.cmdline("LAYOUT N Sheet7").unwrap();
s.undo().unwrap();
assert_eq!(layouts(&s), ["Layout1", "Sheet A", "Sheet A (2)"]);
}