Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Information Bar #1338

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 18 additions & 53 deletions crates/trippy-tui/locales/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,55 +76,20 @@ target:
it: "Target"
pt: "Alvo"
zh: "目标"
config:
en: "Config"
fr: "Config"
tr: "Konfigurasyon"
it: "Config"
pt: "Config"
zh: "配置"
status:
en: "Status"
fr: "Statut"
tr: "Durum"
it: "Stato"
pt: "Estado"
zh: "状态"
protocol:
en: "protocol"
fr: "protocole"
tr: "protokol"
it: "protocollo"
pt: "protocolo"
zh: "协议"
as-info:
en: "as-info"
fr: "info-as"
tr: "AS bilgisi"
it: "info-as"
pt: "info-as"
zh: "AS 信息"
details:
en: "details"
fr: "détails"
en: "detail"
fr: "détail"
tr: "ayrıntılar"
it: "dettagli"
pt: "detalhes"
pt: "detalhe"
zh: "详情"
max-hosts:
en: "max-hosts"
fr: "nombre d'hôtes maximum"
tr: "maksimum hostlar"
it: "max-hosts"
pt: "max-hosts"
zh: "最大主机数"
privacy:
en: "privacy"
fr: "confidentialité"
tr: "gizlilik"
it: "privacy"
pt: "privacidade"
zh: "隐私"
privileged:
en: "privileged"
fr: "privilégié"
Expand Down Expand Up @@ -224,25 +189,25 @@ awaiting_data:
pt: "Aguardando dados..."
zh: "等待数据……"
header_help:
en: "elp"
fr: "Aide"
tr: "Yardım"
it: "Aiuto"
pt: "Ajuda"
en: "help"
fr: "aide"
tr: "yardım"
it: "aiuto"
pt: "ajuda"
zh: "帮助"
header_settings:
en: "ettings"
fr: "Paramètres"
tr: "Ayarlar"
it: "Impostazioni"
pt: "Configurações"
en: "settings"
fr: "paramètres"
tr: "ayarlar"
it: "impostazioni"
pt: "configurações"
zh: "设置"
header_quit:
en: "uit"
fr: "Quitter"
tr: "Çıkış"
it: "Uscita"
pt: "Sair"
en: "quit"
fr: "quitter"
tr: "cıkış"
it: "uscita"
pt: "sair"
zh: "退出"
title_hops:
en: "Hops"
Expand Down
20 changes: 14 additions & 6 deletions crates/trippy-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use trippy_privilege::Privilege;
/// Run the trippy application.
pub fn run_trippy(cfg: &TrippyConfig, pid: u16) -> anyhow::Result<()> {
set_locale(cfg.tui_locale.as_deref());
let locale = locale();
let _guard = configure_logging(cfg);
let resolver = start_dns_resolver(cfg)?;
let geoip_lookup = create_geoip_lookup(cfg, locale())?;
let geoip_lookup = create_geoip_lookup(cfg, &locale)?;
let addrs = resolve_targets(cfg, &resolver)?;
if addrs.is_empty() {
return Err(anyhow!(
Expand All @@ -29,7 +30,7 @@ pub fn run_trippy(cfg: &TrippyConfig, pid: u16) -> anyhow::Result<()> {
}
let traces = start_tracers(cfg, &addrs, pid)?;
Privilege::drop_privileges()?;
run_frontend(cfg, resolver, geoip_lookup, traces)
run_frontend(cfg, locale, resolver, geoip_lookup, traces)
}

/// Start all tracers.
Expand Down Expand Up @@ -87,12 +88,18 @@ fn start_tracer(
/// Run the TUI, stream or report.
fn run_frontend(
args: &TrippyConfig,
locale: String,
resolver: DnsResolver,
geoip_lookup: GeoIpLookup,
traces: Vec<TraceInfo>,
) -> anyhow::Result<()> {
match args.mode {
Mode::Tui => frontend::run_frontend(traces, make_tui_config(args), resolver, geoip_lookup)?,
Mode::Tui => frontend::run_frontend(
traces,
make_tui_config(args, locale),
resolver,
geoip_lookup,
)?,
Mode::Stream => report::stream::report(&traces[0], &resolver)?,
Mode::Csv => report::csv::report(&traces[0], args.report_cycles, &resolver)?,
Mode::Json => report::json::report(&traces[0], args.report_cycles, &resolver)?,
Expand Down Expand Up @@ -141,9 +148,9 @@ fn start_dns_resolver(cfg: &TrippyConfig) -> anyhow::Result<DnsResolver> {
))?)
}

fn create_geoip_lookup(cfg: &TrippyConfig, locale: String) -> anyhow::Result<GeoIpLookup> {
fn create_geoip_lookup(cfg: &TrippyConfig, locale: &str) -> anyhow::Result<GeoIpLookup> {
if let Some(path) = cfg.geoip_mmdb_file.as_ref() {
GeoIpLookup::from_file(path, locale)
GeoIpLookup::from_file(path, String::from(locale))
} else {
Ok(GeoIpLookup::empty())
}
Expand Down Expand Up @@ -192,7 +199,7 @@ fn configure_logging(cfg: &TrippyConfig) -> Option<FlushGuard> {
}

/// Make the TUI configuration.
fn make_tui_config(args: &TrippyConfig) -> TuiConfig {
fn make_tui_config(args: &TrippyConfig, locale: String) -> TuiConfig {
TuiConfig::new(
args.tui_refresh_rate,
args.tui_privacy_max_ttl,
Expand All @@ -208,6 +215,7 @@ fn make_tui_config(args: &TrippyConfig) -> TuiConfig {
&args.tui_custom_columns,
args.geoip_mmdb_file.clone(),
args.dns_resolve_all,
locale,
)
}

Expand Down
4 changes: 4 additions & 0 deletions crates/trippy-tui/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ pub struct ConfigThemeColors {
pub map_info_panel_border_color: Option<TuiColor>,
pub map_info_panel_bg_color: Option<TuiColor>,
pub map_info_panel_text_color: Option<TuiColor>,
pub info_bar_bg_color: Option<TuiColor>,
pub info_bar_text_color: Option<TuiColor>,
}

impl Default for ConfigThemeColors {
Expand Down Expand Up @@ -348,6 +350,8 @@ impl Default for ConfigThemeColors {
map_info_panel_border_color: Some(theme.map_info_panel_border),
map_info_panel_bg_color: Some(theme.map_info_panel_bg),
map_info_panel_text_color: Some(theme.map_info_panel_text),
info_bar_bg_color: Some(theme.info_bar_bg),
info_bar_text_color: Some(theme.info_bar_text),
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions crates/trippy-tui/src/config/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ pub struct TuiTheme {
pub map_info_panel_bg: TuiColor,
/// The color of text in the map info panel.
pub map_info_panel_text: TuiColor,
/// The color of the info bar background.
pub info_bar_bg: TuiColor,
/// The color of the info bar text.
pub info_bar_text: TuiColor,
}

impl Default for TuiTheme {
Expand Down Expand Up @@ -114,6 +118,8 @@ impl Default for TuiTheme {
map_info_panel_border: TuiColor::Gray,
map_info_panel_bg: TuiColor::Black,
map_info_panel_text: TuiColor::Gray,
info_bar_bg: TuiColor::White,
info_bar_text: TuiColor::Black,
}
}
}
Expand Down Expand Up @@ -251,6 +257,14 @@ impl From<(HashMap<TuiThemeItem, TuiColor>, ConfigThemeColors)> for TuiTheme {
.get(&TuiThemeItem::MapInfoPanelTextColor)
.or(cfg.map_info_panel_text_color.as_ref())
.unwrap_or(&Self::default().map_info_panel_text),
info_bar_bg: *color_map
.get(&TuiThemeItem::InfoBarBgColor)
.or(cfg.info_bar_bg_color.as_ref())
.unwrap_or(&Self::default().info_bar_bg),
info_bar_text: *color_map
.get(&TuiThemeItem::InfoBarTextColor)
.or(cfg.info_bar_text_color.as_ref())
.unwrap_or(&Self::default().info_bar_text),
}
}
}
Expand Down Expand Up @@ -324,6 +338,10 @@ pub enum TuiThemeItem {
MapInfoPanelBgColor,
/// The color of text in the map info panel.
MapInfoPanelTextColor,
/// The color of the info bar background.
InfoBarBgColor,
/// The color of the info bar text.
InfoBarTextColor,
}

/// A TUI color.
Expand Down
5 changes: 4 additions & 1 deletion crates/trippy-tui/src/frontend/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct TuiConfig {
pub tui_columns: Columns,
pub geoip_mmdb_file: Option<String>,
pub dns_resolve_all: bool,
/// The current locale.
pub locale: String,
}

impl TuiConfig {
Expand All @@ -51,9 +53,9 @@ impl TuiConfig {
tui_theme: TuiTheme,
tui_bindings: &TuiBindings,
tui_columns: &TuiColumns,

geoip_mmdb_file: Option<String>,
dns_resolve_all: bool,
locale: String,
) -> Self {
Self {
refresh_rate,
Expand All @@ -70,6 +72,7 @@ impl TuiConfig {
tui_columns: Columns::from(tui_columns.clone()),
geoip_mmdb_file,
dns_resolve_all,
locale,
}
}
}
1 change: 1 addition & 0 deletions crates/trippy-tui/src/frontend/render.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod app;
pub mod bar;
pub mod body;
pub mod bsod;
pub mod chart;
Expand Down
27 changes: 17 additions & 10 deletions crates/trippy-tui/src/frontend/render/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::frontend::render::{body, flows, footer, header, help, settings, tabs};
use crate::frontend::render::{bar, body, flows, footer, header, help, settings, tabs};
use crate::frontend::tui_app::TuiApp;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame;
Expand All @@ -25,14 +25,15 @@ use ratatui::Frame;
/// | History | Frequency |
/// | | |
/// ------------------------------------
/// ====== info configuration bar ======
///
/// - Header: the title, configuration, destination, clock and keyboard controls
/// - Tab: a tab for each target being traced (shown if > 1 target requested, can't be used with
/// flows)
/// - Header: the title, target, clock and basic keyboard controls
/// - Tab: a tab for each target (shown if > 1 target requested, can't be used with flows)
/// - Flows: a navigable chart of individual trace flows (toggled on/off, can't be used with tabs)
/// - Hops: a table where each row represents a single hop (time-to-live) in the trace
/// - History: a graph of historic round-trip ping samples for the target host
/// - Frequency: a histogram of sample frequencies by round-trip time for the target host
/// - Info bar: a bar showing the current value for configurable items
///
/// On startup a splash screen is shown in place of the hops table, until the completion of the
/// first round.
Expand All @@ -53,13 +54,16 @@ pub fn render(f: &mut Frame<'_>, app: &mut TuiApp) {
tabs::render(f, chunks[1], app);
body::render(f, chunks[2], app);
footer::render(f, chunks[3], app);
bar::render(f, chunks[4], app);
} else if app.show_flows {
flows::render(f, chunks[1], app);
body::render(f, chunks[2], app);
footer::render(f, chunks[3], app);
bar::render(f, chunks[4], app);
} else {
body::render(f, chunks[1], app);
footer::render(f, chunks[2], app);
bar::render(f, chunks[3], app);
}
if app.show_settings {
settings::render(f, app);
Expand All @@ -68,22 +72,25 @@ pub fn render(f: &mut Frame<'_>, app: &mut TuiApp) {
}
}

const LAYOUT_WITHOUT_TABS: [Constraint; 3] = [
Constraint::Length(5),
const LAYOUT_WITHOUT_TABS: [Constraint; 4] = [
Constraint::Length(4),
Constraint::Min(10),
Constraint::Length(6),
Constraint::Length(1),
];

const LAYOUT_WITH_TABS: [Constraint; 4] = [
Constraint::Length(5),
const LAYOUT_WITH_TABS: [Constraint; 5] = [
Constraint::Length(4),
Constraint::Length(3),
Constraint::Min(10),
Constraint::Length(6),
Constraint::Length(1),
];

const LAYOUT_WITH_FLOWS: [Constraint; 4] = [
Constraint::Length(5),
const LAYOUT_WITH_FLOWS: [Constraint; 5] = [
Constraint::Length(4),
Constraint::Length(6),
Constraint::Min(10),
Constraint::Length(6),
Constraint::Length(1),
];
Loading