mod.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. pub use self::cell::{TextCell, TextCellContents, DisplayWidth};
  2. pub use self::escape::escape;
  3. pub mod details;
  4. pub mod file_name;
  5. pub mod grid;
  6. pub mod grid_details;
  7. pub mod icons;
  8. pub mod lines;
  9. pub mod render;
  10. pub mod table;
  11. pub mod time;
  12. mod cell;
  13. mod escape;
  14. mod tree;
  15. /// The **view** contains all information about how to format output.
  16. #[derive(Debug)]
  17. pub struct View {
  18. pub mode: Mode,
  19. pub width: TerminalWidth,
  20. pub file_style: file_name::Options,
  21. pub deref_links: bool,
  22. }
  23. /// The **mode** is the “type” of output.
  24. #[derive(PartialEq, Eq, Debug)]
  25. #[allow(clippy::large_enum_variant)]
  26. pub enum Mode {
  27. Grid(grid::Options),
  28. Details(details::Options),
  29. GridDetails(grid_details::Options),
  30. Lines,
  31. }
  32. /// The width of the terminal requested by the user.
  33. #[derive(PartialEq, Eq, Debug, Copy, Clone)]
  34. pub enum TerminalWidth {
  35. /// The user requested this specific number of columns.
  36. Set(usize),
  37. /// Look up the terminal size at runtime.
  38. Automatic,
  39. }
  40. impl TerminalWidth {
  41. pub fn actual_terminal_width(self) -> Option<usize> {
  42. // All of stdin, stdout, and stderr could not be connected to a
  43. // terminal, but we’re only interested in stdout because it’s
  44. // where the output goes.
  45. match self {
  46. Self::Set(width) => Some(width),
  47. Self::Automatic => terminal_size::terminal_size().map(|(w, _)| w.0.into()),
  48. }
  49. }
  50. }