From 4bb98332404fb7fde95e9f0fa12c673a243b963d Mon Sep 17 00:00:00 2001 From: flippedround <734243792@qq.com> Date: Wed, 8 Jan 2025 23:12:06 +0800 Subject: [PATCH] feat(gui): add input parameter handling for GUI mode --- packages/core/src/command/actions/gui.ts | 4 ++-- packages/gui/src/lib.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/core/src/command/actions/gui.ts b/packages/core/src/command/actions/gui.ts index 2b515b4..690621f 100644 --- a/packages/core/src/command/actions/gui.ts +++ b/packages/core/src/command/actions/gui.ts @@ -25,8 +25,7 @@ export function actionGuiCLI() { }) const [command, ..._args] = fullCustomCommand.split(' ') - const { error, stdout } = sync(command, [..._args], { - input, + const { error, stdout } = sync(command, [..._args, '--input', input], { stdio: 'pipe', }) @@ -36,6 +35,7 @@ export function actionGuiCLI() { let data: any if (stdout.length > 0) { const data_string = stdout.toString() + console.log(data_string) try { const _data = JSON.parse(data_string) if (_data.useTemplate) { diff --git a/packages/gui/src/lib.rs b/packages/gui/src/lib.rs index caaee02..c83b24a 100644 --- a/packages/gui/src/lib.rs +++ b/packages/gui/src/lib.rs @@ -29,7 +29,12 @@ pub fn create_webview() -> Result<()> { let current_dir: PathBuf = env::current_dir().expect("Unable to get current working directory"); let mut input = String::new(); - io::stdin().read_to_string(&mut input).unwrap(); + let args: Vec = env::args().collect(); + if let Some(input_value) = args.iter().position(|x| x == "--input").and_then(|i| args.get(i + 1)) { + input = input_value.to_string(); + } else { + println!("No input provided."); + } let current_dir_str = current_dir.to_str().unwrap_or(""); let escaped_current_dir_str = current_dir_str.replace("\\", "\\\\");