Struct ptree::print_config::PrintConfig
source · [−]pub struct PrintConfig {
pub depth: u32,
pub indent: usize,
pub padding: usize,
pub styled: StyleWhen,
pub characters: IndentChars,
pub branch: Style,
pub leaf: Style,
}
Expand description
Structure controlling the print output formatting
Fields
depth: u32
Maximum recursion depth when printing
The default is infinity, i.e. there is no recursion limit.
indent: usize
Indentation size. The default value is 3.
padding: usize
Padding size. The default value is 1.
styled: StyleWhen
Control when output is styled.
The default value is StyleWhen::Tty
, meaning that ANSI styles are only used for printing to the standard
output, and only when the standard output is a TTY.
characters: IndentChars
Characters used to print indentation lines or “branches” of the tree
branch: Style
ANSI style used for printing the indentation lines (“branches”)
leaf: Style
ANSI style used for printing the item text (“leaves”)
Implementations
sourceimpl PrintConfig
impl PrintConfig
sourcepub fn from_env() -> PrintConfig
pub fn from_env() -> PrintConfig
Load print configuration from a configuration file or environment variables
Configuration files and variables
If the PTREE_CONFIG
environment variable is set, its value is used as the path to a file
from which to read to configuration parameters.
Otherwise, any file with a stem of ptree
inside the directory returned by [config_dir
]
is used.
Finally, environment variables may be used to override the values from the configuration file.
For every field of the PrintConfig
structure, the corresponding environment variable name
is PTREE_<FIELD_NAME>, for example PTREE_INDENT=4
sets the indent
field to 4.
Nested fields are supported; to set the branch foreground color use PTREE_BRANCH_FOREGROUND=red
.
Field values
[indent
] and [depth
] accept non-negative integers.
[styled
] accepts either "always"
, "tty"
or "never"
[leaf
] and [branch
] accept a Style
structure.
In a configuration file, this takes a form of a map.
Using environment variables, each field has to be set separately.
Color fields accept either an ANSI named color, a named web color, a hex code like “#33ffbb”, an ANSI integer fixed color, or a [red, green, blue] triple of non-negative integers.
Other Style
fields are boolean parameters.
In a configuration file, they are parsed according to the rules of the deserialization format.
In an environment variables, TRUE
, ON
and 1
evaluate to true
, and FALSE
, OFF
and 0
evaluate to false
. Environment variable values are case insensitive.
[characters
] can be set to a string with a value of “utf”, “ascii”, “ascii-plus”, “utf-bold”, “utf-double”
or “utf-dashed”. Alternatively, it can be set to a structure with each of their fields set to the
appropriate character.
Configuration file example
indent = 3
depth = 100
styled = "tty"
[branch]
foreground = "red"
dimmed = true
bold = false
[leaf]
foreground = "MediumSeaGreen"
background = "#102018"
Errors
This function does not report errors.
If anything goes wrong while loading the configuration parameters, a default PrintConfig
is returned.
sourcepub fn should_style_output(&self, output_kind: OutputKind) -> bool
pub fn should_style_output(&self, output_kind: OutputKind) -> bool
Checks if output to a writer should be styled
sourcepub fn paint_branch(&self, input: impl Display) -> impl Display
pub fn paint_branch(&self, input: impl Display) -> impl Display
Formats input
according to the branch style
This function is a wrapper that is available even without the "ansi"
feature.
Without that feature it returns the input unchanged.
sourcepub fn paint_leaf(&self, input: impl Display) -> impl Display
pub fn paint_leaf(&self, input: impl Display) -> impl Display
Formats input
according to the leaf style
This function is a wrapper that is available even without the "ansi"
feature.
Without that feature it returns the input unchanged.
Trait Implementations
sourceimpl Clone for PrintConfig
impl Clone for PrintConfig
sourcefn clone(&self) -> PrintConfig
fn clone(&self) -> PrintConfig
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for PrintConfig
impl Debug for PrintConfig
sourceimpl Default for PrintConfig
impl Default for PrintConfig
sourcefn default() -> PrintConfig
fn default() -> PrintConfig
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for PrintConfig where
PrintConfig: Default,
impl<'de> Deserialize<'de> for PrintConfig where
PrintConfig: Default,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<PrintConfig> for PrintConfig
impl PartialEq<PrintConfig> for PrintConfig
sourcefn eq(&self, other: &PrintConfig) -> bool
fn eq(&self, other: &PrintConfig) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PrintConfig) -> bool
fn ne(&self, other: &PrintConfig) -> bool
This method tests for !=
.
sourceimpl Serialize for PrintConfig
impl Serialize for PrintConfig
impl StructuralPartialEq for PrintConfig
Auto Trait Implementations
impl RefUnwindSafe for PrintConfig
impl Send for PrintConfig
impl Sync for PrintConfig
impl Unpin for PrintConfig
impl UnwindSafe for PrintConfig
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more