1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
mod list; pub use list::*; mod tree; mod tree_lib; use crate::{query::ListQuery, script_time::ScriptTime}; use colored::{ColoredString, Colorize}; use std::borrow::Cow; fn time_str<T: Clone + std::fmt::Debug>(time: &Option<ScriptTime<T>>) -> Cow<'static, str> { match time { None => Cow::Borrowed("Never"), Some(t) => Cow::Owned(t.to_string()), } } #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub enum DisplayIdentStyle { File, Name, Normal, } #[derive(Debug, Eq, PartialEq)] pub enum DisplayStyle<T, U> { Short(DisplayIdentStyle, U), Long(T), } #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub enum Grouping { Tag, Tree, None, } impl Grouping { pub fn is_none(self) -> bool { self == Grouping::None } } impl<T: AsRef<str>> From<T> for Grouping { fn from(s: T) -> Self { match s.as_ref() { "tag" => Grouping::Tag, "tree" => Grouping::Tree, "none" => Grouping::None, _ => unreachable!(), } } } #[derive(Debug)] pub struct ListOptions<'a, T = (), U = ()> { pub grouping: Grouping, pub queries: &'a [ListQuery], pub plain: bool, pub display_style: DisplayStyle<T, U>, } #[inline] fn style<T: AsRef<str>, F: FnOnce(ColoredString) -> ColoredString>( plain: bool, s: T, f: F, ) -> ColoredString { let s = s.as_ref().normal(); if !plain { f(s) } else { s } }