Crate duat

source ·
Expand description

Duat is a text editor built with extensibility and performance in mind, while still having very sensible defaults. It is configured in Rust, by use of a crate. The choice of Rust for configuration grants several benefits:

  • Safe code by default;
  • Top quality code checking through rust-analyzer;
  • Cargo is the plugin manager;
  • The vast expressiveness of the Rust type system;
  • Rust is just a fun language to code in;

The use of Rust, to some, may seem like a mistake, since it is not a “beginner friendly language”, but Duat is developed with ease of configuration in mind, so an average configuration file won’t be as verbose as a lot of Rust code, while maintaining good levels of readability:

use duat::prelude::*;
use duat_kak::{KeyMap, Mode, OnModeChange};

run! {
    print::wrap_on_width();

    hooks::remove_group("FileWidgets");
    hooks::add::<OnFileOpen>(|builder| {
        builder.push::<VertRule>();
        builder.push::<LineNumbers>();
    });

    hooks::remove_group("WindowWidgets");
    hooks::add::<OnWindowOpen>(|builder| {
        let status = status!(
            [File] { File::name } " "
            { KeyMap::mode_fmt } " "
            selections_fmt " " main_fmt
        );

        let (child, _) = builder.push_cfg(status);
        builder.push_cfg_to(CommandLine::cfg().left_with_percent(30), child);
    });

    input::set(KeyMap::new());

    hooks::add::<OnModeChange>(|(_, new)| match new {
        Mode::Insert => cursor::set_main(CursorShape::SteadyBar),
        _ => cursor::set_main(CursorShape::SteadyBlock)
    });

    forms::set("Mode", Form::new().dark_magenta());
}

This configuration does the following things:

  • Changes the wrapping;
  • Removes the hook group “FileWidgets”;
  • Pushes a vertical rule and line numbers to every file;
  • Removes the hook group “WindowWidgets”;
  • Pushes a status line and command line to the bottom of the screen;
  • Changes the input method to a Kakoune inspired duat-kak;
  • Adds hooks for mode changes in said input method;
  • Changes the style of the mode printed on the status line;

These are some of the configurations available for usage in Duat, and one might perceive how these can be tinkered with to change a lot of things within Duat. For example, the usage of hooks to push widgets to files means that you could do this:

hooks::add::<OnFileOpen>(|builder| {
    builder.push::<VertRule>();
    builder.push::<LineNumbers>();
    builder.push_cfg(LineNumbers::cfg().on_the_right());
    builder.push_cfg(LineNumbers::cfg().on_the_right());
});

Now, every file will open with two lines of numbers, one on each side. Would you ever want to do this? …No, not really, but it shows how configurable Duat can be.

Duat also comes with a fully fledged text styling system, which significantly eases the creation of widgets:

let styled text = text!([MyForm] "Waow it's my text" [] "not anymore 😢");

In this example, I’m using the “MyForm” form in order to style the text, while [] reverts back to the “Default” form.

With the tags provided by Duat, you can also change the alignment, conceal text, add ghost text that can’t be interacted with, and also add buttons that take mouse input (in the future). These other tags are particularly useful when one wants to style the file, where multiple plugins may insert tags that do not interact with eachother.

Duat also has a simple command system, that lets you add commands with arguments supported by Rust’s type system:

let callers = ["collapse-command-line", "ccl"];
commands::add_for_widget::<CommandLine>(callers, |command_line, area| {
    area.change_constraintk
})

Re-exports§

  • pub use setup::layout_hooks;
  • pub use setup::run_duat;

Modules§

  • Utilities for addition and execution of commands Creation and execution of commands.
  • Control functions that are prebuilt with Duat
  • Functions to alter the cursors of Duat
  • Functions to alter the Forms of Duat
  • Hook utilities
  • Options concerning the [File]’s [InputMethod]
  • The prelude of Duat, imports most of what a configuration needs
  • Options concerning the printing of Files
  • The widgets defined by Duat, [StatusLine] and [CommandLine]

Macros§

  • Macro responsible for running Duat

Type Aliases§