diff --git a/Cargo.lock b/Cargo.lock index 91ba928..a3ca4d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1459,6 +1459,8 @@ dependencies = [ "rlimit", "serde", "serde_json", + "smallvec", + "strum 0.27.2", "tikv-jemallocator", "tokio", "tokio-util", @@ -1583,7 +1585,7 @@ dependencies = [ "itertools 0.13.0", "lru", "paste", - "strum", + "strum 0.26.3", "unicode-segmentation", "unicode-truncate", "unicode-width 0.2.0", @@ -1996,7 +1998,16 @@ version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros", + "strum_macros 0.26.4", +] + +[[package]] +name = "strum" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" +dependencies = [ + "strum_macros 0.27.2", ] [[package]] @@ -2012,6 +2023,18 @@ dependencies = [ "syn", ] +[[package]] +name = "strum_macros" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "subtle" version = "2.6.1" diff --git a/Cargo.toml b/Cargo.toml index 2b2d158..5843904 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,11 @@ reqwest-middleware = "=0.4.2" rlimit = "=0.10.2" serde = "=1.0.228" serde_json = "=1.0.145" +smallvec = { version = "=1.15.1", features = [ + "const_generics", + "union", +], optional = true } +strum = { version = "=0.27.2", features = ["derive"], optional = true } tokio = { version = "=1.47.1", features = ["full"] } tokio-util = "=0.7.16" toml = "=0.9.7" @@ -64,7 +69,14 @@ jemalloc = ["dep:tikv-jemallocator"] mimalloc_v2 = ["dep:mimalloc"] mimalloc_v3 = ["dep:mimalloc", "mimalloc/v3"] tokio-current-thread = [] -tui = ["dep:crossterm", "dep:futures", "dep:ratatui", "dep:tui-logger"] +tui = [ + "dep:crossterm", + "dep:futures", + "dep:smallvec", + "dep:strum", + "dep:ratatui", + "dep:tui-logger", +] [profile.release] strip = true diff --git a/src/proxy.rs b/src/proxy.rs index edf9320..6ce36df 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -16,6 +16,7 @@ use crate::{ #[derive( Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, )] +#[cfg_attr(feature = "tui", derive(strum::EnumCount))] #[serde(rename_all = "lowercase")] pub enum ProxyType { Http, diff --git a/src/tui.rs b/src/tui.rs index b29eb3b..5a40b1d 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -17,6 +17,7 @@ use ratatui::{ text::{Line, Text}, widgets::{Block, Gauge}, }; +use strum::EnumCount as _; use tui_logger::{TuiLoggerWidget, TuiWidgetEvent, TuiWidgetState}; use crate::{ @@ -205,7 +206,8 @@ fn draw(f: &mut Frame<'_>, state: &AppState, logger_state: &TuiWidgetState) { ); drop(ipdb_layout); - let mut proxy_types: Vec<_> = state.sources_total.keys().collect(); + let mut proxy_types: smallvec::SmallVec<[_; ProxyType::COUNT]> = + state.sources_total.keys().collect(); proxy_types.sort_unstable(); let proxies_layout = Layout::default()