forked from 1b-agent/opencadstudio-upstream
Execute command scripts through full input runner
This commit is contained in:
1 parent
8bb6703c70
commit
d426012660
4 files changed
+20
-8
No files matched your search
@@ -335,9 +335,9 @@ impl OpenCADStudio {
|
|||||||
"PERSP" => return Some(Task::done(Message::SetProjection(false))),
|
"PERSP" => return Some(Task::done(Message::SetProjection(false))),
|
||||||
"LAYERS" => return Some(Task::done(Message::ToggleLayers)),
|
"LAYERS" => return Some(Task::done(Message::ToggleLayers)),
|
||||||
|
|
||||||
// SCRIPT <path> — run a command script: each non-blank, non-comment
|
// SCRIPT <path> — run a command script: each non-comment
|
||||||
// line is fed through the same command path the `--script` startup
|
// line is fed through the same command path the `--script` startup
|
||||||
// flag uses, so the behaviour matches headless automation exactly.
|
// flag uses. Blank rows submit Enter to the active command.
|
||||||
"SCRIPT" | "SCR" => {
|
"SCRIPT" | "SCR" => {
|
||||||
use crate::command::ValuePromptCommand;
|
use crate::command::ValuePromptCommand;
|
||||||
let c = ValuePromptCommand::new("SCRIPT", "SCRIPT path to the .scr file:");
|
let c = ValuePromptCommand::new("SCRIPT", "SCRIPT path to the .scr file:");
|
||||||
@@ -352,10 +352,8 @@ impl OpenCADStudio {
|
|||||||
let cmds: Vec<Task<Message>> = text
|
let cmds: Vec<Task<Message>> = text
|
||||||
.lines()
|
.lines()
|
||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.filter(|l| {
|
.filter(|l| !l.starts_with('#') && !l.starts_with(';'))
|
||||||
!l.is_empty() && !l.starts_with('#') && !l.starts_with(';')
|
.map(|l| Task::done(Message::ScriptLine(l.to_string())))
|
||||||
})
|
|
||||||
.map(|l| Task::done(Message::Command(l.to_string())))
|
|
||||||
.collect();
|
.collect();
|
||||||
self.command_line.push_output(crate::tf!(
|
self.command_line.push_output(crate::tf!(
|
||||||
"SCRIPT: running {} command(s) from {p}.",
|
"SCRIPT: running {} command(s) from {p}.",
|
||||||
|
|||||||
+5
-1
@@ -2117,6 +2117,10 @@ pub enum Message {
|
|||||||
CommandInput(String),
|
CommandInput(String),
|
||||||
CommandSubmit,
|
CommandSubmit,
|
||||||
Command(String),
|
Command(String),
|
||||||
|
/// Execute one complete line read from a command script. Unlike UI/ribbon
|
||||||
|
/// dispatch, this accepts an interactive verb and all of its arguments on
|
||||||
|
/// the same line (`BOX 0,0,0 10,10,0 10`).
|
||||||
|
ScriptLine(String),
|
||||||
/// Append one typed character to the command-line input from the
|
/// Append one typed character to the command-line input from the
|
||||||
/// global key-press subscription. Used when the text-input widget
|
/// global key-press subscription. Used when the text-input widget
|
||||||
/// itself isn't focused (focus parked on viewport / button / etc.)
|
/// itself isn't focused (focus parked on viewport / button / etc.)
|
||||||
@@ -3832,7 +3836,7 @@ impl OpenCADStudio {
|
|||||||
Task::batch(
|
Task::batch(
|
||||||
cfg.script_lines
|
cfg.script_lines
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|line| Task::done(Message::Command(line))),
|
.map(|line| Task::done(Message::ScriptLine(line))),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
s.queue_startup_prompts();
|
s.queue_startup_prompts();
|
||||||
|
|||||||
@@ -1953,6 +1953,14 @@ impl OpenCADStudio {
|
|||||||
self.dispatch_command(&cmd)
|
self.dispatch_command(&cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message::ScriptLine(line) => {
|
||||||
|
if line.trim().is_empty() {
|
||||||
|
self.feed_command(crate::command::StepInput::Enter)
|
||||||
|
} else {
|
||||||
|
self.run_command_line(&line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Message::ToggleLayers => {
|
Message::ToggleLayers => {
|
||||||
if self.active_modal == Some(super::ModalKind::Layers) {
|
if self.active_modal == Some(super::ModalKind::Layers) {
|
||||||
self.ribbon.deactivate_tool_if("LAYERS");
|
self.ribbon.deactivate_tool_if("LAYERS");
|
||||||
|
|||||||
+3
-1
@@ -134,7 +134,9 @@ fn main() -> iced::Result {
|
|||||||
Ok(text) => text
|
Ok(text) => text
|
||||||
.lines()
|
.lines()
|
||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
// Blank script rows are significant: they submit Enter to
|
||||||
|
// the active command (for example, accepting a preview).
|
||||||
|
.filter(|l| !l.starts_with('#') && !l.starts_with(';'))
|
||||||
.map(str::to_string)
|
.map(str::to_string)
|
||||||
.collect(),
|
.collect(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
Reference in new issue
Block a user