From 28b4a0d16bf3c0696148ec85da87e7d5a07740f0 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 27 Aug 2022 08:07:26 -0700 Subject: [PATCH] Add some comments about new Pane methods and helpers --- mux/src/pane.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mux/src/pane.rs b/mux/src/pane.rs index 084c9cfff..caf24bf30 100644 --- a/mux/src/pane.rs +++ b/mux/src/pane.rs @@ -403,11 +403,34 @@ pub trait Pane: Downcast { } impl_downcast!(Pane); +/// This trait is used to implement/provide a callback that is used together +/// with the Pane::with_lines_mut method. +/// Ideally we'd simply pass an FnMut with the same signature as the trait +/// method defined here, but doing so results in Pane not being object-safe. pub trait WithPaneLines { + /// The `first_row` parameter is set to the StableRowIndex of the resolved + /// first row from the Pane::with_lines_mut method. It will usually be + /// the start of the lines range, but in case that row is no longer in + /// a valid range (scrolled out of scrollback), it may be revised. + /// + /// `lines` is a mutable slice of the mutable lines in the requested + /// stable range. fn with_lines_mut(&mut self, first_row: StableRowIndex, lines: &mut [&mut Line]); } +/// This trait is used to implement/provide a callback that is used together +/// with the Pane::for_each_logical_line_in_stable_range_mut method. +/// Ideally we'd simply pass an FnMut with the same signature as the trait +/// method defined here, but doing so results in Pane not being object-safe. pub trait ForEachPaneLogicalLine { + /// The `stable_range` parameter is set to the range of physical lines + /// that comprise the current logical line. + /// + /// `lines` is a mutable slice of the mutable physical lines that comprise + /// the current logical line. + /// + /// Return `true` to continue with the next logical line in the requested + /// range, or `false` to cease iteration. fn with_logical_line_mut( &mut self, stable_range: Range, @@ -415,6 +438,12 @@ pub trait ForEachPaneLogicalLine { ) -> bool; } +/// A helper that allows you to implement Pane::with_lines_mut in terms +/// of your existing Pane::get_lines method. +/// +/// The mutability is really a lie: while `with_lines` is passed something +/// that is mutable, it is operating on a copy the lines that won't persist +/// beyond the call to Pane::with_lines_mut. pub fn impl_with_lines_via_get_lines( pane: &P, lines: Range, @@ -428,6 +457,12 @@ pub fn impl_with_lines_via_get_lines( with_lines.with_lines_mut(first, &mut line_refs); } +/// A helper that allows you to implement Pane::for_each_logical_line_in_stable_range_mut +/// in terms of your existing Pane::get_logical_lines method. +/// +/// The mutability is really a lie: while `with_lines` is passed something +/// that is mutable, it is operating on a copy the lines that won't persist +/// beyond the call to Pane::with_lines_mut. pub fn impl_for_each_logical_line_via_get_logical_lines( pane: &P, lines: Range, @@ -449,6 +484,8 @@ pub fn impl_for_each_logical_line_via_get_logical_lines( } } +/// A helper that allows you to implement Pane::get_logical_lines in terms of +/// your Pane::get_lines method. pub fn impl_get_logical_lines_via_get_lines( pane: &P, lines: Range, @@ -532,6 +569,8 @@ pub fn impl_get_logical_lines_via_get_lines( lines } +/// A helper that allows you to implement Pane::get_lines in terms +/// of your Pane::with_lines_mut method. pub fn impl_get_lines_via_with_lines( pane: &P, lines: Range,