1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Owns rendered output blocks and their placement around the prompt.
use std::collections::HashMap;
use crate::terminal_history_generation::TerminalHistoryGeneration;
use crate::{BlockId, StyledBlock};
/// Rendered output blocks and their placement around the prompt.
pub(super) struct BlockLayoutState {
/// Central block storage.
pub(super) blocks: HashMap<BlockId, StyledBlock>,
/// Human-readable labels for diagnostics.
pub(super) block_debug_ids: HashMap<BlockId, String>,
/// Next auto-increment id.
pub(super) next_id: u64,
/// Persistent output — append-only ordered list of block ids.
pub(super) history: Vec<BlockId>,
/// Reference count of block ids present in `history`.
pub(super) history_refs: HashMap<BlockId, usize>,
/// Bumped whenever persistent history content, order, or layout changes.
pub(super) history_generation: TerminalHistoryGeneration,
/// Earliest history entry changed since the redraw cache last refreshed.
///
/// Ordinary output appends and removals mark their changed suffix. Content
/// changes conservatively invalidate from entry zero.
pub(super) history_dirty_from: Option<usize>,
/// Number of history entries inspected by removal in test builds.
#[cfg(test)]
pub(super) history_removal_scan_entries: usize,
/// Mutable blocks above the prompt (can be reordered).
pub(super) above_active: Vec<BlockId>,
/// Blocks pinned right above the prompt.
pub(super) above_sticky: Vec<BlockId>,
/// Blocks rendered immediately below the input line (e.g. completion
/// menus), between the prompt and `below`.
pub(super) suggestions: Vec<BlockId>,
/// Blocks rendered below suggestions.
pub(super) below: Vec<BlockId>,
}
impl BlockLayoutState {
/// Creates empty block storage and placement zones.
pub(super) fn new() -> Self {
Self {
blocks: HashMap::new(),
block_debug_ids: HashMap::new(),
next_id: 0,
history: Vec::new(),
history_refs: HashMap::new(),
history_generation: TerminalHistoryGeneration::default(),
history_dirty_from: None,
#[cfg(test)]
history_removal_scan_entries: 0,
above_active: Vec::new(),
above_sticky: Vec::new(),
suggestions: Vec::new(),
below: Vec::new(),
}
}
}