pub struct StyleMap {Show 67 fields
pub default: CompoundStyle,
pub tree: CompoundStyle,
pub parent: CompoundStyle,
pub file: CompoundStyle,
pub directory: CompoundStyle,
pub exe: CompoundStyle,
pub link: CompoundStyle,
pub pruning: CompoundStyle,
pub perm__: CompoundStyle,
pub perm_r: CompoundStyle,
pub perm_w: CompoundStyle,
pub perm_x: CompoundStyle,
pub owner: CompoundStyle,
pub group: CompoundStyle,
pub count: CompoundStyle,
pub dates: CompoundStyle,
pub sparse: CompoundStyle,
pub content_extract: CompoundStyle,
pub content_match: CompoundStyle,
pub device_id_major: CompoundStyle,
pub device_id_sep: CompoundStyle,
pub device_id_minor: CompoundStyle,
pub git_branch: CompoundStyle,
pub git_insertions: CompoundStyle,
pub git_deletions: CompoundStyle,
pub git_status_current: CompoundStyle,
pub git_status_modified: CompoundStyle,
pub git_status_new: CompoundStyle,
pub git_status_ignored: CompoundStyle,
pub git_status_conflicted: CompoundStyle,
pub git_status_other: CompoundStyle,
pub selected_line: CompoundStyle,
pub char_match: CompoundStyle,
pub file_error: CompoundStyle,
pub flag_label: CompoundStyle,
pub flag_value: CompoundStyle,
pub input: CompoundStyle,
pub status_error: CompoundStyle,
pub status_job: CompoundStyle,
pub status_normal: CompoundStyle,
pub status_italic: CompoundStyle,
pub status_bold: CompoundStyle,
pub status_code: CompoundStyle,
pub status_ellipsis: CompoundStyle,
pub purpose_normal: CompoundStyle,
pub purpose_italic: CompoundStyle,
pub purpose_bold: CompoundStyle,
pub purpose_ellipsis: CompoundStyle,
pub scrollbar_track: CompoundStyle,
pub scrollbar_thumb: CompoundStyle,
pub help_paragraph: CompoundStyle,
pub help_bold: CompoundStyle,
pub help_italic: CompoundStyle,
pub help_code: CompoundStyle,
pub help_headers: CompoundStyle,
pub help_table_border: CompoundStyle,
pub preview: CompoundStyle,
pub preview_title: CompoundStyle,
pub preview_line_number: CompoundStyle,
pub preview_match: CompoundStyle,
pub hex_null: CompoundStyle,
pub hex_ascii_graphic: CompoundStyle,
pub hex_ascii_whitespace: CompoundStyle,
pub hex_ascii_other: CompoundStyle,
pub hex_non_ascii: CompoundStyle,
pub staging_area_title: CompoundStyle,
pub mode_command_mark: CompoundStyle,
/* private fields */
}
Expand description
a struct whose fields are
- a boolean telling whether it’s a no-style map
- the styles to apply to various parts/cases
Fields§
§default: CompoundStyle
§tree: CompoundStyle
§parent: CompoundStyle
§file: CompoundStyle
§directory: CompoundStyle
§exe: CompoundStyle
§link: CompoundStyle
§pruning: CompoundStyle
§perm__: CompoundStyle
§perm_r: CompoundStyle
§perm_w: CompoundStyle
§perm_x: CompoundStyle
§owner: CompoundStyle
§group: CompoundStyle
§count: CompoundStyle
§dates: CompoundStyle
§sparse: CompoundStyle
§content_extract: CompoundStyle
§content_match: CompoundStyle
§device_id_major: CompoundStyle
§device_id_sep: CompoundStyle
§device_id_minor: CompoundStyle
§git_branch: CompoundStyle
§git_insertions: CompoundStyle
§git_deletions: CompoundStyle
§git_status_current: CompoundStyle
§git_status_modified: CompoundStyle
§git_status_new: CompoundStyle
§git_status_ignored: CompoundStyle
§git_status_conflicted: CompoundStyle
§git_status_other: CompoundStyle
§selected_line: CompoundStyle
§char_match: CompoundStyle
§file_error: CompoundStyle
§flag_label: CompoundStyle
§flag_value: CompoundStyle
§input: CompoundStyle
§status_error: CompoundStyle
§status_job: CompoundStyle
§status_normal: CompoundStyle
§status_italic: CompoundStyle
§status_bold: CompoundStyle
§status_code: CompoundStyle
§status_ellipsis: CompoundStyle
§purpose_normal: CompoundStyle
§purpose_italic: CompoundStyle
§purpose_bold: CompoundStyle
§purpose_ellipsis: CompoundStyle
§scrollbar_track: CompoundStyle
§scrollbar_thumb: CompoundStyle
§help_paragraph: CompoundStyle
§help_bold: CompoundStyle
§help_italic: CompoundStyle
§help_code: CompoundStyle
§help_headers: CompoundStyle
§help_table_border: CompoundStyle
§preview: CompoundStyle
§preview_title: CompoundStyle
§preview_line_number: CompoundStyle
§preview_match: CompoundStyle
§hex_null: CompoundStyle
§hex_ascii_graphic: CompoundStyle
§hex_ascii_whitespace: CompoundStyle
§hex_ascii_other: CompoundStyle
§hex_non_ascii: CompoundStyle
§staging_area_title: CompoundStyle
§mode_command_mark: CompoundStyle
Implementations§
source§impl StyleMap
impl StyleMap
sourcepub fn queue_reset<W: Write>(&self, f: &mut W) -> Result<(), ProgramError>
pub fn queue_reset<W: Write>(&self, f: &mut W) -> Result<(), ProgramError>
Examples found in repository?
src/display/displayable_tree.rs (line 476)
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
pub fn write_on<W: Write>(&self, f: &mut W) -> Result<(), ProgramError> {
#[cfg(not(any(target_family = "windows", target_os = "android")))]
let perm_writer = super::PermWriter::for_tree(self.skin, self.tree);
let tree = self.tree;
let total_size = tree.total_sum();
let scrollbar = if self.in_app {
termimad::compute_scrollbar(
tree.scroll,
tree.lines.len() - 1, // the root line isn't scrolled
self.area.height - 1, // the scrollbar doesn't cover the first line
self.area.top + 1,
)
} else {
None
};
if self.in_app {
f.queue(cursor::MoveTo(self.area.left, self.area.top))?;
}
let mut cw = CropWriter::new(f, self.area.width as usize);
let pattern_object = tree.options.pattern.pattern.object();
self.write_root_line(&mut cw, self.in_app && tree.selection == 0)?;
self.skin.queue_reset(f)?;
let visible_cols: Vec<Col> = tree
.options
.cols_order
.iter()
.filter(|col| col.is_visible(tree, self.app_state))
.cloned()
.collect();
// if necessary we compute the width of the count column
let count_len = if tree.options.show_counts {
tree.lines.iter()
.skip(1) // we don't show the counts of the root
.map(|l| l.sum.map_or(0, |s| s.to_count()))
.max()
.map(|c| format_count(c).len())
.unwrap_or(0)
} else {
0
};
// we compute the length of the dates, depending on the format
let date_len = if tree.options.show_dates {
let date_time: DateTime<Local> = Local::now();
date_time.format(tree.options.date_time_format).to_string().len()
} else {
0 // we don't care
};
for y in 1..self.area.height {
if self.in_app {
f.queue(cursor::MoveTo(self.area.left, y + self.area.top))?;
} else {
write!(f, "\r\n")?;
}
let mut line_index = y as usize;
if line_index > 0 {
line_index += tree.scroll as usize;
}
let mut selected = false;
let mut cw = CropWriter::new(f, self.area.width as usize);
let cw = &mut cw;
if line_index < tree.lines.len() {
let line = &tree.lines[line_index];
selected = self.in_app && line_index == tree.selection;
let label_style = self.label_style(line, selected);
let mut in_branch = false;
let space_style = if selected {
&self.skin.selected_line
} else {
&self.skin.default
};
if visible_cols[0].needs_left_margin() {
cw.queue_char(space_style, ' ')?;
}
let staged = self.app_state
.map_or(false, |a| a.stage.contains(&line.path));
for col in &visible_cols {
let void_len = match col {
Col::Mark => {
self.write_line_selection_mark(cw, &label_style, selected)?
}
Col::Git => {
self.write_line_git_status(cw, line, selected)?
}
Col::Branch => {
in_branch = true;
self.write_branch(cw, line_index, line, selected, staged)?
}
Col::DeviceId => {
#[cfg(not(unix))]
{ 0 }
#[cfg(unix)]
self.write_line_device_id(cw, line, selected)?
}
Col::Permission => {
#[cfg(any(target_family = "windows", target_os = "android"))]
{ 0 }
#[cfg(not(any(target_family = "windows", target_os = "android")))]
perm_writer.write_permissions(cw, line, selected)?
}
Col::Date => {
if let Some(seconds) = line.sum.and_then(|sum| sum.to_valid_seconds()) {
self.write_date(cw, seconds, selected)?
} else {
date_len + 1
}
}
Col::Size => {
if tree.options.sort.prevent_deep_display() {
// as soon as there's only one level displayed we can show the size bars
self.write_line_size_with_bar(cw, line, &label_style, total_size, selected)?
} else {
self.write_line_size(cw, line, &label_style, selected)?
}
}
Col::Count => {
self.write_line_count(cw, line, count_len, selected)?
}
Col::Staged => {
self.write_line_stage_mark(cw, &label_style, staged)?
}
Col::Name => {
in_branch = false;
self.write_line_label(cw, line, &label_style, pattern_object, selected)?
}
};
// void: intercol & replacing missing cells
if in_branch && void_len > 2 {
cond_bg!(void_style, self, selected, self.skin.tree);
cw.repeat(void_style, &BRANCH_FILLING, void_len)?;
} else {
cond_bg!(void_style, self, selected, self.skin.default);
cw.repeat(void_style, &SPACE_FILLING, void_len)?;
}
}
if cw.allowed > 8 && pattern_object.content {
let extract = tree.options.pattern.pattern
.search_content(&line.path, cw.allowed - 2);
if let Some(extract) = extract {
self.write_content_extract(cw, extract, selected)?;
}
}
}
self.extend_line_bg(cw, selected)?;
self.skin.queue_reset(f)?;
if self.in_app {
if let Some((sctop, scbottom)) = scrollbar {
f.queue(cursor::MoveTo(self.area.left + self.area.width - 1, y))?;
let style = if sctop <= y && y <= scbottom {
&self.skin.scrollbar_thumb
} else {
&self.skin.scrollbar_track
};
style.queue_str(f, "▐")?;
}
}
}
if !self.in_app {
write!(f, "\r\n")?;
}
Ok(())
}
source§impl StyleMap
impl StyleMap
sourcepub fn no_term() -> Self
pub fn no_term() -> Self
build a skin without any terminal control character (for file output)
Examples found in repository?
src/print.rs (line 91)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
pub fn print_tree(
tree: &Tree,
screen: Screen,
panel_skin: &PanelSkin,
con: &AppContext,
) -> Result<CmdResult, ProgramError> {
// We write on stdout, but we must do it after app closing to have the normal terminal
let show_color = con.launch_args.color.unwrap_or_else(|| stdout().is_tty());
let styles = if show_color {
panel_skin.styles.clone()
} else {
StyleMap::no_term()
};
Ok(CmdResult::from(Launchable::tree_printer(
tree,
screen,
styles,
con.ext_colors.clone(),
)))
}
More examples
src/skin/app_skin.rs (line 25)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
pub fn new(conf: &Conf, no_style: bool) -> Self {
if no_style {
Self {
focused: PanelSkin::new(StyleMap::no_term()),
unfocused: PanelSkin::new(StyleMap::no_term()),
}
} else {
let def_skin;
let skin = if let Some(skin) = &conf.skin {
skin
} else {
def_skin = AHashMap::default();
&def_skin
};
let StyleMaps { focused, unfocused } = StyleMaps::create(skin);
Self {
focused: PanelSkin::new(focused),
unfocused: PanelSkin::new(unfocused),
}
}
}