Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Status on files and on window

In these snippets, you might have noticed that I'm mapping all StatusLines, not just some of them. So how would one map only the StatusLines belonging to files then? Or depending on other factors?

You could just replace all hooks for Files and WindowCreated, but that is rather tedious and verbose. Instead, you can just do the following:

#![allow(unused)]
fn main() {
use duat::prelude::*;
hook::add::<StatusLine<Ui>>(|_, (cfg, builder)| {
    if builder.file().is_some() {
        cfg.fmt(status!("{Spacer}{name_txt}"))
    } else {
        cfg
    }
});
}

The snippet above will only remap the StatusLine when it is pushe onto a File.

You can go even further, by, e.g. checking on the filetype:

#![allow(unused)]
fn main() {
use duat::prelude::*;
hook::add::<StatusLine<Ui>>(|pa, (cfg, builder)| {
    if let Some(file) = builder.file() {
        if let Some("rust") = file.filetype(pa)
            && file.read(pa).path().contains(".config/duat")
        {
            cfg.fmt(status!("[config] {Spacer}{name_txt}"))
        } else {
            cfg.fmt(status!("{Spacer}{name_txt}"))
        }
    } else {
        cfg
    }
});
}