ratatui_toolkit/widgets/code_diff/widget/methods/helpers/
render_hunk_header.rs1use ratatui::buffer::Buffer;
2use ratatui::layout::{Position, Rect};
3use ratatui::style::Style;
4
5use crate::widgets::code_diff::diff_config::DiffConfig;
6use crate::widgets::code_diff::diff_hunk::DiffHunk;
7
8#[allow(dead_code)]
17pub fn render_hunk_header(hunk: &DiffHunk, config: &DiffConfig, area: Rect, buf: &mut Buffer) {
18 if area.height == 0 || area.width == 0 {
19 return;
20 }
21
22 let style = Style::default()
23 .bg(config.hunk_header_bg)
24 .fg(config.hunk_header_fg);
25
26 for x in area.x..area.x + area.width {
28 if let Some(cell) = buf.cell_mut(Position::new(x, area.y)) {
29 cell.set_style(style);
30 cell.set_char(' ');
31 }
32 }
33
34 let header_text = hunk.header_text();
36 let mut x = area.x + 1;
37
38 for ch in header_text.chars() {
39 if x >= area.x + area.width {
40 break;
41 }
42 if let Some(cell) = buf.cell_mut(Position::new(x, area.y)) {
43 cell.set_char(ch);
44 cell.set_style(style);
45 }
46 x += 1;
47 }
48}