Skip to main content

terminal/
types.rs

1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use vt100::Screen;
6
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct SizeInfo {
9    pub width: f32,
10    pub height: f32,
11    pub cell_width: f32,
12    pub cell_height: f32,
13    pub padding_x: f32,
14    pub padding_y: f32,
15    pub dpr: f32,
16}
17
18pub enum Scroll {
19    Lines(isize),
20    PageUp,
21    PageDown,
22    Bottom,
23    Top,
24}
25
26impl Scroll {
27    pub fn scroll_screen(&self, screen: &mut Screen) {
28        let scrollback = screen.scrollback_len();
29        let (visible_lines, _) = screen.size();
30        let visible_lines = visible_lines.into();
31        let history = scrollback.saturating_add(visible_lines);
32
33        let new_scroll = match self {
34            Scroll::Lines(lines) => scrollback.saturating_add_signed(*lines),
35            Scroll::PageUp => scrollback.saturating_add(visible_lines),
36            Scroll::PageDown => scrollback.saturating_sub(visible_lines),
37            Scroll::Top => history,
38            Scroll::Bottom => 0,
39        };
40
41        let clamped = new_scroll.max(0).min(history);
42        screen.set_scrollback(clamped);
43    }
44}