pub struct Buffer {
pub opts: PrintOpts,
/* private fields */
}Expand description
The widget that is used to print and edit buffers
Fields§
§opts: PrintOptsYou can use this member to change the way this Buffer will
be printed specifically.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn save(&mut self) -> Result<Option<usize>, Text>
pub fn save(&mut self) -> Result<Option<usize>, Text>
Writes the buffer to the current PathBuf, if one was set
Sourcepub fn save_to(&mut self, path: impl AsRef<Path>) -> Result<Option<usize>>
pub fn save_to(&mut self, path: impl AsRef<Path>) -> Result<Option<usize>>
Writes the buffer to the given Path
Sourcepub fn path(&self) -> String
pub fn path(&self) -> String
The full path of the buffer.
If there is no set path, returns "*scratch buffer*#{id}".
Sourcepub fn path_set(&self) -> Option<String>
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.
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
The buffer’s name.
If there is no set path, returns "*scratch buffer #{id}*".
Sourcepub fn name_set(&self) -> Option<String>
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.
Sourcepub fn name_txt(&self) -> Text
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}*Sourcepub fn printed_lines(&self) -> MutexGuard<'_, Vec<(usize, bool)>>
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.
Sourcepub fn selections(&self) -> &Selections
pub fn selections(&self) -> &Selections
The Selections that are used on the Text
Sourcepub fn selections_mut(&mut self) -> &mut Selections
pub fn selections_mut(&mut self) -> &mut Selections
A mutable reference to the Selections
Sourcepub fn add_parser<P: Parser>(
&mut self,
f: impl FnOnce(BufferTracker) -> P,
) -> Result<(), Text>
pub fn add_parser<P: Parser>( &mut self, f: impl FnOnce(BufferTracker) -> P, ) -> Result<(), Text>
Sourcepub fn read_parser<P: Parser, Ret>(
&self,
read: impl FnOnce(&P) -> Ret,
) -> Option<Ret>
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.
Sourcepub fn try_read_parser<P: Parser, Ret>(
&self,
read: impl FnOnce(&P) -> Ret,
) -> Option<Ret>
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.
Sourcepub fn write_parser<P: Parser, Ret>(
&self,
write: impl FnOnce(&mut P) -> Ret,
) -> Option<Ret>
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.
Sourcepub fn try_write_parser<P: Parser, Ret>(
&self,
write: impl FnOnce(&mut P) -> Ret,
) -> Option<Ret>
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 Widget for Buffer
impl Widget for Buffer
Source§fn needs_update(&self, _: &Pass) -> bool
fn needs_update(&self, _: &Pass) -> bool
Source§fn get_print_opts(&self) -> PrintOpts
fn get_print_opts(&self) -> PrintOpts
Source§fn on_mouse_event(pa: &mut Pass, handle: &Handle<Self>, event: MouseEvent)
fn on_mouse_event(pa: &mut Pass, handle: &Handle<Self>, event: MouseEvent)
MouseEvent Read moreAuto 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> 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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.