summaryrefslogtreecommitdiff
path: root/utils/src/input.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-27 06:18:30 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-27 06:18:30 +0800
commitda1a67d4d32b081fee59f30c43695de21225522a (patch)
tree84cdb00e05f4d85f9e441894f846cfaa1b884bd0 /utils/src/input.rs
parent49f8161fafb636d9d44d2f0878a7429058fb1db6 (diff)
Add utility functions and macros
- Add `current_tempfile_path` function to get temporary file paths - Add `input_with_editor_custom` function that accepts custom editor - Add `string_vec!` macro for creating `Vec<String>` from literals
Diffstat (limited to 'utils/src/input.rs')
-rw-r--r--utils/src/input.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/utils/src/input.rs b/utils/src/input.rs
index 80ea569..bc67d90 100644
--- a/utils/src/input.rs
+++ b/utils/src/input.rs
@@ -63,6 +63,21 @@ pub async fn input_with_editor(
cache_file: impl AsRef<std::path::Path>,
comment_char: impl AsRef<str>,
) -> Result<String, std::io::Error> {
+ input_with_editor_cutsom(
+ default_text,
+ cache_file,
+ comment_char,
+ get_default_editor().await,
+ )
+ .await
+}
+
+pub async fn input_with_editor_cutsom(
+ default_text: impl AsRef<str>,
+ cache_file: impl AsRef<std::path::Path>,
+ comment_char: impl AsRef<str>,
+ editor: String,
+) -> Result<String, std::io::Error> {
let cache_path = cache_file.as_ref();
let default_content = default_text.as_ref();
let comment_prefix = comment_char.as_ref();
@@ -70,9 +85,6 @@ pub async fn input_with_editor(
// Write default text to cache file
fs::write(cache_path, default_content).await?;
- // Get editor from environment variable
- let editor = get_default_editor().await;
-
// Open editor with cache file
let status = Command::new(editor).arg(cache_path).status().await?;