pub struct EditorSource<R: EditorRunner = RealEditorRunner> { /* private fields */ }Expand description
Collect input via an external text editor.
Opens the user’s preferred editor (from $VISUAL or $EDITOR) with a
temporary file, waits for the user to save and close, then reads the result.
§Editor Detection
Editors are detected in this order:
$VISUALenvironment variable (supports GUI editors)$EDITORenvironment variable- Platform fallbacks:
vim,vi,nanoon Unix;notepadon Windows
§Example
ⓘ
use standout_input::{InputChain, ArgSource, EditorSource};
// Fall back to editor if no CLI argument
let chain = InputChain::<String>::new()
.try_source(ArgSource::new("message"))
.try_source(EditorSource::new());
let message = chain.resolve(&matches)?;§Configuration
ⓘ
let source = EditorSource::new()
.initial_content("# Enter your message\n\n")
.extension(".md")
.require_save(true);Implementations§
Source§impl EditorSource<RealEditorRunner>
impl EditorSource<RealEditorRunner>
Source§impl<R: EditorRunner> EditorSource<R>
impl<R: EditorRunner> EditorSource<R>
Sourcepub fn with_runner(runner: R) -> Self
pub fn with_runner(runner: R) -> Self
Create an editor source with a custom runner.
Primarily used for testing to mock editor invocation.
Sourcepub fn initial_content(self, content: impl Into<String>) -> Self
pub fn initial_content(self, content: impl Into<String>) -> Self
Set initial content to populate the editor with.
This can be used to provide a template or instructions.
Sourcepub fn extension(self, ext: impl Into<String>) -> Self
pub fn extension(self, ext: impl Into<String>) -> Self
Set the file extension for the temporary file.
This affects syntax highlighting in the editor.
Default is .txt.
Sourcepub fn require_save(self, require: bool) -> Self
pub fn require_save(self, require: bool) -> Self
Require the user to actually save the file.
If true, the source will return None if the file’s modification
time hasn’t changed (i.e., the user closed without saving).
Default is false.
Trait Implementations§
Source§impl<R: Clone + EditorRunner> Clone for EditorSource<R>
impl<R: Clone + EditorRunner> Clone for EditorSource<R>
Source§fn clone(&self) -> EditorSource<R>
fn clone(&self) -> EditorSource<R>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for EditorSource<RealEditorRunner>
impl Default for EditorSource<RealEditorRunner>
Source§impl<R: EditorRunner + 'static> InputCollector<String> for EditorSource<R>
impl<R: EditorRunner + 'static> InputCollector<String> for EditorSource<R>
Source§fn is_available(&self, _matches: &ArgMatches) -> bool
fn is_available(&self, _matches: &ArgMatches) -> bool
Check if this collector can provide input in the current environment. Read more
Source§fn collect(&self, _matches: &ArgMatches) -> Result<Option<String>, InputError>
fn collect(&self, _matches: &ArgMatches) -> Result<Option<String>, InputError>
Attempt to collect input from this source. Read more
Auto Trait Implementations§
impl<R> Freeze for EditorSource<R>
impl<R> RefUnwindSafe for EditorSource<R>where
R: RefUnwindSafe,
impl<R> Send for EditorSource<R>
impl<R> Sync for EditorSource<R>
impl<R> Unpin for EditorSource<R>
impl<R> UnsafeUnpin for EditorSource<R>
impl<R> UnwindSafe for EditorSource<R>where
R: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more