Skip to main content

NotificationStore

Struct NotificationStore 

Source
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

Source

pub fn new() -> Self

Source

pub fn max_visible(&self) -> usize

How many the corner shows at once — notifications.max-visible.

Source

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.

Source

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.

Source

pub fn post( &self, level: NotificationLevel, text: impl Into<String>, ) -> NotificationId

Post a notification and return its id.

Source

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”.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn dismiss_all(&self) -> usize

Remove everything. :notifications-clear’s body.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Source

pub fn version(&self) -> u64

Bumped on every change. A renderer that finds it unchanged has nothing to repaint.

Source

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.

Trait Implementations§

Source§

impl Default for NotificationStore

Source§

fn default() -> NotificationStore

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more