#![allow(dead_code)]
use ratatui::{
buffer::Buffer,
layout::Rect,
style::{Color, Style},
widgets::Widget,
};
const ACTIVE_FG: Color = Color::White;
const ACTIVE_BG: Color = Color::Rgb(70, 70, 140);
const GRAY_LEFT_FG: Color = Color::Rgb(190, 190, 190);
const GRAY_LEFT_BG: Color = Color::Rgb(52, 52, 52);
const GRAY_RIGHT_FG: Color = Color::Rgb(140, 140, 140);
const GRAY_RIGHT_BG: Color = Color::Rgb(36, 36, 36);
const SEP_FG: Color = Color::Rgb(80, 80, 80);
const FILL_BG: Color = Color::Rgb(28, 28, 28);
pub struct TerminalTabBar<'a> {
pub tabs: &'a [(String, u64)],
pub active: usize,
}
impl<'a> Widget for TerminalTabBar<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
if area.height == 0 {
return;
}
let y = area.top();
let mut x = area.left();
let right = area.right();
for col in area.left()..right {
if let Some(cell) = buf.cell_mut((col, y)) {
cell.set_char(' ');
cell.set_style(Style::default().bg(FILL_BG));
}
}
for (i, (title, _id)) in self.tabs.iter().enumerate() {
let is_active = i == self.active;
let (fg, bg) = if is_active {
(ACTIVE_FG, ACTIVE_BG)
} else if i < self.active {
(GRAY_LEFT_FG, GRAY_LEFT_BG)
} else {
(GRAY_RIGHT_FG, GRAY_RIGHT_BG)
};
let label = format!(" {} ", title);
for ch in label.chars() {
if x >= right {
return;
}
if let Some(cell) = buf.cell_mut((x, y)) {
cell.set_char(ch);
cell.set_style(Style::default().fg(fg).bg(bg));
}
x += 1;
}
if !is_active && i + 1 < self.tabs.len() && x < right {
if let Some(cell) = buf.cell_mut((x, y)) {
cell.set_char('▏');
cell.set_style(Style::default().fg(SEP_FG).bg(
if i + 1 == self.active {
GRAY_LEFT_BG
} else {
GRAY_RIGHT_BG
},
));
}
x += 1;
}
}
}
}