terminal is fixed and im not happy about it

This commit is contained in:
Zacharias-Brohn
2026-04-10 00:29:13 +02:00
parent 5129612f9f
commit 32ce278743
4 changed files with 188 additions and 69 deletions
+59 -28
View File
@@ -2406,14 +2406,19 @@ impl Renderer {
/// Parse ANSI escape sequences from raw statusline content.
/// Returns a vector of (char, fg_color, bg_color, bold) tuples.
fn parse_ansi_statusline(content: &str) -> Vec<(char, StatuslineColor, StatuslineColor, bool)> {
fn parse_ansi_statusline(content: &str, is_light: bool) -> Vec<(char, StatuslineColor, StatuslineColor, bool)> {
let mut result = Vec::new();
let chars: Vec<char> = content.chars().collect();
let mut i = 0;
// Current styling state
let mut fg = StatuslineColor::Default;
let mut bg = StatuslineColor::Rgb(0x1a, 0x1a, 0x1a); // Default statusline background
let default_bg_color = if is_light {
StatuslineColor::Rgb(0xD0, 0xD0, 0xD0)
} else {
StatuslineColor::Rgb(0x1a, 0x1a, 0x1a)
};
let mut bg = default_bg_color.clone(); // Default statusline background
let mut bold = false;
while i < chars.len() {
@@ -2494,7 +2499,7 @@ impl Renderer {
}
}
}
49 => bg = StatuslineColor::Rgb(0x1a, 0x1a, 0x1a), // Reset to default statusline bg
49 => bg = default_bg_color.clone(), // Reset to default statusline bg
90..=97 => fg = StatuslineColor::Indexed((code - 90 + 8) as u8),
100..=107 => bg = StatuslineColor::Indexed((code - 100 + 8) as u8),
_ => {}
@@ -2528,7 +2533,7 @@ impl Renderer {
/// this is used to expand the middle gap to fill the full window width.
///
/// Returns the number of columns used.
fn update_statusline_cells(&mut self, content: &StatuslineContent, target_width: f32) -> usize {
fn update_statusline_cells(&mut self, content: &StatuslineContent, target_width: f32, is_light: bool) -> usize {
self.statusline_gpu_cells.clear();
// Calculate target columns based on window width
@@ -2540,14 +2545,19 @@ impl Renderer {
self.statusline_max_cols
};
// Default background color for statusline (dark gray)
let default_bg = Self::pack_statusline_color(StatuslineColor::Rgb(0x1a, 0x1a, 0x1a));
// Default background color for statusline
let default_bg_color = if is_light {
StatuslineColor::Rgb(0xD0, 0xD0, 0xD0)
} else {
StatuslineColor::Rgb(0x1a, 0x1a, 0x1a)
};
let default_bg = Self::pack_statusline_color(default_bg_color);
let _ = default_bg; // Silence unused warning - used by Sections path
match content {
StatuslineContent::Raw(ansi_content) => {
// Parse ANSI escape sequences to extract colors and text
let parsed = Self::parse_ansi_statusline(ansi_content);
let parsed = Self::parse_ansi_statusline(ansi_content, is_light);
// Find the middle gap (largest consecutive run of spaces)
// and expand it to fill the target width
@@ -2597,7 +2607,7 @@ impl Renderer {
let gap_bg = if best_gap_len > 0 && best_gap_start < parsed.len() {
parsed[best_gap_start].2
} else {
StatuslineColor::Rgb(0x1a, 0x1a, 0x1a)
default_bg_color.clone()
};
// The position right before right-hand content starts (end of gap)
@@ -2845,7 +2855,7 @@ impl Renderer {
// Fill remaining width with default background cells
// This ensures the statusline covers the entire window width
let default_bg_packed = Self::pack_statusline_color(StatuslineColor::Default);
let default_bg_packed = default_bg;
while self.statusline_gpu_cells.len() < target_cols && self.statusline_gpu_cells.len() < self.statusline_max_cols {
self.statusline_gpu_cells.push(GPUCell {
fg: 0,
@@ -4331,10 +4341,17 @@ impl Renderer {
TabBarPosition::Hidden => unreachable!(),
};
// Use same color as statusline: 0x1a1a1a (26, 26, 26) in sRGB
// Pre-computed linear RGB value for srgb_to_linear(26/255) ≈ 0.00972
const TAB_BAR_BG_LINEAR: f32 = 0.00972;
let tab_bar_bg = [TAB_BAR_BG_LINEAR, TAB_BAR_BG_LINEAR, TAB_BAR_BG_LINEAR, 1.0];
let is_light = self.palette.is_light();
let tab_bar_bg = if is_light {
// Light mode statusline bg is approx 0xD0, linear is ~0.63076
const TAB_BAR_BG_LINEAR_LIGHT: f32 = 0.63076;
[TAB_BAR_BG_LINEAR_LIGHT, TAB_BAR_BG_LINEAR_LIGHT, TAB_BAR_BG_LINEAR_LIGHT, 1.0]
} else {
// Use same color as statusline: 0x1a1a1a (26, 26, 26) in sRGB
// Pre-computed linear RGB value for srgb_to_linear(26/255) ≈ 0.00972
const TAB_BAR_BG_LINEAR_DARK: f32 = 0.00972;
[TAB_BAR_BG_LINEAR_DARK, TAB_BAR_BG_LINEAR_DARK, TAB_BAR_BG_LINEAR_DARK, 1.0]
};
// Draw tab bar background
log::debug!("render_panes: drawing tab bar at y={}, height={}, num_tabs={}, quads_before={}",
@@ -4354,23 +4371,23 @@ impl Renderer {
let tab_width = title_width.max(min_tab_width);
let tab_bg = if is_active {
// Active tab: brightest - significantly brighter than tab bar
// Active tab: brightest - matches terminal background or slightly brighter
let [r, g, b] = self.palette.default_bg;
let boost = 50.0_f32; // More visible for active tab
let boost = if is_light { 0.0_f32 } else { 50.0_f32 };
[
Self::srgb_to_linear((r as f32 + boost).min(255.0) / 255.0),
Self::srgb_to_linear((g as f32 + boost).min(255.0) / 255.0),
Self::srgb_to_linear((b as f32 + boost).min(255.0) / 255.0),
Self::srgb_to_linear((r as f32 + boost).clamp(0.0, 255.0) / 255.0),
Self::srgb_to_linear((g as f32 + boost).clamp(0.0, 255.0) / 255.0),
Self::srgb_to_linear((b as f32 + boost).clamp(0.0, 255.0) / 255.0),
1.0,
]
} else {
// Inactive tab: slightly brighter than tab bar background
// Inactive tab: between tab bar background and active tab
let [r, g, b] = self.palette.default_bg;
let boost = 30.0_f32;
let boost = if is_light { -30.0_f32 } else { 30.0_f32 };
[
Self::srgb_to_linear((r as f32 + boost).min(255.0) / 255.0),
Self::srgb_to_linear((g as f32 + boost).min(255.0) / 255.0),
Self::srgb_to_linear((b as f32 + boost).min(255.0) / 255.0),
Self::srgb_to_linear((r as f32 + boost).clamp(0.0, 255.0) / 255.0),
Self::srgb_to_linear((g as f32 + boost).clamp(0.0, 255.0) / 255.0),
Self::srgb_to_linear((b as f32 + boost).clamp(0.0, 255.0) / 255.0),
1.0,
]
};
@@ -4651,7 +4668,11 @@ impl Renderer {
CursorShape::BlinkingUnderline | CursorShape::SteadyUnderline => 1,
CursorShape::BlinkingBar | CursorShape::SteadyBar => 2,
},
background_opacity: self.background_opacity,
background_opacity: if terminal.using_alternate_screen {
1.0
} else {
self.background_opacity
},
selection_start_col: sel_start_col,
selection_start_row: sel_start_row,
selection_end_col: sel_end_col,
@@ -4767,9 +4788,10 @@ impl Renderer {
// ═══════════════════════════════════════════════════════════════════
let statusline_cols = {
let statusline_y = self.statusline_y();
let is_light = self.palette.is_light();
// Update statusline GPU cells from content, passing window width for gap expansion
let cols = self.update_statusline_cells(statusline_content, width);
let cols = self.update_statusline_cells(statusline_content, width, is_light);
if cols > 0 {
// Upload statusline cells to GPU
@@ -5009,10 +5031,19 @@ impl Renderer {
{
let [bg_r, bg_g, bg_b] = self.palette.default_bg;
let bg_r_linear = Self::srgb_to_linear(bg_r as f32 / 255.0) as f64;
let bg_g_linear = Self::srgb_to_linear(bg_g as f32 / 255.0) as f64;
let bg_b_linear = Self::srgb_to_linear(bg_b as f32 / 255.0) as f64;
let mut bg_r_linear = Self::srgb_to_linear(bg_r as f32 / 255.0) as f64;
let mut bg_g_linear = Self::srgb_to_linear(bg_g as f32 / 255.0) as f64;
let mut bg_b_linear = Self::srgb_to_linear(bg_b as f32 / 255.0) as f64;
let bg_alpha = self.background_opacity as f64;
// If the compositor expects premultiplied alpha, we must premultiply the clear color.
// Otherwise, light backgrounds with opacity will look fully opaque or super-luminous.
if self.surface_config.alpha_mode == wgpu::CompositeAlphaMode::PreMultiplied {
bg_r_linear *= bg_alpha;
bg_g_linear *= bg_alpha;
bg_b_linear *= bg_alpha;
}
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {