style: add density fades to tabs and status
This commit is contained in:
+50
-29
@@ -1041,7 +1041,8 @@ fn draw_tab_bar(frame: &mut Frame, editor: &Editor, area: Rect) -> Rect {
|
||||
let active = editor.tab_index();
|
||||
let mut first = active;
|
||||
let padding = u16::from(bar.width > 1);
|
||||
let mut width = labels[active].width() + usize::from(padding);
|
||||
let fade = usize::from(bar.width) >= labels[active].width() + usize::from(padding) + 6;
|
||||
let mut width = labels[active].width() + usize::from(padding) + if fade { 6 } else { 0 };
|
||||
while first > 0 && width + labels[first - 1].width() <= usize::from(bar.width) {
|
||||
first -= 1;
|
||||
width += labels[first].width();
|
||||
@@ -1049,18 +1050,27 @@ fn draw_tab_bar(frame: &mut Frame, editor: &Editor, area: Rect) -> Rect {
|
||||
let inactive = Style::default().fg(Color::Gray);
|
||||
let mut x = bar.x + padding;
|
||||
for (index, label) in labels.iter().enumerate().skip(first) {
|
||||
let width = label.width().min(usize::from(bar.right() - x)) as u16;
|
||||
let style = if index == active {
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
let decorated = index == active && fade;
|
||||
let width = (label.width() + if decorated { 6 } else { 0 })
|
||||
.min(usize::from(bar.right() - x)) as u16;
|
||||
let highlight = Style::default()
|
||||
.fg(Color::Black)
|
||||
.bg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let edge = Style::default().fg(Color::Cyan);
|
||||
let line = if decorated {
|
||||
Line::from(vec![
|
||||
Span::styled("░▒▓", edge),
|
||||
Span::styled(label.as_str(), highlight),
|
||||
Span::styled("▓▒░", edge),
|
||||
])
|
||||
} else {
|
||||
inactive
|
||||
Line::from(Span::styled(
|
||||
label.as_str(),
|
||||
if index == active { highlight } else { inactive },
|
||||
))
|
||||
};
|
||||
frame.render_widget(
|
||||
Paragraph::new(label.as_str()).style(style),
|
||||
Rect::new(x, bar.y, width, 1),
|
||||
);
|
||||
frame.render_widget(Paragraph::new(line), Rect::new(x, bar.y, width, 1));
|
||||
x += width;
|
||||
if x == bar.right() {
|
||||
break;
|
||||
@@ -1604,6 +1614,7 @@ fn draw_status(frame: &mut Frame, editor: &Editor, syntax: &SyntaxCache, status_
|
||||
} else {
|
||||
format!(" {}", editor.mode())
|
||||
};
|
||||
let mode_end = status.len();
|
||||
if let Some(sequence) = editor.sequence_pending() {
|
||||
write!(status, " {sequence}").unwrap();
|
||||
}
|
||||
@@ -1636,11 +1647,9 @@ fn draw_status(frame: &mut Frame, editor: &Editor, syntax: &SyntaxCache, status_
|
||||
}
|
||||
write!(
|
||||
status,
|
||||
" {}{} {}:{}",
|
||||
" {}{}",
|
||||
path,
|
||||
if editor.dirty() { " [+]" } else { "" },
|
||||
cursor.row + 1,
|
||||
cursor.column + 1,
|
||||
)
|
||||
.unwrap();
|
||||
if editor.selection_count() > 1 {
|
||||
@@ -1654,10 +1663,34 @@ fn draw_status(frame: &mut Frame, editor: &Editor, syntax: &SyntaxCache, status_
|
||||
} else if let Some(language) = syntax.language() {
|
||||
write!(status, " {language}").unwrap();
|
||||
}
|
||||
frame.render_widget(
|
||||
Paragraph::new(status).style(Style::default().fg(Color::Black).bg(Color::Cyan)),
|
||||
status_area,
|
||||
let highlight = Style::default().fg(Color::Black).bg(Color::Cyan);
|
||||
let edge = Style::default().fg(Color::Cyan);
|
||||
let position = format!(" {}:{} ", cursor.row + 1, cursor.column + 1);
|
||||
let right_width = (position.width() + 3) as u16;
|
||||
let show_right = status_area.width >= right_width + 12;
|
||||
let left = Rect::new(
|
||||
status_area.x,
|
||||
status_area.y,
|
||||
status_area.width - if show_right { right_width } else { 0 },
|
||||
status_area.height,
|
||||
);
|
||||
frame.render_widget(
|
||||
Paragraph::new(Line::from(vec![
|
||||
Span::styled(&status[..mode_end], highlight),
|
||||
Span::styled("▓▒░", edge),
|
||||
Span::raw(&status[mode_end..]),
|
||||
])),
|
||||
left,
|
||||
);
|
||||
if show_right {
|
||||
frame.render_widget(
|
||||
Paragraph::new(Line::from(vec![
|
||||
Span::styled("░▒▓", edge),
|
||||
Span::styled(position, highlight),
|
||||
])),
|
||||
Rect::new(left.right(), status_area.y, right_width, status_area.height),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
struct DiffGeometry {
|
||||
@@ -9201,9 +9234,6 @@ end
|
||||
assert_eq!(buffer[(x, y)].bg, Color::Reset);
|
||||
}
|
||||
}
|
||||
for x in area.x..area.right() {
|
||||
assert_eq!(buffer[(x, area.bottom() - 2)].bg, Color::Cyan);
|
||||
}
|
||||
assert_eq!(buffer[(0, 0)].symbol(), " ");
|
||||
editor.handle(Input::Char(' '));
|
||||
editor.handle(Input::Char('e'));
|
||||
@@ -10419,25 +10449,16 @@ end
|
||||
.unwrap();
|
||||
assert!(!screen_text(&terminal).contains("[buffer"));
|
||||
editor.execute(&format!("edit {}", b.display()));
|
||||
let b_id = editor.buffer_id();
|
||||
terminal
|
||||
.draw(|frame| viewports.draw(frame, &mut editor))
|
||||
.unwrap();
|
||||
let text = screen_text(&terminal);
|
||||
assert!(
|
||||
text.contains(&format!("NORMAL [buffer {b_id}/2]")),
|
||||
"{text}"
|
||||
);
|
||||
assert!(!text.contains("3 selections"), "{text}");
|
||||
editor.execute(&format!("buffer {a_id}"));
|
||||
terminal
|
||||
.draw(|frame| viewports.draw(frame, &mut editor))
|
||||
.unwrap();
|
||||
let text = screen_text(&terminal);
|
||||
assert!(
|
||||
text.contains(&format!("VISUAL [buffer {a_id}/2]")),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("3 selections"), "{text}");
|
||||
let (top, left) = viewports.offsets[&a_id];
|
||||
for selection in editor.selections() {
|
||||
|
||||
Reference in New Issue
Block a user