Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

fix(cli): compute about string only once, refactor it out of Theme (#441)

thenhnnb7fcbed2d8bb
diff --git a/crates/uzu/src/cli/components/logo.rs b/crates/uzu/src/cli/components/logo.rs
index fd2707cc5..a83f1c58d 100644
--- a/crates/uzu/src/cli/components/logo.rs
+++ b/crates/uzu/src/cli/components/logo.rs
@@ -1,10 +1,42 @@
+use backend_uzu::VERSION;
+use indoc::indoc;
use iocraft::prelude::*;
-use crate::cli::components::ApplicationState;
+use crate::{cli::components::ApplicationState, device::home_path};
+
+const LOGO: &str = indoc! {r"
+ _ __ ___ (_) _ __ __ _ (_)
+ | '_ ` _ \ | | | '__| / _` | | |
+ | | | | | | | | | | | (_| | | |
+ |_| |_| |_| |_| |_| \__,_| |_|"};
+
+fn about_text() -> String {
+ let current_path = std::env::current_dir().ok();
+ let home_path = home_path();
+
+ let mut lines = vec![
+ format!("v{}", VERSION),
+ "A high-performance inference engine for AI models".to_string(),
+ "Zero latency, full data privacy, no inference costs".to_string(),
+ ];
+
+ if let Some(current_path) = current_path {
+ let path = match home_path.as_ref().and_then(|home_path| current_path.strip_prefix(home_path).ok()) {
+ Some(relative_path) if relative_path.as_os_str().is_empty() => "~".to_string(),
+ Some(relative_path) => format!("~/{}", relative_path.display()),
+ None => current_path.display().to_string(),
+ };
+
+ lines.push(path);
+ }
+
+ lines.join("\n")
+}
#[component]
-pub fn Logo(hooks: Hooks) -> impl Into<AnyElement<'static>> {
+pub fn Logo(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
let state = hooks.use_context::<State<ApplicationState>>();
+ let about = hooks.use_const(|| about_text());
element! {
View(
@@ -14,11 +46,11 @@ pub fn Logo(hooks: Hooks) -> impl Into<AnyElement<'static>> {
column_gap: state.read().theme.padding_wide(),
) {
Text(
- content: state.read().theme.logo(),
+ content: LOGO,
color: state.read().theme.accent_color
)
Text(
- content: state.read().theme.about(),
+ content: about,
color: state.read().theme.subtitle_color
)
}
diff --git a/crates/uzu/src/cli/components/theme.rs b/crates/uzu/src/cli/components/theme.rs
index 03bc029c9..572b2e2c6 100644
--- a/crates/uzu/src/cli/components/theme.rs
+++ b/crates/uzu/src/cli/components/theme.rs
@@ -1,10 +1,7 @@
-use backend_uzu::VERSION;
-use indoc::indoc;
use iocraft::prelude::*;
use crate::{
cli::helpers::ColorRgb,
- device::Device,
settings::{SettingKind, Settings, SettingsError},
};
@@ -89,37 +86,6 @@ impl Theme {
}
}
-impl Theme {
- pub fn logo(&self) -> String {
- let text = indoc! {r"
- _ __ ___ (_) _ __ __ _ (_)
- | '_ ` _ \ | | | '__| / _` | | |
- | | | | | | | | | | | (_| | | |
- |_| |_| |_| |_| |_| \__,_| |_|"};
- text.to_string()
- }
-
- pub fn about(&self) -> String {
- let current_path = std::env::current_dir().ok().map(|path| path.display().to_string());
- let home_path = Device::new().ok().map(|device| device.home_path);
- let mut lines = vec![
- format!("v{}", VERSION),
- "A high-performance inference engine for AI models".to_string(),
- "Zero latency, full data privacy, no inference costs".to_string(),
- ];
- if let Some(current_path) = current_path {
- let path = match &home_path {
- Some(home_path) if current_path.starts_with(home_path.as_str()) => {
- format!("~{}", &current_path[home_path.len()..])
- },
- _ => current_path,
- };
- lines.push(path);
- }
- lines.join("\n")
- }
-}
-
impl Theme {
pub fn load(settings: &Settings) -> Result<Option<Self>, SettingsError> {
let Some(name) = settings.load(SettingKind::Config, SETTINGS_THEME.to_string())? else {
diff --git a/crates/uzu/src/device/mod.rs b/crates/uzu/src/device/mod.rs
index 775cb7c82..8e6c0ee57 100644
--- a/crates/uzu/src/device/mod.rs
+++ b/crates/uzu/src/device/mod.rs
@@ -2,7 +2,7 @@ mod error;
mod os;
pub use error::DeviceError;
-use os::home_path;
+pub(crate) use os::home_path;
use serde::{Deserialize, Serialize};
use sysinfo::System;