MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / open_editor

Function open_editor

crates/chat-cli/src/cli/chat/cli/editor.rs:127–149  ·  view source on GitHub ↗

Opens the user's preferred editor to compose a prompt

(initial_text: Option<String>)

Source from the content-addressed store, hash-verified

125
126/// Opens the user's preferred editor to compose a prompt
127pub fn open_editor(initial_text: Option<String>) -> Result<String, ChatError> {
128 // Create a temporary file with a unique name
129 let temp_dir = std::env::temp_dir();
130 let file_name = format!("q_prompt_{}.md", Uuid::new_v4());
131 let temp_file_path = temp_dir.join(file_name);
132
133 // Write initial content to the file if provided
134 let initial_content = initial_text.unwrap_or_default();
135 std::fs::write(&temp_file_path, &initial_content)
136 .map_err(|e| ChatError::Custom(format!("Failed to create temporary file: {}", e).into()))?;
137
138 // Launch the editor
139 launch_editor(&temp_file_path)?;
140
141 // Read the content back
142 let content = std::fs::read_to_string(&temp_file_path)
143 .map_err(|e| ChatError::Custom(format!("Failed to read temporary file: {}", e).into()))?;
144
145 // Clean up the temporary file
146 let _ = std::fs::remove_file(&temp_file_path);
147
148 Ok(content.trim().to_string())
149}

Callers 3

executeMethod · 0.85
executeMethod · 0.85

Calls 4

CustomClass · 0.85
joinMethod · 0.80
to_stringMethod · 0.80
launch_editorFunction · 0.70

Tested by

no test coverage detected