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: NodeImplementations§
source§impl Tree
impl Tree
sourcepub const MAX_DEPTH: usize = 5usize
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.
pub const REQUIRED_HEIGHT: usize = 80usize
sourcepub fn set_required_height(&mut self, height: usize)
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.
sourcepub fn increase_required_height(&mut self)
pub fn increase_required_height(&mut self)
The required height is used to stop filling the view content.
sourcepub fn increase_required_height_by_ten(&mut self)
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.
sourcepub fn reset_required_height(&mut self)
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.
sourcepub fn decrease_required_height(&mut self)
pub fn decrease_required_height(&mut self)
Decrement the required height if possible. The required height is used to stop filling the view content.
sourcepub fn decrease_required_height_by_ten(&mut self)
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.
sourcepub fn from_path(
path: &Path,
max_depth: usize,
users_cache: &UsersCache,
filter_kind: &FilterKind,
show_hidden: bool,
parent_position: Vec<usize>
) -> Result<Self>
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.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear every vector attributes of the tree. It’s used to free some unused memory.
sourcepub fn empty(path: &Path, users_cache: &UsersCache) -> Result<Self>
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.
pub fn update_sort_from_char(&mut self, c: char)
sourcepub fn select_root(&mut self)
pub fn select_root(&mut self)
Select the root node of the tree.
sourcepub fn unselect_children(&mut self)
pub fn unselect_children(&mut self)
Unselect every node in the tree.
sourcepub fn fold_children(&mut self)
pub fn fold_children(&mut self)
Fold every node in the tree.
sourcepub fn unfold_children(&mut self)
pub fn unfold_children(&mut self)
Unfold every node in the tree.
sourcepub fn select_next_sibling(&mut self) -> Result<()>
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.
sourcepub fn select_prev_sibling(&mut self) -> Result<()>
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.
sourcepub fn select_first_child(&mut self) -> Result<()>
pub fn select_first_child(&mut self) -> Result<()>
Select the first child of a current node. Does nothing if the node has no child.
sourcepub fn select_parent(&mut self) -> Result<()>
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.
sourcepub fn go_to_bottom_leaf(&mut self) -> Result<()>
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.
sourcepub fn select_from_position(&mut self) -> Result<(usize, usize, Node)>
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.
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.
sourcepub fn select_first_match(&mut self, key: &str) -> Option<Vec<usize>>
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.
sourcepub fn explore_position(&mut self, unfold: bool) -> (&mut Tree, usize, usize)
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.