Skip to main content

ui/
utils.rs

1//! UI-related utilities
2
3use gpui::App;
4use theme::ActiveTheme;
5
6mod apca_contrast;
7mod color_contrast;
8mod constants;
9mod corner_solver;
10mod format_distance;
11mod fuzzy_match;
12mod search_input;
13mod with_rem_size;
14
15pub use apca_contrast::*;
16pub use color_contrast::*;
17pub use constants::*;
18pub use corner_solver::{CornerSolver, inner_corner_radius};
19pub use format_distance::*;
20pub use fuzzy_match::*;
21pub use search_input::*;
22pub use with_rem_size::*;
23
24/// Returns true if the current theme is light or vibrant light.
25pub fn is_light(cx: &mut App) -> bool {
26    cx.theme().appearance.is_light()
27}
28
29/// Returns the platform-appropriate label for the "reveal in file manager" action.
30pub fn reveal_in_file_manager_label(is_remote: bool) -> &'static str {
31    if cfg!(target_os = "macos") && !is_remote {
32        "Reveal in Finder"
33    } else if cfg!(target_os = "windows") && !is_remote {
34        "Reveal in File Explorer"
35    } else {
36        "Reveal in File Manager"
37    }
38}
39
40/// Capitalizes the first character of a string.
41///
42/// This function takes a string slice as input and returns a new `String` with the first character
43/// capitalized.
44///
45/// # Examples
46///
47/// ```
48/// use ui::utils::capitalize;
49///
50/// assert_eq!(capitalize("hello"), "Hello");
51/// assert_eq!(capitalize("WORLD"), "WORLD");
52/// assert_eq!(capitalize(""), "");
53/// ```
54pub fn capitalize(str: &str) -> String {
55    let mut chars = str.chars();
56    match chars.next() {
57        None => String::new(),
58        Some(first_char) => first_char.to_uppercase().collect::<String>() + chars.as_str(),
59    }
60}