diff options
| -rw-r--r-- | src/client/macros.rs | 13 | ||||
| -rw-r--r-- | src/render/stream.rs | 2 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/client/macros.rs b/src/client/macros.rs index ee710c3..0543cd6 100644 --- a/src/client/macros.rs +++ b/src/client/macros.rs @@ -98,21 +98,20 @@ macro_rules! register_client { anyhow::bail!("Unknown client '{}'", client) } - static mut ALL_CLIENT_MODELS: Option<Vec<$crate::client::Model>> = None; + static ALL_CLIENT_MODELS: std::sync::OnceLock<Vec<$crate::client::Model>> = std::sync::OnceLock::new(); pub fn list_models(config: &$crate::config::Config) -> Vec<&'static $crate::client::Model> { - if unsafe { ALL_CLIENT_MODELS.is_none() } { - let models: Vec<_> = config + let models = ALL_CLIENT_MODELS.get_or_init(|| { + config .clients .iter() .flat_map(|v| match v { $(ClientConfig::$config(c) => $client::list_models(c),)+ ClientConfig::Unknown => vec![], }) - .collect(); - unsafe { ALL_CLIENT_MODELS = Some(models) }; - } - unsafe { ALL_CLIENT_MODELS.as_ref().unwrap().iter().collect() } + .collect() + }); + models.iter().collect() } pub fn list_chat_models(config: &$crate::config::Config) -> Vec<&'static $crate::client::Model> { diff --git a/src/render/stream.rs b/src/render/stream.rs index 6ff6ea7..d2ac6ef 100644 --- a/src/render/stream.rs +++ b/src/render/stream.rs @@ -204,5 +204,5 @@ fn split_line_tail(text: &str) -> (&str, &str) { fn need_rows(text: &str, columns: u16) -> u16 { let buffer_width = display_width(text).max(1) as u16; - (buffer_width + columns - 1) / columns + buffer_width.div_ceil(columns) } |
