From 7d314fc3b771a104d29f653d3c1286b1f0fd0bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Thu, 8 Feb 2024 10:29:32 +0900 Subject: [PATCH 01/10] Update main.rs Become cross-platform compatible --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6960444..d8584c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -866,9 +866,20 @@ impl Executor { // ファイルを開く "open" => { - let _result = std::process::Command::new("cmd") - .args(&["/C", "start", "", self.pop_stack().get_string().as_str()]) - .spawn(); + if cfg!(target_os = "windows") { + let _result = std::process::Command::new("cmd") + .args(&["/C", "start", "", self.pop_stack().get_string().as_str()]) + .spawn(); + } else if cfg!(target_os = "linux") { + let _result = + std::process::Command::new("xdg-open") // Linuxの場合 + .arg(self.pop_stack().get_string().as_str()) + .spawn(); + } else if cfg!(target_os = "macos") { + let _result = std::process::Command::new("open") + .arg(self.pop_stack().get_string().as_str()) + .spawn(); + } } // シェルコマンドを実行 From d97ab39df84f961230e3e33051df20f574d349c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Thu, 8 Feb 2024 12:41:23 +0900 Subject: [PATCH 02/10] use crate `opener` multi-platform complitible --- Cargo.toml | 1 + src/main.rs | 16 ++-------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 83bef41..d00dbfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +opener = "0.6.1" powershell_script = "1.1.0" rand = "0.8" reqwest = { version = "0.11.0", features = ["blocking"] } diff --git a/src/main.rs b/src/main.rs index d8584c3..56d7907 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use powershell_script::PsScriptBuilder; use rand::seq::SliceRandom; use std::collections::HashMap; use std::env; +use opener; use std::fs::File; use std::io::{self, Error, Read, Write}; use std::thread; @@ -866,20 +867,7 @@ impl Executor { // ファイルを開く "open" => { - if cfg!(target_os = "windows") { - let _result = std::process::Command::new("cmd") - .args(&["/C", "start", "", self.pop_stack().get_string().as_str()]) - .spawn(); - } else if cfg!(target_os = "linux") { - let _result = - std::process::Command::new("xdg-open") // Linuxの場合 - .arg(self.pop_stack().get_string().as_str()) - .spawn(); - } else if cfg!(target_os = "macos") { - let _result = std::process::Command::new("open") - .arg(self.pop_stack().get_string().as_str()) - .spawn(); - } + let _result = opener::open(self.pop_stack().get_string()); } // シェルコマンドを実行 From 1ab3c1415e88bf3aa04bb3c0e2be692fa969253a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Thu, 8 Feb 2024 13:08:55 +0900 Subject: [PATCH 03/10] become direction access file-system replace command `shell` --- Cargo.toml | 1 - src/main.rs | 51 ++++++++++++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d00dbfb..e64aaed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,5 @@ edition = "2021" [dependencies] opener = "0.6.1" -powershell_script = "1.1.0" rand = "0.8" reqwest = { version = "0.11.0", features = ["blocking"] } diff --git a/src/main.rs b/src/main.rs index 56d7907..3c00334 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,8 @@ -use powershell_script::PsScriptBuilder; +use opener; use rand::seq::SliceRandom; use std::collections::HashMap; use std::env; -use opener; -use std::fs::File; +use std::fs::{self, File}; use std::io::{self, Error, Read, Write}; use std::thread; use std::thread::sleep; @@ -870,32 +869,34 @@ impl Executor { let _result = opener::open(self.pop_stack().get_string()); } - // シェルコマンドを実行 - "shell" => { - let ps = PsScriptBuilder::new() - .no_profile(true) - .non_interactive(true) - .hidden(false) - .print_commands(false) - .build(); - let _ = ps.run( - "[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding('utf-8')", - ); - let result = ps.run(self.pop_stack().get_string().as_str()); - match result { - Ok(i) => self.stack.push(Type::String( - i.stdout() - .unwrap_or("".to_string()) - .as_str() - .trim() - .to_string(), - )), - Err(_) => { - self.log_print("エラー! シェルスクリプトの実行に失敗しました\n".to_string()) + //カレントディレクトリを変更 + "cd" => { + if let Err(err) = std::env::set_current_dir(self.pop_stack().get_string()) { + self.log_print(format!("エラー! {}", err)); + } + } + + // カレントディレクトリを表示 + "pwd" => { + if let Ok(current_dir) = std::env::current_dir() { + if let Some(path) = current_dir.to_str() { + self.stack.push(Type::String(String::from(path))); } } } + // ファイル一覧のリスト + "ls" => { + if let Ok(entries) = fs::read_dir(".") { + let value: Vec = entries + .filter_map(|entry| { + entry.ok().and_then(|e| e.file_name().into_string().ok()).map(|x| Type::String(x)) + }) + .collect(); + self.stack.push(Type::List(value)); + } + } + // コマンドとして認識されない場合は文字列とする _ => self.stack.push(Type::String(command)), } From 03a925e2c603031e62a2671cf0b4f778e4f72467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Thu, 8 Feb 2024 21:54:08 +0900 Subject: [PATCH 04/10] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e64aaed..19db930 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stack" -version = "1.5.0" +version = "1.8.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From cb787212392a01ffd1e2e8710832c6d75099524c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Thu, 8 Feb 2024 22:06:23 +0900 Subject: [PATCH 05/10] Update main.rs --- src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3c00334..a8ef4c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -872,7 +872,7 @@ impl Executor { //カレントディレクトリを変更 "cd" => { if let Err(err) = std::env::set_current_dir(self.pop_stack().get_string()) { - self.log_print(format!("エラー! {}", err)); + self.log_print(format!("エラー! {}\n", err)); } } @@ -888,13 +888,16 @@ impl Executor { // ファイル一覧のリスト "ls" => { if let Ok(entries) = fs::read_dir(".") { - let value: Vec = entries - .filter_map(|entry| { - entry.ok().and_then(|e| e.file_name().into_string().ok()).map(|x| Type::String(x)) - }) - .collect(); - self.stack.push(Type::List(value)); - } + let value: Vec = entries + .filter_map(|entry| { + entry + .ok() + .and_then(|e| e.file_name().into_string().ok()) + .map(|x| Type::String(x)) + }) + .collect(); + self.stack.push(Type::List(value)); + } } // コマンドとして認識されない場合は文字列とする From 2663dabd3d7d7458e2efdd408cd0c32962870abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Fri, 9 Feb 2024 12:01:53 +0900 Subject: [PATCH 06/10] Update main.rs --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index a8ef4c7..362444a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use opener; use rand::seq::SliceRandom; use std::collections::HashMap; use std::env; +use std::path::Path; use std::fs::{self, File}; use std::io::{self, Error, Read, Write}; use std::thread; @@ -900,6 +901,12 @@ impl Executor { } } + "folder" => { + let path = self.pop_stack().get_string(); + let path = Path::new(path.as_str()); + self.stack.push(Type::Bool(path.is_dir())); + } + // コマンドとして認識されない場合は文字列とする _ => self.stack.push(Type::String(command)), } From d92c3f88864566856311d480d31dd42f669ad4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Fri, 9 Feb 2024 18:28:49 +0900 Subject: [PATCH 07/10] Update main.rs append comment of `folder` command --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index 362444a..cf8b96b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -901,6 +901,7 @@ impl Executor { } } + // フォルダかどうか判定 "folder" => { let path = self.pop_stack().get_string(); let path = Path::new(path.as_str()); From aeaef447745cd78c89afc4c75f0dc0629b791720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Sun, 11 Feb 2024 10:54:22 +0900 Subject: [PATCH 08/10] Update main.rs Append comment of `encode` command --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index cf8b96b..c969947 100644 --- a/src/main.rs +++ b/src/main.rs @@ -458,6 +458,7 @@ impl Executor { } } + // 文字列をUTF-8でエンコード "encode" => { let string = self.pop_stack().get_string(); if let Some(first_char) = string.chars().next() { From dedeae9c5f1282fce3089aeff3ff0f2db522297f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Sun, 11 Feb 2024 12:18:31 +0900 Subject: [PATCH 09/10] Update main.rs Formated! --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c969947..84acee2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,9 @@ use opener; use rand::seq::SliceRandom; use std::collections::HashMap; use std::env; -use std::path::Path; use std::fs::{self, File}; use std::io::{self, Error, Read, Write}; +use std::path::Path; use std::thread; use std::thread::sleep; use std::time::{Duration, SystemTime, UNIX_EPOCH}; From 3ea9283c340bbcf5aa2758ca3f3b1ab862fd090b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Tue, 13 Feb 2024 09:18:48 +0900 Subject: [PATCH 10/10] Update main.rs --- src/main.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 84acee2..c37e076 100644 --- a/src/main.rs +++ b/src/main.rs @@ -573,13 +573,10 @@ impl Executor { "while" => { let cond = self.pop_stack().get_string(); let code = self.pop_stack().get_string(); - loop { - if { - self.evaluate_program(cond.clone()); - !self.pop_stack().get_bool() - } { - break; - } + while { + self.evaluate_program(cond.clone()); + self.pop_stack().get_bool() + } { self.evaluate_program(code.clone()); } }