| 42 | |
| 43 | impl RollingBuffer { |
| 44 | fn new(title: &str) -> Self { |
| 45 | let term = Term::stderr(); |
| 46 | let (rows, cols) = term.size(); |
| 47 | let rows = rows as usize; |
| 48 | let cols = cols as usize; |
| 49 | |
| 50 | let active = *IS_TTY && rows >= 5; |
| 51 | // Reserve space for title + delimiters |
| 52 | let max_lines = if active { |
| 53 | 20.min(rows.saturating_sub(6)) |
| 54 | } else { |
| 55 | 0 |
| 56 | }; |
| 57 | |
| 58 | Self { |
| 59 | lines: VecDeque::with_capacity(max_lines), |
| 60 | max_lines, |
| 61 | total_lines: 0, |
| 62 | rendered_count: 0, |
| 63 | term, |
| 64 | term_width: cols, |
| 65 | active, |
| 66 | title: title.to_string(), |
| 67 | start: Instant::now(), |
| 68 | finished: false, |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | pub fn is_active(&self) -> bool { |
| 73 | self.active |