Skip to content

Commit

Permalink
feat: add tui-max-flows config
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Nov 29, 2023
1 parent 71b5691 commit 6c6b544
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub struct TrippyConfig {
pub dns_resolve_method: ResolveMethod,
pub dns_lookup_as_info: bool,
pub tui_max_samples: usize,
pub tui_max_flows: usize,
pub tui_preserve_screen: bool,
pub tui_refresh_rate: Duration,
pub tui_privacy_max_ttl: u8,
Expand Down Expand Up @@ -413,6 +414,11 @@ impl TrippyConfig {
cfg_file_tui.tui_max_samples,
constants::DEFAULT_TUI_MAX_SAMPLES,
);
let tui_max_flows = cfg_layer(
args.tui_max_flows,
cfg_file_tui.tui_max_flows,
constants::DEFAULT_TUI_MAX_FLOWS,
);
let tui_preserve_screen = cfg_layer_bool_flag(
args.tui_preserve_screen,
cfg_file_tui.tui_preserve_screen,
Expand Down Expand Up @@ -599,6 +605,7 @@ impl TrippyConfig {
dns_resolve_method,
dns_lookup_as_info,
tui_max_samples,
tui_max_flows,
tui_preserve_screen,
tui_refresh_rate,
tui_privacy_max_ttl,
Expand Down Expand Up @@ -649,6 +656,7 @@ impl Default for TrippyConfig {
dns_resolve_method: dns_resolve_method(constants::DEFAULT_DNS_RESOLVE_METHOD),
dns_lookup_as_info: constants::DEFAULT_DNS_LOOKUP_AS_INFO,
tui_max_samples: constants::DEFAULT_TUI_MAX_SAMPLES,
tui_max_flows: constants::DEFAULT_TUI_MAX_FLOWS,
tui_preserve_screen: constants::DEFAULT_TUI_PRESERVE_SCREEN,
tui_refresh_rate: duration(constants::DEFAULT_TUI_REFRESH_RATE),
tui_privacy_max_ttl: constants::DEFAULT_TUI_PRIVACY_MAX_TTL,
Expand Down
4 changes: 4 additions & 0 deletions src/config/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ pub struct Args {
#[arg(long, short = 's')]
pub tui_max_samples: Option<usize>,

/// The maximum number of flows to show [default: 40]
#[arg(long)]
pub tui_max_flows: Option<usize>,

/// Preserve the screen on exit [default: false]
#[arg(long)]
pub tui_preserve_screen: bool,
Expand Down
3 changes: 3 additions & 0 deletions src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub const DEFAULT_STRATEGY_READ_TIMEOUT: &str = "10ms";
/// The default value for `tui-max-samples`.
pub const DEFAULT_TUI_MAX_SAMPLES: usize = 256;

/// The default value for `tui-max-flows`.
pub const DEFAULT_TUI_MAX_FLOWS: usize = 64;

/// The default value for `tui-preserve-screen`.
pub const DEFAULT_TUI_PRESERVE_SCREEN: bool = false;

Expand Down
2 changes: 2 additions & 0 deletions src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl Default for ConfigReport {
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct ConfigTui {
pub tui_max_samples: Option<usize>,
pub tui_max_flows: Option<usize>,
pub tui_preserve_screen: Option<bool>,
pub tui_refresh_rate: Option<String>,
pub tui_privacy_max_ttl: Option<u8>,
Expand All @@ -228,6 +229,7 @@ impl Default for ConfigTui {
fn default() -> Self {
Self {
tui_max_samples: Some(super::constants::DEFAULT_TUI_MAX_SAMPLES),
tui_max_flows: Some(super::constants::DEFAULT_TUI_MAX_FLOWS),
tui_preserve_screen: Some(super::constants::DEFAULT_TUI_PRESERVE_SCREEN),
tui_refresh_rate: Some(String::from(super::constants::DEFAULT_TUI_REFRESH_RATE)),
tui_privacy_max_ttl: Some(super::constants::DEFAULT_TUI_PRIVACY_MAX_TTL),
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct TuiConfig {
pub max_addrs: Option<u8>,
/// The maximum number of samples to record per hop.
pub max_samples: usize,
/// The maximum number of flows to display.
pub max_flows: usize,
/// The Tui color theme.
pub theme: Theme,
/// The Tui keyboard bindings.
Expand All @@ -46,6 +48,7 @@ impl TuiConfig {
geoip_mode: GeoIpMode,
max_addrs: Option<u8>,
max_samples: usize,
max_flows: usize,
tui_theme: TuiTheme,
tui_bindings: &TuiBindings,
) -> Self {
Expand All @@ -60,6 +63,7 @@ impl TuiConfig {
geoip_mode,
max_addrs,
max_samples,
max_flows,
theme: Theme::from(tui_theme),
bindings: Bindings::from(*tui_bindings),
}
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/render/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn format_all_settings(app: &TuiApp) -> Vec<(&'static str, &'static str, Vec<Set
fn format_tui_settings(app: &TuiApp) -> Vec<SettingsItem> {
vec![
SettingsItem::new("tui-max-samples", format!("{}", app.tui_config.max_samples)),
SettingsItem::new("tui-max-flows", format!("{}", app.tui_config.max_flows)),
SettingsItem::new(
"tui-preserve-screen",
format!("{}", app.tui_config.preserve_screen),
Expand Down Expand Up @@ -419,7 +420,7 @@ fn format_theme_settings(app: &TuiApp) -> Vec<SettingsItem> {

/// The name and number of items for each tabs in the setting dialog.
pub const SETTINGS_TABS: [(&str, usize); 6] = [
("Tui", 8),
("Tui", 9),
("Trace", 15),
("Dns", 4),
("GeoIp", 1),
Expand Down
1 change: 1 addition & 0 deletions src/frontend/tui_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl TuiApp {
})
.sorted_by(order_flows)
.rev()
.take(self.tui_config.max_flows)
.collect::<Vec<_>>();
}

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ fn make_tui_config(args: &TrippyConfig) -> TuiConfig {
args.tui_geoip_mode,
args.tui_max_addrs,
args.tui_max_samples,
args.tui_max_flows,
args.tui_theme,
&args.tui_bindings,
)
Expand Down
3 changes: 3 additions & 0 deletions trippy-config-sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ tui-max-addrs = 0
# The maximum number of samples to record per hop [default: 256]
tui-max-samples = 256

# The maximum number of flows to show [default: 40]
tui-max-flows = 64

# Whether to preserve the screen on exit [default: false]
tui-preserve-screen = false

Expand Down

0 comments on commit 6c6b544

Please sign in to comment.