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

The prelude module

At the top of your crate, you should be able to find this:

#![allow(unused)]
fn main() {
setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    // The stuff inside your setup...
}
}

This will import everything in the prelude module of duat. This should have everything you will need in order to configure Duat, not including things from other crates that you may want to import (such as plugins).

When calling use duat::prelude::*, most imported things will be in the form of modules, like this:

#![allow(unused)]
fn main() {
use duat::prelude::*;
use duat::print;
}

This is importing the print module, as opposed to importing its items directly, like this:

#![allow(unused)]
fn main() {
use duat::prelude::*;
use duat::print::*;
}

This means that, for most options, their path is made up of a {module}::{function} combo. So the usual setup function should look something like this:

#![allow(unused)]
fn main() {
mod duat_kak {
    use duat::{prelude::{*, mode::KeyEvent}};
    #[derive(Clone)]
    pub struct Insert;
    impl Mode<Ui> for Insert {
        type Widget = File;
        fn send_key(&mut self, _: &mut Pass, _: KeyEvent, _: Handle<File>) {
            todo!();
        }
    }
    #[derive(Default)]
    pub struct Kak;
    impl duat_core::Plugin<Ui> for Kak {
        fn plug(self, _: &duat_core::Plugins<Ui>) {}
    }
}
setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    plug(duat_kak::Kak::default());

    print::wrap_at(150);
    print::trailing_new_line('󱁐');
    
    form::set("caret.main", Form::yellow());
    
    cmd::add!("set-rel-lines", |pa, ln: cmd::Handles<LineNumbers<Ui>>| {
        ln.on_flags(pa, |pa, handle| {
            handle.write(pa).rel_abs();
        });
        
        Ok(Some(txt!("Lines were set to [a]relative absolute").build()))
    });
    
    map::<duat_kak::Insert>("jk", "<Esc>:w<Enter>");
}
}

The exceptions to this are the map, alias and plug functions, the setup_duat! macro. These items are imported directly.

The following chapters should give a quick overview of these items imported from the prelude module.