feat(tui): move tabs to border title, fix live log auto-scroll
This commit is contained in:
1 parent
bc07b4af31
commit
011e0ef6bf
4 files changed
+57
-27
No files matched your search
+32
-20
@@ -2,7 +2,7 @@ use ratatui::{
|
||||
layout::{Alignment, Constraint, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph, Tabs},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use throbber_widgets_tui::{Throbber, ThrobberState};
|
||||
@@ -84,32 +84,44 @@ pub fn render(
|
||||
THEME.colors.border_unfocused
|
||||
};
|
||||
|
||||
let tab_titles: Vec<Span> = ContentTab::ALL
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, t)| {
|
||||
let mut spans = Vec::new();
|
||||
if i > 0 {
|
||||
spans.push(Span::styled(
|
||||
"\u{2022}",
|
||||
Style::default().fg(THEME.colors.border_unfocused),
|
||||
));
|
||||
}
|
||||
if i == tab.index() {
|
||||
spans.push(Span::styled(
|
||||
format!(" {} ", t.label()),
|
||||
Style::default()
|
||||
.fg(THEME.colors.accent)
|
||||
.bg(THEME.colors.row_background)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
} else {
|
||||
spans.push(Span::styled(
|
||||
format!(" {} ", t.label()),
|
||||
Style::default().fg(THEME.colors.foreground),
|
||||
));
|
||||
}
|
||||
spans
|
||||
})
|
||||
.collect();
|
||||
|
||||
let block = Block::default()
|
||||
.title_top(Line::from(tab_titles))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(border_color));
|
||||
|
||||
let inner = block.inner(area);
|
||||
let content_area = block.inner(area);
|
||||
frame.render_widget(block, area);
|
||||
|
||||
let [tabs_area, content_area] =
|
||||
Layout::vertical([Constraint::Length(1), Constraint::Min(0)]).areas(inner);
|
||||
|
||||
let tab_titles: Vec<&str> = ContentTab::ALL.iter().map(|t| t.label()).collect();
|
||||
let tabs = Tabs::new(tab_titles)
|
||||
.select(tab.index())
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.colors.accent)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.divider(Span::styled(
|
||||
" │ ",
|
||||
Style::default().fg(THEME.colors.border_unfocused),
|
||||
));
|
||||
|
||||
frame.render_widget(tabs, tabs_area);
|
||||
|
||||
match tab {
|
||||
ContentTab::Mods => {
|
||||
if let Some(instance) = instance {
|
||||
|
||||
@@ -303,6 +303,12 @@ pub fn render(
|
||||
let show_selected = is_focused && context.is_selected;
|
||||
let use_mc_colors = *enabled && !show_selected;
|
||||
|
||||
let stripe_bg = if context.index % 2 == 0 {
|
||||
Color::Reset
|
||||
} else {
|
||||
THEME.colors.row_alternate_bg
|
||||
};
|
||||
|
||||
let (name_style, description_style, background) = match (*enabled, show_selected) {
|
||||
(true, true) => (
|
||||
Style::default()
|
||||
@@ -316,7 +322,7 @@ pub fn render(
|
||||
.fg(THEME.colors.foreground)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.colors.text_idle),
|
||||
THEME.colors.row_alternate_bg,
|
||||
stripe_bg,
|
||||
),
|
||||
(false, true) => (
|
||||
Style::default()
|
||||
@@ -330,7 +336,7 @@ pub fn render(
|
||||
.fg(THEME.colors.text_idle)
|
||||
.add_modifier(Modifier::CROSSED_OUT),
|
||||
Style::default().fg(THEME.colors.text_idle),
|
||||
THEME.colors.row_alternate_bg,
|
||||
stripe_bg,
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{
|
||||
Block, BorderType, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,
|
||||
@@ -142,7 +142,10 @@ impl LogsState {
|
||||
|
||||
fn has_live(&self) -> bool {
|
||||
let name = self.loaded_for.as_deref().unwrap_or("");
|
||||
!crate::instance_logs::get_all(name).is_empty()
|
||||
matches!(
|
||||
crate::running::get(name),
|
||||
Some(crate::running::RunState::Running) | Some(crate::running::RunState::Starting)
|
||||
)
|
||||
}
|
||||
|
||||
fn display_count(&self) -> usize {
|
||||
@@ -367,6 +370,8 @@ fn render_list(
|
||||
|
||||
let bg = if show_selected {
|
||||
THEME.colors.row_background
|
||||
} else if context.index % 2 == 0 {
|
||||
Color::Reset
|
||||
} else {
|
||||
THEME.colors.row_alternate_bg
|
||||
};
|
||||
@@ -419,9 +424,10 @@ fn render_viewer(
|
||||
};
|
||||
|
||||
let visible_height = area.height as usize;
|
||||
let was_at_bottom = state.viewer_scroll >= state.viewer_max_scroll.saturating_sub(1);
|
||||
state.update_viewer_scrollbar(visible_height, lines.len());
|
||||
|
||||
if is_live && !state.viewer_focused {
|
||||
if is_live && was_at_bottom {
|
||||
state.viewer_scroll = state.viewer_max_scroll;
|
||||
state.viewer_scrollbar_state =
|
||||
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crossterm::event::KeyCode;
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Modifier, Style},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span, Text},
|
||||
widgets::{Block, BorderType, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
|
||||
Frame,
|
||||
@@ -221,6 +221,12 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
let idx = filtered[context.index];
|
||||
let instance = &state.instances[idx];
|
||||
|
||||
let stripe_bg = if context.index % 2 == 0 {
|
||||
Color::Reset
|
||||
} else {
|
||||
THEME.colors.row_alternate_bg
|
||||
};
|
||||
|
||||
let (name_style, meta_style, bg) = if context.is_selected {
|
||||
(
|
||||
Style::default()
|
||||
@@ -235,7 +241,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
.fg(THEME.colors.border_focused)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.colors.border_unfocused),
|
||||
THEME.colors.row_alternate_bg,
|
||||
stripe_bg,
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user