use std::{fmt::Display, future::Future}; use gpui_kit::{ App, AsyncWindowContext, Context, Div, Entity, ParentElement, Styled, WeakEntity, Window, component::{input::Input, input::InputState}, div, px, }; use super::{ Yumush, notify_error, style::{Tokens, size, space}, }; pub(super) fn underline(t: Tokens, height: f32, child: impl gpui_kit::IntoElement) -> Div { div() .h(px(height)) .flex() .items_center() .border_b_1() .border_color(t.thread()) .child(div().flex_1().min_w_0().child(child)) } pub(super) fn field(t: Tokens, input: &Entity) -> Div { frame(t, Input::new(input).token(super::glyph::token)) } pub(super) fn compact_field(t: Tokens, input: &Entity) -> Div { underline( t, size::CONTROL_SM + space::XS, bare_input(t, Input::new(input).token(super::glyph::token)), ) } pub(super) fn frame(t: Tokens, input: Input) -> Div { underline(t, size::CONTROL, bare_input(t, input)) } pub(super) fn bare_input(t: Tokens, input: Input) -> Input { input .appearance(false) .text_color(t.paper()) .flex_1() .min_w_0() } pub(super) fn search_text(input: &Entity, cx: &App) -> String { input.read(cx).text().to_string().trim().to_lowercase() } pub(super) fn ok_or_notify( result: Result, this: &WeakEntity, cx: &mut AsyncWindowContext, ) -> Option { result.map_err(|error| notify_error(this, cx, error)).ok() } pub(super) fn spawn_done( window: &mut Window, cx: &mut Context, call: impl Future> + 'static, ) { cx.spawn_in(window, async move |this, cx| { if let Err(error) = call.await { notify_error(&this, cx, error); } }) .detach(); } pub(super) fn spawn_warn( cx: &mut Context, label: &'static str, call: impl Future> + 'static, ) { cx.spawn(async move |_, _| { if let Err(error) = call.await { tracing::warn!("{label} failed: {error}"); } }) .detach(); }