Duat is a text editor with sane defaults, while still having an incredible amount of modularity, to the point where you can replace pretty much anything.
It is written and configured in Rust, through the use of a config crate. The configuration can then be reloaded without closing Duat, by being recompiled as requested.
I know that Rust isn’t really a scripting language, but I’ve worked really hard to make this API intuitive to use, whilst still maintaining all the safety and expressiveness that Rust is known for.
Rust is also known for long compile times, but for Duat, I’ve managed to reduce the vast majority of reloads to under ~1.3 seconds, with a large chunk taking less than 800 ms (on my relatively old mid range laptop).
Do keep in mind that this is a work in progress, so there might be bugs. Any feedback on features, bugs or requests is highly appreciated 🥰.
To install Duat, I am assuming that you have cargo installed on
your system, if you don’t, install it. If you are installing it
on Windows, you should additionlly follow the instructions that
they give you for installing C/C++ libraries through Visual
Studio.
On this section, I will be referring to duat’s configuration by
~/.config/duat/, but you should replace it with your operating
system’s config path. The same also applies to ~/.local/duat/.
Next, in order to run duat, you should add ~/.cargo/bin/ to your
$PATH variable. Alternatively, you can just add
~/.cargo/bin/duat, if you want to add just duat to the
$PATH. Now, you can install duat:
cargo install duatThat is the recommended version, however, if you wish to install the bleeding edge version, you can call this instead:
cargo install --git https://github.com/AhoyISki/duat --features git-depsWhen you first run duat, you will be prompted for the creation
of a new configuration crate in ~/.config/duat/ (unless it
already exists).
In the configuration’s src/lib.rs, there should be a
setup_duat! macro, which takes in a function with no parameters.
This function is the setup for duat, and it can be empty, which is the equivalent of the default configuration for Duat.
Here’s an example configuration buffer, which makes use of the
duat-kak crate, which is a plugin for Duat. This plugin, like
all others, is included without the duat_ prefix, so in the
config it is just kak.
setup_duat!(setup);
use duat::prelude::*;
fn setup() {
map::<Insert>("jk", "<Esc>");
opts::set(|opts| {
opts.wrap_lines = true;
opts.scrolloff.y = 5;
});
opts::set_lines(|opts| {
opts.align = std::fmt::Alignment::Right;
});
opts::set_status(|pa| {
let upper_mode = mode_name().map(|m| m.to_uppercase());
status!("[mode]{upper_mode}{Spacer}{name_txt} {sels_txt} {main_txt}")
});
hook::add::<ModeSwitched>(|_, (_, new)| {
match new {
"Insert" => cursor::set_main(CursorShape::SteadyBar),
_ => cursor::unset(),
}
Ok(())
});
form::set("mode", Form::dark_magenta());
}This configuration does the following things:
- Maps jk to esc in the
Insertmode; - Sets options for the
Buffer,LineNumbersandStatusLine - Adds hooks for mode changes in Duat, which change the shape of the cursor;
- Changes the style of the mode printed on the status line;
These are only some of the options available to configure Duat,
you can also add custom commands, place widgets around other
Widgets and windows, create Parsers that can track every
change on a Buffer, and many other things.
Duat also comes with a fully fledged text creation system, which significantly eases the creation of highly formatted text:
let infix = "text";
let text = txt!("This {infix} is [form1]colored and {Spacer} distant");In the example above, [form1] will change the style of the text
to the "form1" Form, while {Spacer} will place a spacer
in between the two parts of the text (See the status line in the
GIF, it uses spacers).
This macro works very similarly to the format! family of
macros, so you also have inlining, as you can see with the
{infix} part. All of this is, of course, checked at compile
time.
These issues asume that you are working with the --git-deps
version of duat
Try running the following:
duat --reload --cleanThis will update all dependencies of the config, potentially solving compatibility issues. The problem may also be with some plugin you installed.
This is an indication that your installed version of duat became
incompatible with that of your config. Rerun the installation
process and call duat --reload.
When you install duat, the default config crate will come with the following plugins:
duat-catppuccinis a just a simple colorscheme plugin, it adds the four flavors from the catppuccin colorscheme. You can pick between the four of them, you can apply its colors to otherForms and you can allow or disallow the colorscheme to set the background color.
It also comes with the following built-in plugins, which I will later on add the ability to disable:
duatmodeis the default mode for editing in Duat. It is heavily inspired by the Kakoune text editor in its design, with some light differences.duat-treesitterbrings tree-sitter to Duat in the form of syntax highlighting and indentation calculation, which can be used by Modes (such as those fromduat-kak) in order to give better feedback when editing buffers.duat-match-pairsadds matched parentheses highlighting to duat. Has some ntegration withduat-treesitter.duat-baseadds all of the default plugins that you see, like the line numbers, status line, prompt line, etc.
Duat provides a lot of features, trying to be as configurable as possible, here are some of the things that Duat is capable of:
- Completely custom modes, with full Vim style remapping;
- Completely custom widgets, with user created modes;
- Arbitrary concealment of text, and arbitrary ghost text;
- Custom hooks, whose activation is up to the creator;
- Custom commands, with customizable parameters supported by; Rust’s robust type system;
- Multi UI adaptability, although for now, only a terminal UI has been made;
- And many others still being planned;
Additionally, by choosing Rust as its configuration language, Duat also gains the following features:
- Complete type safety;
- A very functional programming language, with lots of native features;
- Cargo is the plugin manager;
These are the goals that have been accomplished or are on their way:
- Implement basic visual functionality (printing, scrolling, etc);
- Implement wrapping;
- Implement editing;
- Create a kak mode;
- Implement the use of multiple cursors;
- Implement a history system;
- Implement colors;
- Implement widgets and designated areas;
- Make all of these things easy to use on a public interface;
- Create a number line and a separator line;
- Create a status line;
- Buffer switching;
- Create a command creation interface and a command line;
- Add the ability to frame areas;
- Implement concealment;
- Implement hot reloading of configuration;
- Create a “normal editing” mode;
- Add the ability to create hooks;
- Create a more generalized plugin system;
- Implement incremental Regex searching;
- Implement tree-sitter;
- Add floating widgets, not tied to the session layout;
- Implement autocompletion lists;
- Create an LSP plugin;
- Create a vim mode;
︙
- Create an gui frontend;
An internal (and more detailed) TODO list, which might hard to
understand, can be found in TODO. This list will is
not a comprehensive roadmap, as I will ocasionally remove
entries from it, particularly those in the FOR NEXT UPDATE
section, when said update comes out.
NOTE: These are not set in stone, and may be done out of order.
I don’t know what your personal reasoning would be, but in my case, I really like Kakoune’s editing model, but was frustrated with the lack of some features, like folding, multiple buffer editing, the general barebonesness of the configuration, etc.
I know that Neovim has all of these features, and Helix supposedly tries to solve some of these issues. But I don’t really like either of their editing styles to be honest.
And so I thought, why not make my own text editor?
I thought, why not make a text editor that is as modular as possible, while still having a sensible default configuration? That I could modify however I wanted, and with a language that I love?
That’s why I decided to create Duat.
idk, cool sounding word that I got from Spelunky 2.