pub struct NotificationStore { /* private fields */ }Expand description
The live notifications, newest last.
Window-scoped rather than buffer-scoped, and that is the point: a notification exists precisely because you have moved on from whatever started the work. Tying it to a buffer would hide it in the buffer you are not looking at.
Implementations§
Source§impl NotificationStore
impl NotificationStore
pub fn new() -> Self
Sourcepub fn max_visible(&self) -> usize
pub fn max_visible(&self) -> usize
How many the corner shows at once — notifications.max-visible.
Sourcepub fn nerd_fonts(&self) -> bool
pub fn nerd_fonts(&self) -> bool
Whether icons use the Nerd Fonts palette — ui.nerd_fonts.
Read by name: the option is declared in lattice-host, which
this crate sits below. A store with no config uses the fallback
palette, which renders everywhere.
Sourcepub fn set_config(&self, config: Arc<ConfigRegistry>)
pub fn set_config(&self, config: Arc<ConfigRegistry>)
Give the store its config. Called by install; without one it
falls back to the compiled defaults.
Sourcepub fn post(
&self,
level: NotificationLevel,
text: impl Into<String>,
) -> NotificationId
pub fn post( &self, level: NotificationLevel, text: impl Into<String>, ) -> NotificationId
Post a notification and return its id.
Sourcepub fn post_with(
&self,
level: NotificationLevel,
text: impl Into<String>,
timeout: Option<Duration>,
) -> NotificationId
pub fn post_with( &self, level: NotificationLevel, text: impl Into<String>, timeout: Option<Duration>, ) -> NotificationId
Post with an explicit timeout — None for “until replaced or
dismissed”.
Sourcepub fn post_scoped(
&self,
level: NotificationLevel,
scope: Option<String>,
text: impl Into<String>,
) -> NotificationId
pub fn post_scoped( &self, level: NotificationLevel, scope: Option<String>, text: impl Into<String>, ) -> NotificationId
NC.2: post with a scope — where the work happened — at the level’s own timeout.
Sourcepub fn post_with_action(
&self,
level: NotificationLevel,
text: impl Into<String>,
action: NotificationAction,
) -> NotificationId
pub fn post_with_action( &self, level: NotificationLevel, text: impl Into<String>, action: NotificationAction, ) -> NotificationId
Post with an action attached — what <CR> runs on that row in
*notifications*.
The failure case is the one that needs it: a notification is one line and git’s stderr is not, so the notification says what broke and the action goes to where the rest is.
Sourcepub fn replace(
&self,
id: NotificationId,
level: NotificationLevel,
text: impl Into<String>,
timeout: Option<Duration>,
) -> bool
pub fn replace( &self, id: NotificationId, level: NotificationLevel, text: impl Into<String>, timeout: Option<Duration>, ) -> bool
Replace id’s content in place, keeping its position in the
stack.
This is what a long operation uses: post “fetching…” with no timeout, then replace with “fetched” on completion. Replacing rather than dismiss-and-post keeps the row from jumping to the bottom of the stack at the moment the user looks at it — and keeps two notifications for one operation from ever being visible at once.
Returns false if the notification is already gone (expired or
dismissed), in which case the caller’s completion is posted
fresh by Self::replace_or_post.
Sourcepub fn replace_or_post(
&self,
id: NotificationId,
level: NotificationLevel,
text: impl Into<String>,
timeout: Option<Duration>,
) -> NotificationId
pub fn replace_or_post( &self, id: NotificationId, level: NotificationLevel, text: impl Into<String>, timeout: Option<Duration>, ) -> NotificationId
Self::replace, falling back to a fresh post when the
original is gone.
The fallback is not defensive padding: a long fetch can outlive its own “started” notification’s timeout, and silently dropping the completion would reintroduce exactly the invisible-success bug the subsystem exists to fix.
Sourcepub fn dismiss(&self, id: NotificationId) -> bool
pub fn dismiss(&self, id: NotificationId) -> bool
Remove one notification. Idempotent — dismissing something already gone is not an error, because expiry and an explicit dismiss race by construction.
Sourcepub fn dismiss_all(&self) -> usize
pub fn dismiss_all(&self) -> usize
Remove everything. :notifications-clear’s body.
Sourcepub fn all(&self) -> Vec<Notification>
pub fn all(&self) -> Vec<Notification>
Every live notification, oldest first — including ones queued
behind MAX_VISIBLE.
Renderers want Self::visible; this is for tests and for
:notifications, which should show what is waiting.
Sourcepub fn visible(&self) -> Vec<Notification>
pub fn visible(&self) -> Vec<Notification>
The notifications a renderer should paint, oldest first, at
most MAX_VISIBLE of them.
§5.9.9: “excess queued”. The ones shown are the oldest, and that ordering is a correctness requirement rather than a preference. Showing the newest instead — which this did on its first pass — means an early notification in a burst can run out its timeout while invisible and be dismissed having never been seen. A notification nobody saw is the bug this subsystem exists to remove, arrived at from the other end.
Its companion guarantee is in [Self::schedule_expiry]: a
queued notification’s clock does not start until it becomes
visible.
Sourcepub fn queued(&self) -> usize
pub fn queued(&self) -> usize
How many are waiting behind the visible ones. A renderer shows this as a “+N more” line rather than dropping them silently.
pub fn is_empty(&self) -> bool
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
Bumped on every change. A renderer that finds it unchanged has nothing to repaint.
Sourcepub fn set_expiry_channel(
&self,
bus: InboundBus<NotifyInbound>,
runtime: Handle,
)
pub fn set_expiry_channel( &self, bus: InboundBus<NotifyInbound>, runtime: Handle, )
Give the store the channel expiry rides on. Called by
install; a store without one records timeouts but never
fires them.