git_tailor/views/
main_view.rs1use ratatui::{
16 layout::Rect,
17 style::{Color, Style},
18 text::{Line, Span},
19 widgets::Paragraph,
20};
21
22use crate::app::AppState;
23use crate::repo::GitRepo;
24use crate::views;
25
26pub fn render(git_repo: &impl GitRepo, app: &mut AppState, frame: &mut ratatui::Frame) {
28 let area = frame.area();
29 const BASE_SPLIT_X: i32 = 72; const MIN_LEFT: i32 = 23;
34 const MIN_RIGHT: i32 = 20;
35 let max_offset = (area.width as i32 - BASE_SPLIT_X - MIN_RIGHT).max(0);
36 let min_offset = (MIN_LEFT - BASE_SPLIT_X).min(0);
37 let clamped_offset = (app.separator_offset as i32).clamp(min_offset, max_offset);
38 app.separator_offset = clamped_offset as i16;
39 let separator_x = ((BASE_SPLIT_X + clamped_offset) as u16).min(area.width);
40 let left_width = separator_x.min(area.width);
41 let right_width = area.width.saturating_sub(left_width);
42
43 if right_width > 0 {
44 let left_area = Rect {
45 x: area.x,
46 y: area.y,
47 width: left_width.saturating_sub(1), height: area.height,
49 };
50 let right_area = Rect {
51 x: area.x + left_width,
52 y: area.y,
53 width: right_width,
54 height: area.height,
55 };
56
57 let saved_offset = app.separator_offset;
62 views::commit_list::render_in_area_without_fragmap_cols(app, frame, left_area);
63 app.separator_offset = saved_offset;
64
65 let sep_height = area.height.saturating_sub(1); let separator_spans: Vec<Line> = (0..sep_height)
68 .map(|_| {
69 Line::from(Span::styled(
70 "│",
71 Style::new().fg(Color::White).bg(Color::Blue),
72 ))
73 })
74 .collect();
75 let sep_area = Rect {
76 x: left_area.x + left_width - 1,
77 y: area.y,
78 width: 1,
79 height: sep_height,
80 };
81 frame.render_widget(Paragraph::new(separator_spans), sep_area);
82
83 views::commit_detail::render(git_repo, frame, app, right_area);
84
85 let footer_area = Rect {
87 x: area.x,
88 y: area.y + area.height.saturating_sub(1),
89 width: area.width,
90 height: 1,
91 };
92 views::commit_list::render_footer(frame, app, footer_area);
93 } else {
94 views::commit_list::render(app, frame);
96 }
97}