gitv_tui/ui/components/
status_bar.rs1use rat_widget::statusline_stacked::StatusLineStacked;
2use ratatui::buffer::Buffer;
3use ratatui::style::{Style, Stylize};
4use ratatui::widgets::Widget;
5use ratatui_macros::{line, span};
6use std::sync::atomic::Ordering;
7
8use crate::ui::components::DumbComponent;
9use crate::ui::components::issue_list::LOADED_ISSUE_COUNT;
10use crate::ui::{AppState, layout::Layout};
11
12pub struct StatusBar {
13 repo_label: String,
14 user_label: String,
15}
16
17impl StatusBar {
18 pub fn new(app_state: AppState) -> Self {
19 Self {
20 repo_label: format!(" {}/{} ", app_state.owner, app_state.repo),
21 user_label: app_state.current_user,
22 }
23 }
24
25 pub fn render(&mut self, area: Layout, buf: &mut Buffer) {
26 let issue_count = LOADED_ISSUE_COUNT.load(Ordering::Relaxed);
27 let count_text = format!(" Issues: {} ", issue_count);
28
29 let label = &self.user_label;
30 let mut ss = StatusLineStacked::new()
31 .start(
32 line![
33 span!(" Logged in as").style(Style::new().black().on_green()),
34 span!(" ").style(Style::new().black().on_green()),
35 span!(label).bold().black().on_green(),
36 span!(" ").style(Style::new().black().on_green()),
37 ],
38 " ",
39 )
40 .start(span!(self.repo_label.as_str()).style(Style::new()), " ")
41 .end(span!(count_text).style(Style::new().black().on_blue()), "")
42 .end(
43 line![
44 span!("q/<C-q>/<C-c").magenta(),
45 " ",
46 span!(" QUIT ").black().on_magenta().bold()
47 ],
48 " ",
49 )
50 .end(
51 line![
52 span!("?").magenta(),
53 " ",
54 span!(" HELP ").black().on_magenta().bold()
55 ],
56 " ",
57 );
58 #[cfg(target_os = "macos")]
59 {
60 ss = ss.end(
61 line![
62 span!("<C-H>").magenta(),
63 " ",
64 span!(" GLOBAL HELP ").black().on_magenta().bold()
65 ],
66 " ",
67 );
68 }
69 #[cfg(not(target_os = "macos"))]
70 {
71 ss = ss.end(
72 line![
73 span!("<C-h>").magenta(),
74 " ",
75 span!(" GLOBAL HELP ").black().on_magenta().bold()
76 ],
77 " ",
78 );
79 }
80 ss.render(area.status_bar, buf);
81 }
82}
83
84impl DumbComponent for StatusBar {
85 fn render(&mut self, area: Layout, buf: &mut Buffer) {
86 self.render(area, buf);
87 }
88}