Buffer

Struct Buffer 

Source
pub struct Buffer {
    pub opts: PrintOpts,
    /* private fields */
}
Expand description

The widget that is used to print and edit buffers

Fields§

§opts: PrintOpts

The PrintOpts of this Buffer

You can use this member to change the way this Buffer will be printed specifically.

Implementations§

Source§

impl Buffer

Source

pub fn save(&mut self) -> Result<Option<usize>, Text>

Writes the buffer to the current PathBuf, if one was set

Source

pub fn save_to(&mut self, path: impl AsRef<Path>) -> Result<Option<usize>>

Writes the buffer to the given Path

Source

pub fn path(&self) -> String

The full path of the buffer.

If there is no set path, returns "*scratch buffer*#{id}".

Source

pub fn path_set(&self) -> Option<String>

The full path of the buffer.

Returns None if the path has not been set yet, i.e., if the buffer is a scratch buffer.

Source

pub fn path_txt(&self) -> Text

A Text from the full path of this PathKind

§Formatting

If the buffer’s path was set:

[buffer]{path}

If the buffer’s path was not set:

[buffer.new.scratch]*scratch buffer #{id}*
Source

pub fn name(&self) -> String

The buffer’s name.

If there is no set path, returns "*scratch buffer #{id}*".

Source

pub fn name_set(&self) -> Option<String>

The buffer’s name.

Returns None if the path has not been set yet, i.e., if the buffer is a scratch buffer.

Source

pub fn name_txt(&self) -> Text

A Text from the name of this PathKind

The name of a Buffer widget is the same as the path, but it strips away the current directory. If it can’t, it will try to strip away the home directory, replacing it with "~". If that also fails, it will just show the full path.

§Formatting

If the buffer’s name was set:

[buffer]{name}

If the buffer’s name was not set:

[buffer.new.scratch]*scratch buffer #{id}*
Source

pub fn path_kind(&self) -> PathKind

The type of PathBuf

This represents the three possible states for a Buffer’s PathBuf, as it could either represent a real Buffer, not exist, or not have been defined yet.

Source

pub fn printed_lines(&self) -> MutexGuard<'_, Vec<(usize, bool)>>

Returns the currently printed set of lines.

These are returned as a usize, showing the index of the line in the buffer, and a bool, which is true when the line is wrapped.

Source

pub fn bytes(&self) -> &Bytes

The Bytes of the Buffer’s Text

Source

pub fn len_bytes(&self) -> usize

The number of bytes in the buffer.

Source

pub fn len_chars(&self) -> usize

The number of chars in the buffer.

Source

pub fn len_lines(&self) -> usize

The number of lines in the buffer.

Source

pub fn selections(&self) -> &Selections

The Selections that are used on the Text

Source

pub fn selections_mut(&mut self) -> &mut Selections

A mutable reference to the Selections

Source

pub fn exists(&self) -> bool

Whether o not the Buffer exists or not

Source

pub fn add_parser<P: Parser>( &mut self, f: impl FnOnce(BufferTracker) -> P, ) -> Result<(), Text>

Adds a Parser to this Buffer

The Parser will be able to keep track of every single Change that takes place in the Buffer’s Text, and can act on the Buffer accordingly.

This function will fail if a Parser of the same type was already added to this Buffer

Source

pub fn read_parser<P: Parser, Ret>( &self, read: impl FnOnce(&P) -> Ret, ) -> Option<Ret>

Reads from a specific Parser, if it was added

This function will block until the Parser is ready to be read. This usually implies that the Parser is done processing all the Changes up to this point. But it could also be the case that the Parser doesn’t really care about Changes.

While this function is being called, trying to read or write to the same Parser will always return None.

If you want to read in a non blocking way, see Buffer::try_read_parser.

Source

pub fn try_read_parser<P: Parser, Ret>( &self, read: impl FnOnce(&P) -> Ret, ) -> Option<Ret>

Tries tor read from a specific Parser, if it was added

Unlike Buffer::read_parser, this function will only be called when the Parser is ready to be read. This may not be the case if, for example, it is still processing Changes to the Text. In that case, the function will not be called and try_read_parser will return None.

While this function is being called, trying to read or write to the same Parser will always return None.

Source

pub fn write_parser<P: Parser, Ret>( &self, write: impl FnOnce(&mut P) -> Ret, ) -> Option<Ret>

Writes to a specific Parser, if it was added

This function will block until the Parser is ready to be written to. This usually implies that the Parser is done processing all the Changes up to this point. But it could also be the case that the Parser doesn’t really care about Changes.

While this function is being called, trying to read or write to the same Parser will always return None.

If you want to write in a non blocking way, see Buffer::try_write_parser.

Source

pub fn try_write_parser<P: Parser, Ret>( &self, write: impl FnOnce(&mut P) -> Ret, ) -> Option<Ret>

Tries tor read a specific Parser, if it was added

Unlike Buffer::write_parser, this function will only be called when the Parser is ready to be written to. This may not be the case if, for example, it is still processing Changes to the Text. In that case, the function will not be called and try_write_parser will return None.

While this function is being called, trying to read or write to the same Parser will always return None.

Trait Implementations§

Source§

impl<'a> Parameter<'a> for Buffer

Source§

type Returns = Handle

The type that is returned
Source§

fn new( pa: &Pass, args: &mut Args<'a>, ) -> Result<(Self::Returns, Option<FormId>), Text>

Tries to consume arguments until forming a parameter Read more
Source§

impl Widget for Buffer

Source§

fn update(pa: &mut Pass, handle: &Handle<Self>)

Updates the widget alongside its RwArea in the Handle Read more
Source§

fn needs_update(&self, _: &Pass) -> bool

Tells Duat that this Widget should be updated Read more
Source§

fn text(&self) -> &Text

The text that this widget prints out
Source§

fn text_mut(&mut self) -> &mut Text

A mutable reference to the Text that is printed
Source§

fn get_print_opts(&self) -> PrintOpts

The configuration for how to print Text Read more
Source§

fn on_mouse_event(pa: &mut Pass, handle: &Handle<Self>, event: MouseEvent)

How to handle a MouseEvent Read more
Source§

fn print(&self, pa: &Pass, painter: Painter, area: &RwArea)

Prints the widget Read more
Source§

fn on_focus(pa: &mut Pass, handle: &Handle<Self>)
where Self: Sized,

Actions to do whenever this Widget is focused Read more
Source§

fn on_unfocus(pa: &mut Pass, handle: &Handle<Self>)
where Self: Sized,

Actions to do whenever this Widget is unfocused Read more

Auto Trait Implementations§

§

impl !Freeze for Buffer

§

impl !RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl !Sync for Buffer

§

impl Unpin for Buffer

§

impl !UnwindSafe for Buffer

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> 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: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

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

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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>,

Source§

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>,

Source§

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.