use duat_core::{
data::Pass,
hook::{self, FocusedOn, UnfocusedFrom},
try_or_log_err,
ui::PushTarget,
};
pub(crate) use self::{
completions::setup_completions, info::add_info_hooks, logbook::add_logbook_hooks,
notifications::add_notifications_hook, promptline::add_promptline_hooks,
whichkey::add_whichkey_hooks,
};
pub use self::{
completions::{CommandsCompletions, Completions, CompletionsBuilder, CompletionsProvider},
gutter::{Gutter, GutterBuffer, GutterEntryBuilder},
info::Info,
line_numbers::{LineNumbers, LineNumbersOpts},
logbook::{LogBook, LogBookOpts},
notifications::{Notifications, NotificationsOpts},
promptline::{PromptLine, PromptLineBuilder},
status_line::{State, StatusLine, StatusLineFmt, status},
whichkey::WhichKey,
};
mod completions;
mod gutter;
mod info;
mod line_numbers;
mod logbook;
mod notifications;
mod promptline;
mod status_line;
mod whichkey;
pub struct FooterWidgets {
status: StatusLineFmt,
prompt: PromptLineBuilder,
notifs: NotificationsOpts,
one_line: bool,
above: bool,
}
impl FooterWidgets {
pub fn push_on(mut self, pa: &mut Pass, push_target: &impl PushTarget) {
let prompt_line = if self.one_line {
self.prompt.request_width()
} else {
self.prompt
};
let prompt_line = if self.above {
prompt_line.above().hidden().push_on(pa, push_target)
} else {
prompt_line.below().hidden().push_on(pa, push_target)
};
if self.one_line {
self.status.right().push_on(pa, &prompt_line);
} else {
self.status.above().push_on(pa, &prompt_line);
};
let notifications = if self.one_line {
self.notifs.request_width();
self.notifs.push_on(pa, &prompt_line)
} else {
self.notifs.push_on(pa, &prompt_line)
};
hook::add::<FocusedOn<PromptLine>>({
let notifications = notifications.clone();
move |pa, (_, handle)| {
try_or_log_err! {
notifications.area().hide(pa)?;
handle.area().reveal(pa)?;
}
}
})
.filter(prompt_line.clone());
hook::add::<UnfocusedFrom<PromptLine>>({
move |pa, (handle, _)| {
try_or_log_err! {
notifications.area().reveal(pa)?;
handle.area().hide(pa)?;
}
}
})
.filter(prompt_line);
}
pub fn new(status_cfg: StatusLineFmt) -> Self {
Self {
status: status_cfg,
prompt: PromptLine::builder(),
notifs: Notifications::builder(),
one_line: false,
above: false,
}
}
pub fn one_line(self) -> Self {
Self { one_line: true, ..self }
}
pub fn above(self) -> Self {
Self { above: true, ..self }
}
pub fn prompt(self, prompt: PromptLineBuilder) -> Self {
Self { prompt, ..self }
}
pub fn notifs(self, notifs: NotificationsOpts) -> Self {
Self { notifs, ..self }
}
}
impl Default for FooterWidgets {
fn default() -> Self {
Self {
status: StatusLine::builder(),
prompt: PromptLine::builder(),
notifs: Notifications::builder(),
one_line: false,
above: false,
}
}
}