Struct add_ed::Ed

source ·
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>

source

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 string
  • clipboard: empty clipboard
  • error: None
  • print_errors: true
  • n: false,
  • l: false,
  • cmd_prefix: Some(':')
  • recursion_limit: 16
source

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

source

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

source

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)

source

pub fn run(&mut self, ui: &mut dyn UI) -> Result<()>

Run until quit by command

Prints ? or error message as errors occur (depending on print_errors). Returns error only if error occurs when printing an error.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Ed<'a>

§

impl<'a> !Send for Ed<'a>

§

impl<'a> !Sync for Ed<'a>

§

impl<'a> Unpin for Ed<'a>

§

impl<'a> !UnwindSafe for Ed<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for T
where T: Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

source§

fn type_name(&self) -> &'static str

Gets the type name of self
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: AsAny + ?Sized,

source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.