diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-04-27 21:40:18 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-04-27 21:40:18 +0200 |
| commit | 8fbac3c232691c18c410ad7e80f4f2108b3a8163 (patch) | |
| tree | 0595206851f56db233261ab87c9973408770724e /pkgs/by-name/lf/lf-make-map/src/mapping/map_tree/display.rs | |
| parent | pkgs/lf-make-map: Reduce flake to a simple dev shell (diff) | |
| download | nixos-config-8fbac3c232691c18c410ad7e80f4f2108b3a8163.zip | |
pkgs/lf-make-map: Use trinitrix's keymaps library
The library was largely modelled after the previously used `MappingTrie`. Thus using that results in code deduplication.
Diffstat (limited to 'pkgs/by-name/lf/lf-make-map/src/mapping/map_tree/display.rs')
| -rw-r--r-- | pkgs/by-name/lf/lf-make-map/src/mapping/map_tree/display.rs | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/pkgs/by-name/lf/lf-make-map/src/mapping/map_tree/display.rs b/pkgs/by-name/lf/lf-make-map/src/mapping/map_tree/display.rs deleted file mode 100644 index 4625289a..00000000 --- a/pkgs/by-name/lf/lf-make-map/src/mapping/map_tree/display.rs +++ /dev/null @@ -1,101 +0,0 @@ -// nixos-config - My current NixOS configuration -// -// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of my nixos-config. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - -use std::fmt::Display; - -use crate::mapping::{ - map_tree::{Node, NodeValue}, - MapKey, -}; - -use super::MappingTree; - -impl Display for MappingTree { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - fn write_node( - f: &mut std::fmt::Formatter<'_>, - node: &Node, - indention: String, - location: Vec<MapKey>, - is_last: bool, - is_root: bool, - ) -> std::fmt::Result { - let node_value = match &node.value { - NodeValue::Parent { children: _ } => "<Parent>".to_owned(), - NodeValue::Child { path, extandable } => { - path.to_owned() + if *extandable { " [exten.]" } else { " [stop]" } - } - }; - - let new_idention = indention.clone() - + if is_root { - "" - } else { - match is_last { - true => " ", - false => "│ ", - } - }; - - let bullet = match is_last { - true => String::from("└── "), - false => String::from("├── "), - }; - - if is_root { - write!(f, ": {}\n", node_value)?; - } else { - write!( - f, - "{}{}\x1b[1;33m{}\x1b[0m: {}\n", - indention, - bullet, - MapKey::display(&location), - node_value, - )?; - }; - - match &node.value { - NodeValue::Parent { children } => { - let mut children_vec: Vec<(&MapKey, &Node)> = children.iter().collect(); - children_vec.sort_by(|(a, _), (b, _)| a.key.cmp(&b.key)); - - let mut counter = 1; - for (key, child) in &children_vec { - let mut new_location = location.clone(); - new_location.push((*key).to_owned()); - - write_node( - f, - child, - new_idention.clone(), - new_location.clone(), - counter == children_vec.len(), - false, - )?; - counter += 1; - } - } - NodeValue::Child { - path: _, - extandable: _, - } => { - // Do nothing and stop the recursion - } - } - - Ok(()) - } - - write_node(f, &self.root, String::new(), vec![], false, true)?; - - Ok(()) - } -} |
