diff options
Diffstat (limited to 'src/output/mod.rs')
-rw-r--r-- | src/output/mod.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/output/mod.rs b/src/output/mod.rs index 277c69e..14b4f15 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -1,6 +1,3 @@ -use crate::output::file_name::FileStyle; -use crate::style::Colours; - pub use self::cell::{TextCell, TextCellContents, DisplayWidth}; pub use self::escape::escape; @@ -23,8 +20,8 @@ mod tree; #[derive(Debug)] pub struct View { pub mode: Mode, - pub colours: Colours, - pub style: FileStyle, + pub width: TerminalWidth, + pub file_style: file_name::Options, } @@ -37,3 +34,28 @@ pub enum Mode { GridDetails(grid_details::Options), Lines(lines::Options), } + + +/// The width of the terminal requested by the user. +#[derive(PartialEq, Debug, Copy, Clone)] +pub enum TerminalWidth { + + /// The user requested this specific number of columns. + Set(usize), + + /// Look up the terminal size at runtime. + Automatic, +} + +impl TerminalWidth { + pub fn actual_terminal_width(self) -> Option<usize> { + // All of stdin, stdout, and stderr could not be connected to a + // terminal, but we’re only interested in stdout because it’s + // where the output goes. + + match self { + Self::Set(width) => Some(width), + Self::Automatic => term_size::dimensions_stdout().map(|t| t.0), + } + } +} |