Common StatusLine parts
The most relevant parts for pretty much every StatusLine
are the following.
Formatted status parts:
name_txt
: Prints theFile
's name and some info about it's newness.- Uses the forms
file
,file.new
,file.new.scratch
andfile.unsaved
. mode_txt
: The lowercased name of theMode
, e.g. "insert", "normal".- Uses the form
mode
.
- Uses the form
main_txt
: Prints the main selection's column and line, and the number of lines. 1 indexed.- Uses the forms
coord
andseparator
.
- Uses the forms
sels_txt
: Prints the number of selections.- Uses the form
selections
;
- Uses the form
cur_map_txt
: Prints the keys being mapped.- Uses the forms
key
andkey.special
- Uses the forms
Unformatted status parts:
main_byte
,main_char
,main_line
,main_col
: Parts of the main cursor.mode_name
: The raw type name of the mode. Could look something likePrompt<IncSearcher<SearchFwd>, Ui>, Ui>
.selections
: The number of selections, no formatting.last_key
: The last key that was typed. Useful for asciinema demonstrations.
Other:
Spacer
: This isn't actually aStatusPart
, it's aTag
that can go in anyText
, which includes theStatusLine
's.AlignLeft
,AlignCenter
,AlignRight
: TheseTag
s (like all others) can also be used in theStatusLine
. However, do note that they are applied line wise. Using any of them will shift the whole line's alignment. For that reason, aSpacer
should generally be preferred.- Forms like
[file]
. Any form can be placed within those braces, and they are all evaluated at compile time.
Some examples
This is the default:
#![allow(unused)] fn main() { use duat::prelude::*; hook::add::<StatusLine<Ui>>(|pa, (cfg, _)| { cfg.fmt(status!("{name_txt}{Spacer}{} {sels_txt} {main_txt}", mode_txt(pa))) }); }
If you want a one sided StatusLine
, you can do this:
#![allow(unused)] fn main() { use duat::prelude::*; hook::add::<StatusLine<Ui>>(|pa, (cfg, _)| { cfg.fmt(status!("{Spacer}{name_txt} {} {sels_txt} {main_txt}", mode_txt(pa))) }); }
Customized main_txt
:
#![allow(unused)] fn main() { use duat::prelude::*; hook::add::<StatusLine<Ui>>(|pa, (cfg, _)| { cfg.fmt(status!( "{name_txt}{Spacer}{} {sels_txt} [coord]c{main_col} l{main_line}[separator]|[coord]{}", mode_txt(pa), |file: &File| file.text().len().line() )) }); }
Customized name_txt
:
#![allow(unused)] fn main() { use duat::prelude::*; fn name_txt(file: &File) -> Text { let mut b = Text::builder(); if let Some(name) = file.name_set() { b.push(txt!("[file]{name}")); if !file.exists() { b.push(txt!("[file.new][[new file]]")); } else if file.text().has_unsaved_changes() { b.push(txt!("[file.unsaved][[has changes]]")); } if let Some("rust") = file.filetype() { b.push(txt!("[[🦀]]")); } } else { b.push(txt!("[file.new.scratch]?!?!?!")); } b.build() } hook::add::<StatusLine<Ui>>(|pa, (cfg, _)| { cfg.fmt(status!("{name_txt}{Spacer}{} {sels_txt} {main_txt}", mode_txt(pa))) }); }