diff --git a/.vscode/launch.json b/.vscode/launch.json index 4f8d508271..e3d5cc69e4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,6 +8,16 @@ "program": "${workspaceRoot}/target/debug/gitui", "args": [], "cwd": "${workspaceRoot}", - } + }, + { + "name": "Attach to cargo run of executable 'gitui'", + "type": "lldb", + "request": "attach", + "program": "${workspaceFolder}/target/debug/gitui", + "stopOnEntry": false, + "sourceLanguages": [ + "rust" + ], + }, ] } \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index eb804e6fdd..096b1c436f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -30,7 +30,10 @@ use crate::{ strings::{self, ellipsis_trim_start, order}, tabs::{FilesTab, Revlog, StashList, Stashing, Status}, try_or_popup, - ui::style::{SharedTheme, Theme}, + ui::{ + mask, + style::{SharedTheme, Theme}, + }, AsyncAppNotification, AsyncNotification, }; use anyhow::{bail, Result}; @@ -295,6 +298,15 @@ impl App { 4 => self.stashlist_tab.draw(f, chunks_main[1])?, _ => bail!("unknown tab"), } + + if self.any_popup_visible() { + // "Tints" the background whenever a popup is open. + // NB: Order is important. We manipulate the entire layout chunk + // assigned to the tab, without the knowledge of where the + // popup is located. Thus, we must tint before drawing the + // popup. + mask::draw_mask(f, chunks_main[1]); + } } self.draw_popups(f)?; diff --git a/src/ui/mask.rs b/src/ui/mask.rs new file mode 100644 index 0000000000..aa3454c23e --- /dev/null +++ b/src/ui/mask.rs @@ -0,0 +1,33 @@ +use ratatui::style::{Color, Style}; +use ratatui::widgets::Widget; +use ratatui::Frame; +use ratatui::{buffer::Buffer, layout::Rect}; + +struct Mask; + +impl Widget for Mask { + fn render(self, area: Rect, buf: &mut Buffer) { + for y in area.top()..area.bottom() { + for x in area.left()..area.right() { + if let Some(cell) = buf.cell_mut((x, y)) { + // TODO(prprabhu): What do we want here? + // Question 1: Set background color vs foreground color + // Question 2: What color should we set to? The total number + // of colors available to us across all backends is + // limited, and we can't really tint the theme colors due + // to the limited number of colors available. + // Question 3: Should we pick a reasonable color and add it + // to the theme? + cell.set_style( + Style::default().fg(Color::DarkGray), + ); + } + } + } + } +} + +pub fn draw_mask(frame: &mut Frame, rect: Rect) { + let mask = Mask; + frame.render_widget(mask, rect); +} diff --git a/src/ui/mod.rs b/src/ui/mod.rs index f0ee1539f9..3c670563ab 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,3 +1,4 @@ +pub mod mask; mod reflow; mod scrollbar; mod scrolllist;