pub struct Ed<'a> {Show 14 fields
pub history: History<Buffer>,
pub clipboard: Clipboard,
pub selection: (usize, usize),
pub io: &'a mut dyn IO,
pub file: String,
pub prev_shell_command: String,
pub prev_s: Option<Substitution>,
pub cmd_prefix: Option<char>,
pub n: bool,
pub l: bool,
pub print_errors: bool,
pub error: Option<EdError>,
pub macro_getter: &'a dyn MacroGetter,
pub recursion_limit: usize,
}
Expand description
The state variable used to track the editor’s internal state.
It is designed to support mutation and analysis by library users, but be careful: modifying this state wrong will cause user facing errors.
Fields§
§history: History<Buffer>
Holds the past, present and sometimes future states of the editing buffer
See History
documentation for how to use.
clipboard: Clipboard
The current clipboard contents
Uses a special Buffer
analogue over PubLine
, since some of the
internal data in Line could cause unexpected behavior if pasted as is.
selection: (usize, usize)
Tracks the currently selected lines in the buffer.
Inclusive 1-indexed start and end bounds over selected lines. Selected lines aren’t required to exist, but it is recommended for user comfort. Empty selection should only occur when the buffer is empty, and in that case exactly (1,0). Invalid selections cause errors, not crashes (verified by fuzzing).
io: &'a mut dyn IO
Currently used IO implementor
It will be used to handle file interactions and command execution as required during command execution
file: String
The path to the currently selected file.
prev_shell_command: String
Shell command last given by the user
Fully processed, meaning all substitutions of % to current file and similar should already have occured before saving here. (Currently saved before successful run, so may be invalid).
prev_s: Option<Substitution>
The previous s
commands arguments, to support repeating last s
command
when no arguments are given to s
.
cmd_prefix: Option<char>
Configuration of prefix before command input.
Traditionally ‘:’ so set to that by default.
n: bool
Set default to print numbered lines.
If set n
printing flag behaviour inverts and disables line numbers.
l: bool
Set default to print literal lines. (A type of escaped print.)
If set l
printing flag behaviour inverts and disables literal printing.
print_errors: bool
Wether or not to print errors when they occur.
If not true Ed prints ? on error, expecting use of h
command to get
the error.
error: Option<EdError>
The previous error that occured.
Is printed by h
command.
UI errors occuring outside of Ed should also be written to this variable,
so h
prints the latest error that occured in the whole application.
macro_getter: &'a dyn MacroGetter
EXPERIMENTAL: Reference to accessor for macros.
recursion_limit: usize
Set how many recursions should be allowed.
One recursion is counted as one macro or ‘g’/‘v’/‘G’/‘V’ invocation. Under 2 is likely to interfere with basic use, 4 will require that macros don’t call into eachother, 16 is unlikely to abort needlessly.
Implementations§
source§impl<'a> Ed<'a>
impl<'a> Ed<'a>
sourcepub fn new(io: &'a mut dyn IO, macro_getter: &'a dyn MacroGetter) -> Self
pub fn new(io: &'a mut dyn IO, macro_getter: &'a dyn MacroGetter) -> Self
Construct a new instance of Ed
Defaults are as follow:
file
: empty stringclipboard
: empty clipboarderror
:None
print_errors
:true
n
:false
,l
:false
,cmd_prefix
:Some(':')
recursion_limit
:16
sourcepub fn run_command(&mut self, ui: &mut dyn UI, command: &str) -> Result<bool>
pub fn run_command(&mut self, ui: &mut dyn UI, command: &str) -> Result<bool>
Run the given command
Returns true if the command was to quit
sourcepub fn get_and_run_command(&mut self, ui: &mut dyn UI) -> Result<bool>
pub fn get_and_run_command(&mut self, ui: &mut dyn UI) -> Result<bool>
Get a single command from the UI and run it
Returns true if the command was to quit, false otherwise. Returns error if any occurs
sourcepub fn run_macro<S: Deref<Target = str>>(
&mut self,
ui: &mut dyn UI,
mac: &Macro,
arguments: &[S]
) -> Result<()>
pub fn run_macro<S: Deref<Target = str>>( &mut self, ui: &mut dyn UI, mac: &Macro, arguments: &[S] ) -> Result<()>
Run given macro until Ed receives a command to quit or errors
Will immediately return error if the macro was given wrong nr of arguments
Returns Ok(()) when quit by command (or end of macro input)