pub struct EditorCallBuilder { /* private fields */ }Implementations§
Source§impl EditorCallBuilder
impl EditorCallBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new EditorCallBuilder.
You can optionally set the line and column numbers later using the at_line and at_column methods.
Finally, you can call the editor with the open_editor, edit_string, or edit_string_mut methods.
§Errors
This function will return an error if the default editor cannot be found in the environment variables.
Examples found in repository?
More examples
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let filename = PathBuf::from_str("./test")?;
9
10 // Spawn editor without waiting
11 EditorCallBuilder::new()
12 .wait_for_editor(false)
13 .open_file(&filename)?;
14
15 println!("Editor launched. Press Ctrl+C to stop.\n");
16
17 loop {
18 let contents = fs::read_to_string(&filename).unwrap_or_default();
19
20 println!("--- Content of {} ---\n{}\n", filename.display(), contents);
21
22 sleep(Duration::from_secs(1));
23 }
24}Sourcepub fn wait_for_editor(self, value: bool) -> Self
pub fn wait_for_editor(self, value: bool) -> Self
Whether to wait for the editor to close before returning.
Examples found in repository?
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let filename = PathBuf::from_str("./test")?;
9
10 // Spawn editor without waiting
11 EditorCallBuilder::new()
12 .wait_for_editor(false)
13 .open_file(&filename)?;
14
15 println!("Editor launched. Press Ctrl+C to stop.\n");
16
17 loop {
18 let contents = fs::read_to_string(&filename).unwrap_or_default();
19
20 println!("--- Content of {} ---\n{}\n", filename.display(), contents);
21
22 sleep(Duration::from_secs(1));
23 }
24}Sourcepub fn with_env_vars(self, env_vars: &[&str]) -> Self
pub fn with_env_vars(self, env_vars: &[&str]) -> Self
Add additional environment variables to look for the editor in. These variables
will have higher priority than VISUAL and EDITOR.
Sourcepub fn with_editor(self, editor: Editor) -> Self
pub fn with_editor(self, editor: Editor) -> Self
Sets a specific editor to use instead of the default one.
Sourcepub fn open_editor(&self) -> Result<String, OpenEditorError>
pub fn open_editor(&self) -> Result<String, OpenEditorError>
Open the default editor and returns what was written in it.
§Errors
If the editor call fails, or if the temporary file cannot be read or cleaned up, or if the editor call fails.
Examples found in repository?
More examples
Sourcepub fn edit_string_mut(
&self,
string: &mut String,
) -> Result<(), OpenEditorError>
pub fn edit_string_mut( &self, string: &mut String, ) -> Result<(), OpenEditorError>
Open the default editor and allows editing of a mutable string.
§Errors
If the editor call fails, or if the temporary file cannot be read or cleaned up, or if the editor call fails.
Sourcepub fn edit_string(&self, string: &str) -> Result<String, OpenEditorError>
pub fn edit_string(&self, string: &str) -> Result<String, OpenEditorError>
Open the default editor and allows editing of a string which is then returned.
§Errors
If the editor call fails, or if the temporary file cannot be read or cleaned up, or if the editor call fails.
Sourcepub fn open_file(&self, file_path: &Path) -> Result<(), OpenEditorError>
pub fn open_file(&self, file_path: &Path) -> Result<(), OpenEditorError>
Opens the specified file in the editor.
§Errors
This function will return an error if the editor call fails or if the file cannot be read.
Examples found in repository?
More examples
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let filename = PathBuf::from_str("./test")?;
9
10 // Spawn editor without waiting
11 EditorCallBuilder::new()
12 .wait_for_editor(false)
13 .open_file(&filename)?;
14
15 println!("Editor launched. Press Ctrl+C to stop.\n");
16
17 loop {
18 let contents = fs::read_to_string(&filename).unwrap_or_default();
19
20 println!("--- Content of {} ---\n{}\n", filename.display(), contents);
21
22 sleep(Duration::from_secs(1));
23 }
24}