Struct fm::tree::Tree

source ·
pub struct Tree {
    pub node: Node,
    pub leaves: Vec<Tree>,
    pub position: Vec<usize>,
    pub current_node: Node,
    /* private fields */
}
Expand description

Holds a recursive view of a directory. Creation can be long as is explores every subfolder to a certain depth. Parsing into a vector of “prefix” (String) and ColoredString is a depthfirst search and it can be long too.

Fields§

§node: Node§leaves: Vec<Tree>§position: Vec<usize>§current_node: Node

Implementations§

source§

impl Tree

source

pub const MAX_DEPTH: usize = 5usize

The max depth when exploring a tree. ATM it’s a constant, in future versions it may change It may be better to stop the recursion when too much file are present and the exploration is slow.

source

pub const REQUIRED_HEIGHT: usize = 80usize

source

pub fn set_required_height(&mut self, height: usize)

Set the required height to a given value. The required height is used to stop filling the view content.

source

pub fn increase_required_height(&mut self)

The required height is used to stop filling the view content.

source

pub fn increase_required_height_by_ten(&mut self)

Add 10 to the required height. The required height is used to stop filling the view content.

source

pub fn reset_required_height(&mut self)

Reset the required height to its default value : Self::MAX_HEIGHT The required height is used to stop filling the view content.

source

pub fn decrease_required_height(&mut self)

Decrement the required height if possible. The required height is used to stop filling the view content.

source

pub fn decrease_required_height_by_ten(&mut self)

Decrease the required height by 10 if possible The required height is used to stop filling the view content.

source

pub fn from_path( path: &Path, max_depth: usize, users_cache: &UsersCache, filter_kind: &FilterKind, show_hidden: bool, parent_position: Vec<usize> ) -> Result<Self>

Recursively explore every subfolder to a certain depth. We start from path and add this node first. Then, for every subfolder, we start again. Files in path are added as simple nodes. Both (subfolder and files) ends in a collections of leaves.

source

pub fn clear(&mut self)

Clear every vector attributes of the tree. It’s used to free some unused memory.

source

pub fn file(&self) -> &FileInfo

A reference to the holded node fileinfo.

source

pub fn sort(&mut self)

Sort the leaves with current sort kind.

source

pub fn empty(path: &Path, users_cache: &UsersCache) -> Result<Self>

Creates an empty tree. Used when the user changes the CWD and hasn’t displayed a tree yet.

source

pub fn update_sort_from_char(&mut self, c: char)

source

pub fn select_root(&mut self)

Select the root node of the tree.

source

pub fn unselect_children(&mut self)

Unselect every node in the tree.

source

pub fn fold_children(&mut self)

Fold every node in the tree.

source

pub fn unfold_children(&mut self)

Unfold every node in the tree.

source

pub fn select_next_sibling(&mut self) -> Result<()>

Select the next “brother/sister” of a node. Sibling have the same parents (ie. are in the same directory). Since the position may be wrong (aka the current node is already the last child of it’s parent) we have to adjust the postion afterwards.

source

pub fn select_prev_sibling(&mut self) -> Result<()>

Select the previous “brother/sister” of a node. Sibling have the same parents (ie. are in the same directory). Since the position may be wrong (aka the current node is already the first child of it’s parent) we have to adjust the postion afterwards.

source

pub fn select_first_child(&mut self) -> Result<()>

Select the first child of a current node. Does nothing if the node has no child.

source

pub fn select_parent(&mut self) -> Result<()>

Move to the parent of current node. If the parent is the root node, it will do nothing.

source

pub fn go_to_bottom_leaf(&mut self) -> Result<()>

Move to the last leaf (bottom line on screen). We use a simple trick since we can’t know how much node there is at every step. We first create a position with max value (usize::MAX) and max size (Self::MAX_DEPTH). Then we select this node and adjust the position.

source

pub fn select_from_position(&mut self) -> Result<(usize, usize, Node)>

Select the node at a given position. Returns the reached depth, the last index and a copy of the node itself.

source

pub fn into_navigable_content( &mut self, colors: &Colors ) -> (usize, Vec<(String, ColoredString)>)

Depth first traversal of the tree. We navigate into the tree and format every element into a pair :

  • a prefix, wich is a string made of glyphs displaying the tree,
  • a colored string to be colored relatively to the file type. This method has to parse all the content until the bottom of screen is reached. There’s no way atm to avoid parsing the first lines since the “prefix” (straight lines at left of screen) can reach the whole screen.
source

pub fn select_first_match(&mut self, key: &str) -> Option<Vec<usize>>

Select the first node matching a key. We use a breath first search algorithm to ensure we select the less deep one.

source

pub fn explore_position(&mut self, unfold: bool) -> (&mut Tree, usize, usize)

Recursively explore the tree while only selecting the node from the position. Returns the reached tree, the reached depth and the last index. It may be used to fix the position. position is a vector of node indexes. At each step, we select the existing node. If unfold is set to true, it will unfold the trees as it traverses them. Since this method is used to fold every node, this parameter is required.

source

pub fn position_from_index(&self, index: usize) -> Vec<usize>

Trait Implementations§

source§

impl Clone for Tree

source§

fn clone(&self) -> Tree

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Tree

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnwindSafe for Tree

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for Twhere T: Any,

source§

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

source§

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

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneAny for Twhere T: Any + Clone + Send + Sync,

§

fn clone_any(&self) -> Box<dyn CloneAny + 'static, Global>

§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send + 'static, Global>

§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync + 'static, Global>

§

fn clone_any_send_sync( &self ) -> Box<dyn CloneAny + Send + Sync + 'static, Global>

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> DebugAny for Twhere T: Any + Debug,

§

impl<T> UnsafeAny for Twhere T: Any,