Common StatusLine parts
The most relevant parts for pretty much every StatusLine
are the following.
Formatted status parts:
file_fmt
: Prints theFile
's name and some info about it's newness.- Uses the forms
file
,file.new
,file.new.scratch
andfile.unsaved
- Uses the forms
mode_fmt
: The lowercased name of theMode
, e.g. "insert", "normal.- Uses the form
mode
- Uses the form
main_fmt
: Prints the main selection's column and line, and the number of lines. 1 indexed.- Uses the forms
coord
andseparator
- Uses the forms
sels_fmt
: Prints the number of selections.- Uses the form
selections
;
- Uses the form
cur_map_fmt
: 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::*; status!("{file_fmt}{Spacer}{mode_fmt} {sels_fmt} {main_fmt}"); }
If you want a one sided StatusLine
:
#![allow(unused)] fn main() { use duat::prelude::*; status!("{Spacer}{file_fmt} {mode_fmt} {sels_fmt} {main_fmt}"); }
Customized main_fmt
:
#![allow(unused)] fn main() { use duat::prelude::*; status!( "{file_fmt}{Spacer} {mode_fmt} {sels_fmt}[coord]c{main_col} l{main_line}[separator]|[coord]{}", |file: &File| file.text().len().line() ); }
Customized file_fmt
:
#![allow(unused)] fn main() { use duat::prelude::*; fn file_fmt(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() } status!("{file_fmt}{Spacer}{mode_fmt} {sels_fmt} {main_fmt}"); }