]> git.proxmox.com Git - rustc.git/blob - vendor/prodash/src/render/tui/draw/information.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / prodash / src / render / tui / draw / information.rs
1 use tui::{
2 buffer::Buffer,
3 layout::Rect,
4 style::{Modifier, Style},
5 text::Span,
6 widgets::{Block, Borders, Widget},
7 };
8
9 use crate::render::tui::{
10 utils::{block_width, draw_text_with_ellipsis_nowrap, rect},
11 Line,
12 };
13
14 pub fn pane(lines: &[Line], bound: Rect, buf: &mut Buffer) {
15 let bold = Style::default().add_modifier(Modifier::BOLD);
16 let block = Block::default()
17 .title(Span::styled("Information", bold))
18 .borders(Borders::TOP | Borders::BOTTOM);
19 let inner_bound = block.inner(bound);
20 block.render(bound, buf);
21
22 let help_text = " ⨯ = [ | ▢ = { ";
23 draw_text_with_ellipsis_nowrap(rect::snap_to_right(bound, block_width(help_text)), buf, help_text, bold);
24
25 let bound = Rect {
26 width: inner_bound.width.saturating_sub(1),
27 ..inner_bound
28 };
29 let mut offset = 0;
30 for (line, info) in lines.windows(2).enumerate() {
31 let (info, next_info) = (&info[0], &info[1]);
32 let line = line + offset;
33 if line >= bound.height as usize {
34 break;
35 }
36 let line_bound = rect::line_bound(bound, line);
37 match info {
38 Line::Title(text) => {
39 let blocks_drawn = draw_text_with_ellipsis_nowrap(line_bound, buf, text, bold);
40 let lines_rect = rect::offset_x(line_bound, blocks_drawn + 1);
41 for x in lines_rect.left()..lines_rect.right() {
42 buf.get_mut(x, lines_rect.y).symbol = "─".into();
43 }
44 offset += 1;
45 }
46 Line::Text(text) => {
47 draw_text_with_ellipsis_nowrap(rect::offset_x(line_bound, 1), buf, text, None);
48 }
49 };
50 if let Line::Title(_) = next_info {
51 offset += 1;
52 }
53 }
54
55 if let Some(Line::Text(text)) = lines.last() {
56 let line = lines.len().saturating_sub(1) + offset;
57 if line < bound.height as usize {
58 draw_text_with_ellipsis_nowrap(rect::offset_x(rect::line_bound(bound, line), 1), buf, text, bold);
59 }
60 }
61 }