use super::*;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ActivityIcon {
Explorer,
Search,
SourceControl,
Remote,
RunDebug,
Extensions,
Testing,
CodeQL,
Sponsor,
Settings,
}
impl ActivityIcon {
pub(super) fn view(self) -> Option<SidebarView> {
match self {
ActivityIcon::Explorer => Some(SidebarView::Explorer),
ActivityIcon::Search => Some(SidebarView::Search),
ActivityIcon::SourceControl => Some(SidebarView::SourceControl),
ActivityIcon::Remote => Some(SidebarView::Remote),
ActivityIcon::RunDebug => Some(SidebarView::RunDebug),
ActivityIcon::Extensions => Some(SidebarView::Extensions),
ActivityIcon::Testing => Some(SidebarView::Testing),
ActivityIcon::CodeQL => Some(SidebarView::CodeQL),
ActivityIcon::Sponsor | ActivityIcon::Settings => None,
}
}
pub(super) const ALL: [ActivityIcon; 10] = [
ActivityIcon::Explorer,
ActivityIcon::Search,
ActivityIcon::SourceControl,
ActivityIcon::Remote,
ActivityIcon::RunDebug,
ActivityIcon::Extensions,
ActivityIcon::Testing,
ActivityIcon::CodeQL,
ActivityIcon::Sponsor,
ActivityIcon::Settings,
];
pub(super) fn slot(self) -> Option<u16> {
match self {
ActivityIcon::Explorer => Some(0),
ActivityIcon::Search => Some(1),
ActivityIcon::SourceControl => Some(2),
ActivityIcon::RunDebug => Some(3),
ActivityIcon::Remote => Some(4),
ActivityIcon::Extensions => Some(5),
ActivityIcon::Testing => Some(6),
ActivityIcon::CodeQL => Some(7),
ActivityIcon::Sponsor | ActivityIcon::Settings => None,
}
}
pub(super) fn label(self) -> &'static str {
match self {
ActivityIcon::Explorer => "Explorer",
ActivityIcon::Search => "Search",
ActivityIcon::SourceControl => "Source Control",
ActivityIcon::Remote => "Remote",
ActivityIcon::RunDebug => "Run and Debug",
ActivityIcon::Extensions => "Extensions",
ActivityIcon::Testing => "Testing",
ActivityIcon::CodeQL => "CodeQL",
ActivityIcon::Sponsor => "Sponsor croft",
ActivityIcon::Settings => "Manage",
}
}
pub(super) fn picture(self) -> (&'static [u8], u32) {
use crate::iterm2_inline as ki;
match self {
ActivityIcon::Explorer => (ki::EXPLORER_SRC_SVG, ki::KITTY_ID_EXPLORER),
ActivityIcon::Search => (ki::SEARCH_SRC_SVG, ki::KITTY_ID_SEARCH),
ActivityIcon::SourceControl => {
(ki::SOURCE_CONTROL_SRC_SVG, ki::KITTY_ID_SOURCE_CONTROL)
}
ActivityIcon::Remote => (ki::REMOTE_SRC_SVG, ki::KITTY_ID_REMOTE),
ActivityIcon::RunDebug => (ki::RUN_DEBUG_SRC_SVG, ki::KITTY_ID_RUN_DEBUG_BAR),
ActivityIcon::Extensions => (ki::EXTENSIONS_SRC_SVG, ki::KITTY_ID_EXTENSIONS),
ActivityIcon::Testing => (ki::TESTING_SRC_SVG, ki::KITTY_ID_TESTING),
ActivityIcon::CodeQL => (ki::CODEQL_SRC_SVG, ki::KITTY_ID_CODEQL),
ActivityIcon::Sponsor => (ki::SPONSOR_HEART_SRC_SVG, ki::KITTY_ID_SPONSOR),
ActivityIcon::Settings => (ki::SETTINGS_GEAR_SRC_SVG, ki::KITTY_ID_SETTINGS),
}
}
pub(super) fn optional(self) -> bool {
matches!(
self,
ActivityIcon::CodeQL | ActivityIcon::Sponsor | ActivityIcon::Settings
)
}
pub(super) fn badge(self) -> Option<(u32, BadgeInk)> {
use crate::iterm2_inline as ki;
match self {
ActivityIcon::Explorer => Some((ki::KITTY_ID_EXPLORER_BADGE, BadgeInk::Accent)),
ActivityIcon::SourceControl => Some((ki::KITTY_ID_SCM_BADGE, BadgeInk::Accent)),
ActivityIcon::Remote => Some((ki::KITTY_ID_REMOTE_BADGE, BadgeInk::Accent)),
ActivityIcon::Testing => Some((ki::KITTY_ID_TESTING_BADGE, BadgeInk::Failure)),
ActivityIcon::Search
| ActivityIcon::RunDebug
| ActivityIcon::Extensions
| ActivityIcon::CodeQL
| ActivityIcon::Sponsor
| ActivityIcon::Settings => None,
}
}
pub(super) fn glyph(self) -> char {
match self {
ActivityIcon::Explorer => crate::icons::ACTIVITY_EXPLORER,
ActivityIcon::Search => crate::icons::ACTIVITY_SEARCH,
ActivityIcon::SourceControl => crate::icons::ACTIVITY_SOURCE_CONTROL,
ActivityIcon::Remote => crate::icons::ACTIVITY_REMOTE,
ActivityIcon::RunDebug => crate::icons::ACTIVITY_RUN_DEBUG,
ActivityIcon::Extensions => crate::icons::ACTIVITY_EXTENSIONS,
ActivityIcon::Testing => crate::icons::ACTIVITY_TESTING,
ActivityIcon::CodeQL => crate::icons::ACTIVITY_CODEQL,
ActivityIcon::Sponsor => crate::icons::ACTIVITY_SPONSOR,
ActivityIcon::Settings => crate::icons::ACTIVITY_SETTINGS,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(super) struct ActivityBlocks([Rect; ActivityIcon::ALL.len()]);
impl ActivityBlocks {
pub(super) fn all(&self) -> &[Rect] {
&self.0
}
}
impl std::ops::Index<ActivityIcon> for ActivityBlocks {
type Output = Rect;
fn index(&self, icon: ActivityIcon) -> &Rect {
&self.0[icon as usize]
}
}
impl std::ops::IndexMut<ActivityIcon> for ActivityBlocks {
fn index_mut(&mut self, icon: ActivityIcon) -> &mut Rect {
&mut self.0[icon as usize]
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum BadgeInk {
Accent,
Failure,
}
#[derive(Clone, Debug, Default)]
pub(super) struct CountBadge {
image: Option<String>,
count: usize,
}
impl CountBadge {
pub(super) fn invalidate(&mut self) {
self.count = usize::MAX;
}
#[cfg(test)]
pub(super) fn count(&self) -> usize {
self.count
}
pub(super) fn refresh(
&mut self,
count: usize,
pictures: bool,
build: impl FnOnce() -> Option<String>,
) -> bool {
if !pictures {
self.image = None;
}
if count == self.count {
return false;
}
self.count = count;
if pictures {
self.image = if count == 0 { None } else { build() };
}
true
}
pub(super) fn placed(&self, icon: Rect) -> Option<(Rect, &str)> {
let image = self.image.as_deref()?;
let width = crate::iterm2_inline::count_badge_cells_w(self.count);
let cells = Rect {
x: icon.x + icon.width.saturating_sub(width),
y: icon.y + icon.height.saturating_sub(1),
width,
height: 1,
};
Some((cells, image))
}
}
pub(super) const SPONSOR_URL: &str = "https://github.com/sponsors/vitali87";
pub(super) const ACTIVITY_BAR_WIDTH: u16 = 4;
pub(super) const ACTIVITY_ICON_HEIGHT: u16 = 2;
pub(super) const ACTIVITY_ICON_GAP: u16 = 0;
pub(super) const SECONDARY_SIDEBAR_WIDTH: u16 = 30;
pub(super) const LAYOUT_ICON_CELLS_W: u16 = 2;
pub(super) const LAYOUT_ICON_CELLS_H: u16 = 1;
pub(super) const LAYOUT_ICONS_W: u16 = (LAYOUT_ICON_CELLS_W + 1) * 3;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum SideBarPosition {
#[default]
Left,
Right,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum PanelAlignment {
Left,
#[default]
Center,
Right,
Justify,
}
impl PanelAlignment {
pub(super) const OPTIONS: [(PanelAlignment, &'static str, &'static str); 4] = [
(PanelAlignment::Left, "left", "Left"),
(PanelAlignment::Center, "center", "Center"),
(PanelAlignment::Right, "right", "Right"),
(PanelAlignment::Justify, "justify", "Justify"),
];
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum QuickInputPosition {
#[default]
Top,
Center,
}
impl QuickInputPosition {
pub(super) const OPTIONS: [(QuickInputPosition, &'static str, &'static str); 2] = [
(QuickInputPosition::Top, "top", "Top"),
(QuickInputPosition::Center, "center", "Center"),
];
}
pub(super) fn centered_editor_rect(area: Rect, width: u16) -> Rect {
if width == 0 || area.width <= width {
return area;
}
Rect {
x: area.x + (area.width - width) / 2,
width,
..area
}
}
pub(super) fn zen_hint_text() -> &'static str {
if cfg!(target_os = "macos") {
"Zen Mode: Cmd+K Z or Esc Esc to exit"
} else {
"Zen Mode: Ctrl+K Z or Esc Esc to exit"
}
}
pub(super) fn compute_chrome_layout(
main: Rect,
activity_visible: bool,
primary_visible: bool,
secondary_visible: bool,
side_bar_position: SideBarPosition,
sidebar_w: u16,
secondary_w: u16,
) -> ChromeLayout {
let activity_w = if activity_visible {
ACTIVITY_BAR_WIDTH
} else {
0
};
let fits = main.width
>= activity_w
.saturating_add(secondary_w)
.saturating_add(RIGHT_PANE_MIN);
let secondary_w = if secondary_visible && fits {
secondary_w
} else {
0
};
let reserved = activity_w.saturating_add(secondary_w);
let after_reserved = main.width.saturating_sub(reserved);
let max_primary = after_reserved.saturating_sub(RIGHT_PANE_MIN);
let primary_w = if primary_visible {
sidebar_w.min(max_primary)
} else {
0
};
let right_w = after_reserved.saturating_sub(primary_w);
let row = |x: u16, w: u16| Rect {
x,
y: main.y,
width: w,
height: main.height,
};
let mut x = main.x;
let (activity, primary_side, right, secondary_side, splitter);
match side_bar_position {
SideBarPosition::Left => {
activity = (activity_w > 0).then(|| row(x, activity_w));
x += activity_w;
primary_side = (primary_w > 0).then(|| row(x, primary_w));
x += primary_w;
let right_rect = row(x, right_w);
splitter = (primary_w > 0).then_some(right_rect.x);
right = right_rect;
x += right_w;
secondary_side = (secondary_w > 0).then(|| row(x, secondary_w));
}
SideBarPosition::Right => {
secondary_side = (secondary_w > 0).then(|| row(x, secondary_w));
x += secondary_w;
let right_rect = row(x, right_w);
right = right_rect;
x += right_w;
splitter = (primary_w > 0).then_some(x);
primary_side = (primary_w > 0).then(|| row(x, primary_w));
x += primary_w;
activity = (activity_w > 0).then(|| row(x, activity_w));
}
}
ChromeLayout {
activity,
primary_side,
secondary_side,
right,
sidebar_splitter_x: splitter,
}
}
pub(super) fn panel_band_rect(band: Rect, alignment: PanelAlignment) -> Rect {
match alignment {
PanelAlignment::Center | PanelAlignment::Justify => band,
PanelAlignment::Left => Rect {
width: (band.width / 2).max(RIGHT_PANE_MIN).min(band.width),
..band
},
PanelAlignment::Right => {
let w = (band.width / 2).max(RIGHT_PANE_MIN).min(band.width);
Rect {
x: band.x + band.width - w,
width: w,
..band
}
}
}
}
pub(super) fn activity_icon_glyph_x(bar: Rect) -> u16 {
bar.x + bar.width / 2
}
pub(super) fn activity_view_y(bar: Rect, slot: u16) -> u16 {
bar.y + 1 + slot * (ACTIVITY_ICON_HEIGHT + ACTIVITY_ICON_GAP)
}
pub(super) fn activity_view_block(bar: Rect, slot: u16) -> Rect {
Rect {
x: bar.x,
y: activity_view_y(bar, slot),
width: bar.width,
height: ACTIVITY_ICON_HEIGHT,
}
}
pub(super) const ACTIVITY_BOTTOM_INSET: u16 = 1;
pub(super) fn activity_settings_block(bar: Rect, codeql_shown: bool) -> Rect {
let y = bar
.y
.saturating_add(bar.height)
.saturating_sub(ACTIVITY_ICON_HEIGHT + ACTIVITY_BOTTOM_INSET);
if y < activity_last_view_bottom(bar, codeql_shown) {
return Rect::default();
}
Rect {
x: bar.x,
y,
width: bar.width,
height: ACTIVITY_ICON_HEIGHT,
}
}
pub(super) fn activity_last_view_bottom(bar: Rect, codeql_shown: bool) -> u16 {
let last = if codeql_shown {
ActivityIcon::CodeQL
} else {
ActivityIcon::Testing
};
let slot = last.slot().expect("CodeQL and Testing are view icons");
activity_view_y(bar, slot) + ACTIVITY_ICON_HEIGHT
}
pub(super) fn activity_sponsor_block(bar: Rect, codeql_shown: bool) -> Rect {
let gear = activity_settings_block(bar, codeql_shown);
let y = gear
.y
.saturating_sub(ACTIVITY_ICON_HEIGHT + ACTIVITY_ICON_GAP);
if gear.width == 0 || y < activity_last_view_bottom(bar, codeql_shown) {
return Rect::default();
}
Rect { y, ..gear }
}
pub(super) fn chip_tint(
t: crate::widgets::surface::Tones,
hue: (u8, u8, u8),
hovered: bool,
) -> (Color, Color) {
let strength = if hovered { 0.32 } else { 0.22 };
(
rgb_color(crate::gradient::lerp_rgb(t.chrome, hue, strength)),
rgb_color(crate::gradient::lerp_rgb(hue, t.lift, 0.35)),
)
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) enum SplitterDrag {
Sidebar,
Terminal,
EditorSeam(editor_layout::Seam),
}
pub(super) const EDITOR_SPLIT_MIN: u16 = 10;
pub(super) const SIDEBAR_WIDTH_DEFAULT: u16 = 32;
pub(super) const SIDEBAR_WIDTH_MIN: u16 = 12;
pub(super) const TERMINAL_HEIGHT_MIN: u16 = 3;
pub(super) const EDITOR_HEIGHT_MIN: u16 = 3;
pub(super) const OSK_MIN_FRAME_HEIGHT: u16 = 16;
pub(super) const RIGHT_PANE_MIN: u16 = 20;
pub(super) const ZEN_ESC_WINDOW: std::time::Duration = std::time::Duration::from_millis(500);
pub(super) const ZEN_HINT_FOR: std::time::Duration = std::time::Duration::from_secs(4);
impl App {
pub(super) fn refresh_activity_badges(&mut self) {
let pictures = self.overlays.activity.has_images();
let mut changed = false;
for icon in ActivityIcon::ALL {
let Some((kitty_id, ink)) = icon.badge() else {
continue;
};
let count = self.activity_badge_count(icon);
let color = match ink {
BadgeInk::Accent => self.theme.accent_rgb(),
BadgeInk::Failure => self.theme.git_deleted_rgb(),
};
let mut badge = std::mem::take(&mut self.activity_badges[icon as usize]);
changed |= badge.refresh(count, pictures, || {
self.build_count_badge_image(count, kitty_id, color)
});
self.activity_badges[icon as usize] = badge;
}
if changed {
self.overlays.activity.mark_dirty();
}
}
pub(super) fn scm_change_count(&self) -> usize {
std::iter::once(&self.git)
.chain(self.git_extra.iter().map(|(_, w)| w))
.map(|w| w.status().changed_count)
.sum()
}
pub(super) fn build_count_badge_image(
&self,
count: usize,
kitty_id: u32,
color: (u8, u8, u8),
) -> Option<String> {
let (cw, ch) = self.cell_pixel?;
let png = crate::iterm2_inline::compose_count_badge(
count,
cw,
ch,
color,
self.chrome_bg_pixel(),
)?;
let raw = crate::iterm2_inline::build_inline_image_z(
self.inline_protocol,
&png,
crate::iterm2_inline::count_badge_cells_w(count),
1,
false,
kitty_id,
1,
)?;
Some(self.wrap_for_terminal(raw))
}
pub fn refresh_problems_badge(&mut self) {
let count = self.problems.total_count();
if !self.overlays.activity.has_images() {
self.problems_badge_count = count;
return;
}
if count == self.problems_badge_count {
return;
}
self.problems_badge_count = count;
if count == 0 {
self.overlays.problems_badge.clear_image();
self.clear_problems_badge_if_emitted();
return;
}
if let Some(img) = self.build_count_badge_image(
count,
crate::iterm2_inline::KITTY_ID_PROBLEMS_BADGE,
crate::gradient::GRAD_TR,
) {
self.overlays.problems_badge.set_image(img);
}
}
pub(super) fn activity_icon_at(&self, col: u16, row: u16) -> Option<ActivityIcon> {
ActivityIcon::ALL
.into_iter()
.find(|&icon| rect_contains(self.sidebar_areas.activity_icons[icon], col, row))
}
pub(super) fn activity_icon_selected(&self, icon: ActivityIcon) -> bool {
match icon.view() {
Some(view) => self.activity_view_active(view),
None => icon == ActivityIcon::Settings && self.settings_menu_active(),
}
}
pub(super) fn activity_badge_count(&self, icon: ActivityIcon) -> usize {
match icon {
ActivityIcon::Explorer => self.unsaved_count(),
ActivityIcon::SourceControl => self.scm_change_count(),
ActivityIcon::Remote => self.ports.forwarded_count(),
ActivityIcon::Testing => self.testing.failed_count(),
_ => 0,
}
}
pub(super) fn settings_menu_origin(&self) -> (u16, u16) {
let gear = self.sidebar_areas.activity_icons[ActivityIcon::Settings];
(gear.x + gear.width, gear.y)
}
pub(super) fn open_settings_menu(&mut self) {
let origin = self.settings_menu_origin();
self.context_menu = Some(ContextMenu::flat(
origin,
vec![
(String::from("Color Theme"), MenuAction::OpenThemePicker),
(
String::from("Customize Layout"),
MenuAction::OpenCustomizeLayout,
),
],
self.workspace_root().to_path_buf(),
));
self.overlays.activity.mark_dirty();
}
pub(super) fn open_sponsor_page(&mut self) {
self.open_url_for_user(SPONSOR_URL);
}
pub(super) fn customize_layout_origin(&self) -> (u16, u16) {
let icon = self.layout_icon_areas.customize;
if icon.width > 0 {
(icon.x.saturating_sub(18), icon.y + 1)
} else {
self.settings_menu_origin()
}
}
pub(super) fn customize_layout_items(&self) -> Vec<MenuEntry> {
let check = |on: bool| if on { "\u{2713} " } else { " " };
vec![
MenuEntry::item(
format!("{}Activity Bar", check(self.activity_bar_visible)),
MenuAction::ToggleActivityBar,
),
MenuEntry::item(
format!("{}Primary Side Bar", check(self.show_tree)),
MenuAction::ToggleSideBar,
),
MenuEntry::item(
format!(
"{}Secondary Side Bar",
check(self.secondary_side_bar_visible)
),
MenuAction::ToggleSecondarySideBar,
),
MenuEntry::item(
format!("{}Panel", check(self.show_terminal)),
MenuAction::TogglePanel,
),
MenuEntry::item(
format!("{}Status Bar", check(self.status_bar_visible)),
MenuAction::ToggleStatusBar,
),
MenuEntry::item(
format!("{}Minimap", check(self.minimap_visible)),
MenuAction::ToggleMinimap,
),
MenuEntry::item(
format!("{}Auto-Hide Side Bar", check(self.sidebar_auto_hide)),
MenuAction::ToggleAutoHideSideBar,
),
MenuEntry::Separator,
MenuEntry::header("Primary Side Bar Position"),
MenuEntry::item(
format!(
"{}Left",
check(self.side_bar_position == SideBarPosition::Left)
),
MenuAction::SetSideBarPosition(SideBarPosition::Left),
),
MenuEntry::item(
format!(
"{}Right",
check(self.side_bar_position == SideBarPosition::Right)
),
MenuAction::SetSideBarPosition(SideBarPosition::Right),
),
MenuEntry::Separator,
MenuEntry::header("Panel Alignment"),
MenuEntry::item(
format!(
"{}Left",
check(self.panel_alignment == PanelAlignment::Left)
),
MenuAction::SetPanelAlignment(PanelAlignment::Left),
),
MenuEntry::item(
format!(
"{}Center",
check(self.panel_alignment == PanelAlignment::Center)
),
MenuAction::SetPanelAlignment(PanelAlignment::Center),
),
MenuEntry::item(
format!(
"{}Right",
check(self.panel_alignment == PanelAlignment::Right)
),
MenuAction::SetPanelAlignment(PanelAlignment::Right),
),
MenuEntry::item(
format!(
"{}Justify",
check(self.panel_alignment == PanelAlignment::Justify)
),
MenuAction::SetPanelAlignment(PanelAlignment::Justify),
),
MenuEntry::Separator,
MenuEntry::header("Quick Input Position"),
MenuEntry::item(
format!(
"{}Top",
check(self.quick_input_position == QuickInputPosition::Top)
),
MenuAction::SetQuickInputPosition(QuickInputPosition::Top),
),
MenuEntry::item(
format!(
"{}Center",
check(self.quick_input_position == QuickInputPosition::Center)
),
MenuAction::SetQuickInputPosition(QuickInputPosition::Center),
),
MenuEntry::Separator,
MenuEntry::item(
format!("{}Zen Mode", check(self.zen_mode)),
MenuAction::ToggleZenMode,
),
MenuEntry::item(
format!("{}Centered Layout", check(self.centered_layout_active())),
MenuAction::ToggleCenteredLayout,
),
]
}
pub(super) fn open_customize_layout_menu_on(&mut self, action: &MenuAction) {
let idx = self
.customize_layout_items()
.iter()
.position(|e| matches!(e, MenuEntry::Item { action: a, .. } if a == action))
.unwrap_or(0);
self.open_customize_layout_menu_at(idx);
}
pub(super) fn open_customize_layout_menu_at(&mut self, selected: usize) {
let origin = self.customize_layout_origin();
self.context_menu = Some(ContextMenu {
crumb: None,
scroll: Default::default(),
submenu_scroll: Default::default(),
origin,
items: self.customize_layout_items(),
selected,
open_submenu: None,
submenu_selected: 0,
target_dir: self.workspace_root().to_path_buf(),
});
self.overlays.activity.mark_dirty();
}
pub(super) fn open_customize_layout_menu(&mut self) {
self.open_customize_layout_menu_at(0);
}
pub(super) fn persist_layout(&mut self) {
if cfg!(test) {
return;
}
let saved = crate::prefs::save_layout(crate::prefs::LayoutPrefs {
activity_bar: self.activity_bar_visible,
status_bar: self.status_bar_visible,
minimap: self.minimap_visible,
side_bar_position: self.side_bar_position,
secondary_side_bar: self.secondary_side_bar_visible,
panel_alignment: self.panel_alignment,
quick_input_position: self.quick_input_position,
centered_layout: self.centered_layout,
zen_center_layout: self.zen_center_layout,
centered_layout_width: self.centered_layout_width,
});
self.report_unsaved_setting(saved);
}
pub(super) fn toggle_activity_bar(&mut self) {
self.activity_bar_visible = !self.activity_bar_visible;
self.sidebar_dwell.disarm();
if !self.activity_bar_visible {
self.sidebar_pinned_open = false;
}
self.persist_layout();
self.after_chrome_visibility_change();
}
pub(super) fn toggle_status_bar(&mut self) {
self.status_bar_visible = !self.status_bar_visible;
self.persist_layout();
self.after_chrome_visibility_change();
}
pub(super) fn set_side_bar_position(&mut self, pos: SideBarPosition) {
self.side_bar_position = pos;
self.persist_layout();
self.after_chrome_visibility_change();
}
pub(super) fn set_panel_alignment(&mut self, al: PanelAlignment) {
self.panel_alignment = al;
self.persist_layout();
}
pub(super) fn set_quick_input_position(&mut self, pos: QuickInputPosition) {
self.quick_input_position = pos;
self.persist_layout();
}
pub(super) fn open_panel_alignment_picker(&mut self) {
use crate::widgets::list_picker::{ListPicker, ListPurpose, ListRow};
let rows = PanelAlignment::OPTIONS
.iter()
.map(|(_, id, label)| ListRow {
id: (*id).to_string(),
label: (*label).to_string(),
})
.collect();
let mut picker = ListPicker::new(ListPurpose::PanelAlignment, "Panel Alignment", rows);
picker.selected = PanelAlignment::OPTIONS
.iter()
.position(|(al, ..)| *al == self.panel_alignment)
.unwrap_or(0);
self.open_list_picker(picker, "No panel alignments");
}
pub(super) fn open_quick_input_position_picker(&mut self) {
use crate::widgets::list_picker::{ListPicker, ListPurpose, ListRow};
let rows = QuickInputPosition::OPTIONS
.iter()
.map(|(_, id, label)| ListRow {
id: (*id).to_string(),
label: (*label).to_string(),
})
.collect();
let mut picker = ListPicker::new(
ListPurpose::QuickInputPosition,
"Quick Input Position",
rows,
);
picker.selected = QuickInputPosition::OPTIONS
.iter()
.position(|(pos, ..)| *pos == self.quick_input_position)
.unwrap_or(0);
self.open_list_picker(picker, "No quick input positions");
}
pub(super) fn after_chrome_visibility_change(&mut self) {
self.overlays.activity.mark_dirty();
if self.overlays.activity.has_images() {
self.overlays.activity.request_clear();
}
self.overlays.welcome.mark_dirty();
}
pub(super) fn toggle_side_bar(&mut self) {
let was_visible = self.show_tree;
self.show_tree = !self.show_tree;
self.sidebar_pinned_open =
self.show_tree && self.sidebar_auto_hide && self.activity_bar_visible && !self.zen_mode;
self.sidebar_dwell.disarm();
if was_visible
&& !self.show_tree
&& self.sidebar_view == SidebarView::RunDebug
&& self.overlays.run_debug.was_emitted()
{
self.overlays.run_debug.request_clear();
}
}
pub(super) fn toggle_secondary_side_bar(&mut self) {
self.secondary_side_bar_visible = !self.secondary_side_bar_visible;
self.after_chrome_visibility_change();
self.status = String::from(if self.secondary_side_bar_visible {
"Secondary side bar shown"
} else {
"Secondary side bar hidden"
});
self.persist_layout();
}
pub(super) fn toggle_zen_mode(&mut self) {
if let Some(prev) = self.pre_zen.take() {
self.activity_bar_visible = prev.activity_bar;
self.status_bar_visible = prev.status_bar;
self.show_tree = prev.side_bar;
self.secondary_side_bar_visible = prev.secondary_side_bar;
self.show_terminal = prev.panel;
self.zen_mode = false;
self.zen_esc_at = None;
self.zen_hint_until = None;
self.status = String::from("Zen Mode off");
} else {
self.pre_zen = Some(PreZenLayout {
activity_bar: self.activity_bar_visible,
status_bar: self.status_bar_visible,
side_bar: self.show_tree,
secondary_side_bar: self.secondary_side_bar_visible,
panel: self.show_terminal,
});
self.activity_bar_visible = false;
self.status_bar_visible = false;
self.show_tree = false;
self.sidebar_dwell.disarm();
self.sidebar_pinned_open = false;
self.secondary_side_bar_visible = false;
self.show_terminal = false;
self.zen_mode = true;
self.zen_centered = self.zen_center_layout;
self.zen_esc_at = None;
self.zen_hint_until = Some(std::time::Instant::now() + ZEN_HINT_FOR);
self.status = String::from("Zen Mode on");
}
self.after_chrome_visibility_change();
}
pub(super) fn centered_layout_active(&self) -> bool {
self.centered_layout || (self.zen_mode && self.zen_centered)
}
pub(super) fn toggle_centered_layout(&mut self) {
if self.centered_layout_active() {
self.centered_layout = false;
self.zen_centered = false;
} else {
self.centered_layout = true;
}
self.status = String::from(if self.centered_layout_active() {
"Centered Layout on"
} else {
"Centered Layout off"
});
self.persist_layout();
}
pub(super) fn note_idle_zen_esc(&mut self, now: std::time::Instant) {
match self.zen_esc_at.take() {
Some(at) if now.saturating_duration_since(at) <= ZEN_ESC_WINDOW => {
self.toggle_zen_mode();
}
_ => self.zen_esc_at = Some(now),
}
}
pub(super) fn esc_fingerprint(&self) -> impl PartialEq + use<> {
(
(
self.focus,
self.zen_mode,
self.open_popups(),
self.context_menu.is_some(),
self.peek_popup.is_some(),
self.hover_popup.is_some(),
self.completion_popup.is_some(),
self.signature_help_popup.is_some(),
),
(
self.editor.selection,
self.editor.has_multi_cursor(),
self.editor.snippet_active(),
self.editor
.markdown_preview
.as_ref()
.map(|md| md.has_selection()),
self.status.clone(),
),
(
self.editor.comment_focus.is_some(),
self.vim.enabled,
self.vim.mode(),
self.vim.has_pending(),
),
)
}
pub(super) fn expire_zen_hint(&mut self, now: std::time::Instant) -> bool {
if self.zen_hint_until.is_some_and(|until| now >= until) {
self.zen_hint_until = None;
return true;
}
false
}
pub(super) fn toggle_screencast_mode(&mut self) {
self.status = String::from(if self.screencast.toggle() {
"Screencast Mode on: the keys you press show at the bottom (Shift+F8 to stop)"
} else {
"Screencast Mode off"
});
}
pub(super) fn screencast_hides_typing(&self) -> bool {
self.input_prompt.as_ref().is_some_and(|p| p.masked)
|| self
.connect_dialog
.as_ref()
.is_some_and(|d| d.input_is_secret())
|| (self.focus == Pane::Terminal && !self.popup_open())
}
pub(super) fn render_screencast(&self, frame: &mut ratatui::Frame, main_area: Rect) {
if !self.screencast.is_on() {
return;
}
let mut area = main_area;
if self.zen_mode
&& self
.zen_hint_until
.is_some_and(|until| std::time::Instant::now() < until)
{
area.height = area.height.saturating_sub(4);
}
let caret = match self.focus {
Pane::Editor if self.editor.diff.is_some() => self.editor.diff_caret_screen_pos(),
Pane::Editor => self.editor.cursor_screen_pos(),
Pane::Terminal if self.show_terminal => self
.terminals
.get(self.active_terminal)
.and_then(|t| t.screen_cursor()),
_ => None,
};
self.screencast
.render(frame.buffer_mut(), area, self.theme, caret);
}
pub(super) fn paint_layout_icons(&mut self, frame: &mut ratatui::Frame, row: Rect) {
self.layout_icon_areas = LayoutIconAreas::default();
let w = LAYOUT_ICON_CELLS_W;
let stride = w + 1; let needed = LAYOUT_ICONS_W;
if row.height == 0 || row.width < needed {
return;
}
let y = row.y;
let right = row.x + row.width;
let cust_x = right.saturating_sub(w + 1); let panel_x = cust_x.saturating_sub(stride);
let side_x = panel_x.saturating_sub(stride);
if side_x < row.x {
return;
}
let rect = |x: u16| Rect {
x,
y,
width: w,
height: LAYOUT_ICON_CELLS_H,
};
self.layout_icon_areas = LayoutIconAreas {
toggle_side_bar: rect(side_x),
toggle_panel: rect(panel_x),
customize: rect(cust_x),
};
if self.overlays.activity.has_images() {
return;
}
let pointer = self.pointer_cell;
let base = self.theme.ui(Color::Rgb(0xcc, 0xcc, 0xcc));
let accent = self.theme.ui(Color::Rgb(0x4e, 0x9a, 0xff));
let surfaces = self.theme.surfaces().is_some();
let theme = self.theme;
let mut paint = |x: u16, glyph: char| {
let hovered = pointer.is_some_and(|(px, py)| py == y && px >= x && px < x + w);
let style = if surfaces {
crate::widgets::header_pill::action_style(theme, hovered)
} else {
Style::default().fg(if hovered { accent } else { base })
};
let buf = frame.buffer_mut();
if surfaces && hovered {
let chip = Rect::new(x, y, w, 1).intersection(buf.area);
buf.set_style(chip, style);
}
buf.set_string(x + w / 2, y, glyph.to_string(), style);
};
let side_glyph = if self.show_tree {
crate::icons::LAYOUT_SIDEBAR_ON
} else {
crate::icons::LAYOUT_SIDEBAR_OFF
};
let panel_glyph = if self.show_terminal {
crate::icons::LAYOUT_PANEL_ON
} else {
crate::icons::LAYOUT_PANEL_OFF
};
paint(side_x, side_glyph);
paint(panel_x, panel_glyph);
paint(cust_x, crate::icons::LAYOUT_CUSTOMIZE);
}
pub(super) fn render_activity_bar(&mut self, frame: &mut ratatui::Frame, area: Rect) {
if area.width == 0 || area.height == 0 {
return;
}
self.refresh_activity_badges();
self.refresh_problems_badge();
self.overlays.activity.note_side_bar_shown(self.show_tree);
let bar_bg = self
.theme
.surfaces()
.map_or(self.theme.editor_bg(), |s| s.chrome());
let bg = if self.overlays.activity.has_images() {
Style::default().bg(Color::Reset)
} else {
Style::default().bg(bar_bg)
};
if !self.overlays.activity.has_images() {
frame.render_widget(ratatui::widgets::Block::default().style(bg), area);
}
let active_bar = self.theme.activity_icon_pill();
let bg_color = bg.bg.unwrap_or(Color::Reset);
let mut blocks = ActivityBlocks::default();
for icon in ActivityIcon::ALL {
if let Some(slot) = icon.slot() {
blocks[icon] = activity_view_block(area, slot);
}
}
if !self.is_extension_enabled("codeql") {
blocks[ActivityIcon::CodeQL] = Rect::default();
}
let codeql_shown = blocks[ActivityIcon::CodeQL].width > 0;
blocks[ActivityIcon::Settings] = activity_settings_block(area, codeql_shown);
blocks[ActivityIcon::Sponsor] = activity_sponsor_block(area, codeql_shown);
if self.overlays.activity.has_images()
&& let Some(s) = self.theme.surfaces()
{
for y in area.top()..area.bottom() {
if !blocks.all().iter().any(|b| y >= b.top() && y < b.bottom()) {
frame.render_widget(
ratatui::widgets::Block::default().style(Style::default().bg(s.chrome())),
Rect {
x: area.x,
y,
width: area.width,
height: 1,
},
);
}
}
}
let hov = self.hovered_activity_icon;
let active_color = self.theme.activity_icon_active();
let hover_color = self.theme.activity_icon_hover();
let inactive_color = self.theme.activity_icon_inactive();
let tones = crate::widgets::surface::tones(self.theme);
let glyph_mods = if tones.is_some() {
Modifier::empty()
} else {
Modifier::BOLD
};
let glyph_x = activity_icon_glyph_x(area);
let render_glyph = |frame: &mut ratatui::Frame,
block: Rect,
glyph: char,
is_active: bool,
is_hovered: bool| {
let mid = block.y + block.height.saturating_sub(1) / 2;
if is_active {
let pill = Rect {
x: block.x,
y: mid,
width: 1,
height: 1,
};
frame.render_widget(
ratatui::widgets::Paragraph::new("▎")
.style(Style::default().fg(active_bar).bg(bg_color)),
pill,
);
}
let cell = Rect {
x: glyph_x,
y: mid,
width: 1,
height: 1,
};
let color = if is_active {
active_color
} else if is_hovered {
hover_color
} else {
inactive_color
};
frame.render_widget(
ratatui::widgets::Paragraph::new(glyph.to_string()).style(
Style::default()
.fg(color)
.bg(bg_color)
.add_modifier(glyph_mods),
),
cell,
);
};
let badge_style = match tones {
Some(t) => {
let (fill, ink) = chip_tint(t, t.accent, false);
Style::default().fg(ink).bg(fill)
}
None => Style::default()
.fg(Color::White)
.bg(self.theme.accent())
.add_modifier(Modifier::BOLD),
};
let render_count_badge = |frame: &mut ratatui::Frame, block: Rect, count: usize| {
if count == 0 {
return;
}
let label = if count > 9 {
String::from("9+")
} else {
count.to_string()
};
let w = label.chars().count() as u16;
frame.render_widget(
ratatui::widgets::Paragraph::new(label).style(badge_style),
Rect {
x: block.x + block.width.saturating_sub(w),
y: block.y + block.height.saturating_sub(1),
width: w,
height: 1,
},
);
};
if !self.overlays.activity.has_images() {
for icon in ActivityIcon::ALL {
let block = blocks[icon];
if block.width == 0 {
continue;
}
if icon == ActivityIcon::Sponsor {
let color = if hov == Some(icon) {
self.theme.activity_sponsor_hover()
} else {
self.theme.activity_sponsor()
};
frame.render_widget(
ratatui::widgets::Paragraph::new(icon.glyph().to_string()).style(
Style::default()
.fg(color)
.bg(bg_color)
.add_modifier(glyph_mods),
),
Rect {
x: glyph_x,
y: block.y + block.height.saturating_sub(1) / 2,
width: 1,
height: 1,
},
);
continue;
}
render_glyph(
frame,
block,
icon.glyph(),
self.activity_icon_selected(icon),
hov == Some(icon),
);
render_count_badge(frame, block, self.activity_badge_count(icon));
}
}
self.sidebar_areas.activity_icons = blocks;
}
pub(super) fn set_sidebar_view(&mut self, view: SidebarView) {
if self.sidebar_view != view {
self.overlays.activity.mark_dirty();
if self.sidebar_view == SidebarView::Search && view != SidebarView::Search {
self.cancel_search_run();
}
if self.sidebar_view == SidebarView::RunDebug
&& view != SidebarView::RunDebug
&& self.overlays.run_debug.was_emitted()
{
self.overlays.run_debug.request_clear();
}
if self.sidebar_view == SidebarView::SourceControl && view != SidebarView::SourceControl
{
self.overlays.hero.request_clear_if_displayed();
}
self.commit_menu_open = false;
}
self.sidebar_view = view;
if self.sidebar_view == SidebarView::Remote && self.remote.refresh_if_config_changed() {
self.status = String::from("Reloaded SSH remotes");
}
if !self.show_tree {
self.show_tree = true; }
match view {
SidebarView::Explorer => self.focus_pane(Pane::Tree),
SidebarView::Search => {
self.focus_pane(Pane::Tree); self.search.select_all_query();
self.resume_cancelled_search();
}
SidebarView::SourceControl => {
self.refresh_source_control();
self.source_control.list_focused = false;
self.focus_pane(Pane::Tree);
}
SidebarView::Remote => self.focus_pane(Pane::Tree),
SidebarView::RunDebug => {
self.refresh_run_debug();
self.focus_pane(Pane::Tree);
}
SidebarView::Extensions => {
self.refresh_extensions();
self.focus_pane(Pane::Tree);
}
SidebarView::Testing => self.focus_pane(Pane::Tree),
SidebarView::CodeQL => {
self.codeql.theme = self.theme;
self.focus_pane(Pane::Tree);
}
}
}
pub(super) fn click_activity_view(&mut self, view: SidebarView) {
if self.activity_view_active(view) {
self.toggle_side_bar();
self.after_chrome_visibility_change();
if self.focus == Pane::Tree {
self.focus_pane(if self.terminal_maximized {
Pane::Terminal
} else {
Pane::Editor
});
}
return;
}
match view {
SidebarView::Testing => self.open_testing_view(),
SidebarView::CodeQL => self.open_codeql_view(),
_ => self.set_sidebar_view(view),
}
}
pub(super) fn activity_view_active(&self, view: SidebarView) -> bool {
self.show_tree && self.sidebar_view == view
}
pub(super) fn without_auto_hide<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R {
let prev = std::mem::replace(&mut self.sidebar_auto_hide_suspended, true);
let out = f(self);
self.sidebar_auto_hide_suspended = prev;
out
}
pub(super) fn sidebar_structurally_suppressed(&self) -> bool {
!self.activity_bar_visible || self.zen_mode
}
pub(super) fn sidebar_auto_hide_allowed(&self) -> bool {
if !self.sidebar_auto_hide || !self.show_tree {
return false;
}
if self.sidebar_auto_hide_suspended {
return false;
}
if self.splitter_drag.is_some() {
return false;
}
if self.popup_open() || self.context_menu.is_some() {
return false;
}
if self.tree_drag.is_some() {
return false;
}
if !self.activity_bar_visible {
return false;
}
if self.zen_mode {
return false;
}
true
}
pub(super) fn toggle_sidebar_auto_hide(&mut self) {
self.sidebar_auto_hide = !self.sidebar_auto_hide;
self.sidebar_dwell.disarm();
self.sidebar_pinned_open = false;
self.status = format!(
"Auto-hide side bar {}",
if self.sidebar_auto_hide { "on" } else { "off" }
);
if !cfg!(test) {
self.report_unsaved_setting(crate::prefs::save_sidebar_auto_hide(
self.sidebar_auto_hide,
));
}
}
pub(super) fn maybe_auto_hide_sidebar(&mut self) {
if self.sidebar_auto_hide && self.show_tree && !self.sidebar_auto_hide_suspended {
self.sidebar_dwell.arm(std::time::Instant::now());
}
}
pub fn tick_sidebar_auto_hide(&mut self) -> bool {
self.tick_sidebar_auto_hide_at(std::time::Instant::now())
}
pub(crate) fn tick_sidebar_auto_hide_at(&mut self, now: std::time::Instant) -> bool {
if !self.sidebar_dwell.armed() {
return false;
}
if self.focus == Pane::Tree || !self.show_tree {
self.sidebar_dwell.disarm();
return false;
}
if !self.sidebar_dwell.due(now, AUTO_HIDE_DWELL) {
return false;
}
if self.sidebar_structurally_suppressed() {
self.sidebar_dwell.restamp(now);
return false;
}
if !self.sidebar_auto_hide_allowed() {
return false;
}
self.sidebar_dwell.disarm();
let exempt = std::mem::take(&mut self.sidebar_pinned_open);
if !exempt {
self.show_tree = false;
return true;
}
false
}
pub(super) fn render_zen_hint(&self, frame: &mut ratatui::Frame) {
if !self.zen_mode
|| !self
.zen_hint_until
.is_some_and(|until| std::time::Instant::now() < until)
{
return;
}
let text = zen_hint_text();
let area = frame.area();
let width = text.chars().count() as u16 + 4;
let height: u16 = 3;
if area.width < width || area.height < height + 1 {
return;
}
let rect = Rect {
x: area.x + (area.width - width) / 2,
y: area.y + area.height - height - 1,
width,
height,
};
let accent = self.theme.accent();
let tones = crate::widgets::surface::tones(self.theme);
let (bg, fg) = match tones {
Some(t) => (t.raised(), t.text()),
None => (self.theme.editor_bg(), accent),
};
let block = ratatui::widgets::Block::default()
.borders(ratatui::widgets::Borders::ALL)
.border_type(ratatui::widgets::BorderType::Rounded)
.border_style(Style::default().fg(accent))
.style(Style::default().bg(bg));
frame.render_widget(ratatui::widgets::Clear, rect);
frame.render_widget(
ratatui::widgets::Paragraph::new(ratatui::text::Span::styled(
text,
Style::default().fg(fg),
))
.alignment(ratatui::layout::Alignment::Center)
.block(block),
rect,
);
if tones.is_some() {
crate::widgets::surface::paint_overlay_frame(frame.buffer_mut(), rect, self.theme);
}
}
pub(super) fn handle_splitter_drag(&mut self, kind: SplitterDrag, column: u16, row: u16) {
match kind {
SplitterDrag::Sidebar => {
let activity_w = if self.activity_bar_visible {
ACTIVITY_BAR_WIDTH
} else {
0
};
let secondary_w = if self.secondary_side_bar_visible {
SECONDARY_SIDEBAR_WIDTH
} else {
0
};
let frame_x = self.last_frame_area.x;
let total = activity_w + secondary_w + self.sidebar_width + self.last_content_width;
let new_w = match self.side_bar_position {
SideBarPosition::Left => {
column.saturating_sub(frame_x).saturating_sub(activity_w)
}
SideBarPosition::Right => (frame_x + total)
.saturating_sub(activity_w)
.saturating_sub(column),
};
let max_sidebar = total
.saturating_sub(activity_w)
.saturating_sub(secondary_w)
.saturating_sub(RIGHT_PANE_MIN);
self.sidebar_width =
new_w.clamp(SIDEBAR_WIDTH_MIN, max_sidebar.max(SIDEBAR_WIDTH_MIN));
}
SplitterDrag::Terminal => {
let Some(splitter_y) = self.terminal_splitter_y else {
return;
};
let bottom = splitter_y + self.terminal_height.unwrap_or(0);
let actual_bottom = if bottom == splitter_y {
splitter_y.saturating_add(self.last_content_height)
} else {
bottom
};
let new_h = actual_bottom.saturating_sub(row);
let max_h = self
.last_content_height
.saturating_sub(EDITOR_HEIGHT_MIN)
.max(TERMINAL_HEIGHT_MIN);
self.terminal_height = Some(new_h.clamp(TERMINAL_HEIGHT_MIN, max_h));
}
SplitterDrag::EditorSeam(seam) => {
if !self.editor_layout.is_split() {
return;
}
let pointer = match seam.dir {
editor_layout::SplitDir::Horizontal => column,
editor_layout::SplitDir::Vertical => row,
};
self.editor_layout
.drag_seam(&seam, pointer, EDITOR_SPLIT_MIN);
}
}
}
}
pub(super) fn cursor_suffix(cursor: Option<(u16, u16)>) -> String {
match cursor {
Some((row, col)) => format!("\u{1b}[{};{}H\u{1b}[?25h", row + 1, col + 1),
None => String::from("\u{1b}[?25l"),
}
}