Skip to main content

Crate qframe

Crate qframe 

Source
Expand description

Quvyta framework: build beautiful terminal applications.

quvyta-framework is a framework for building terminal applications in Rust. It was started to design Quvyta’s own applications and has grown into an open-source framework anyone can use.

An application gives the framework three things: language files, theme files (with icon files), and components built in code. A default theme, icon set and English and Turkish strings are embedded, so an application runs without any files.

An application is data, a view that draws it and an update that changes it:

use qframe::prelude::*;

#[derive(Default)]
struct Counter {
    count: i32,
}

#[derive(Clone)]
enum Msg {
    Increment,
}

impl App for Counter {
    type Msg = Msg;

    fn update(&mut self, msg: Msg) -> Command<Msg> {
        match msg {
            Msg::Increment => self.count += 1,
        }
        Command::none()
    }

    fn view(&self, ui: &mut View<'_, Msg>) {
        ui.column(|ui| {
            ui.add(Text::new(format!("Count: {}", self.count)));
            ui.add(Button::new("Add one").variant("primary").on_press(Msg::Increment));
        })
        .gap(1);
    }
}

// Tests drive the application without a terminal; a program calls
// `Runtime::new(Counter::default()).run()` in `main` instead.
let mut app = Harness::new(Counter::default(), 30, 4);
app.press("tab").press("enter");
assert!(app.screen().contains("Count: 1"));

Modules:

  • prelude — the names nearly every application uses.
  • runtime — the App trait, commands, the terminal runtime, background tasks and the test harness.
  • widget — the widget model, the view builder and layout.
  • widgets — ready-made widgets.
  • theme — colour tokens, motion values and CSS-like style rules; style and color hold the resolved styles and colours widgets paint with.
  • icons — icon sets with Nerd Font, Unicode and ASCII glyphs; animation — one-cell animations defined in icon sets and themes.
  • i18n — locales, plural forms and the t! macro.
  • keymap — named actions bound to key chords; event — key, mouse and paste events.
  • env — the loaded theme, icons, language and keymap an application runs with.
  • geometry and text — rectangles and padding in cells, and text measured in cells.
  • desktop — which program opens a file: the desktop’s shared MIME database, the installed programs’ .desktop files and the person’s defaults, read without drawing.
  • date — calendar dates, times of day and the local time zone offset.
  • uptime — the monotonic clocks that tell time awake from time the machine slept.
  • motion — easing, moving values and cell-stepped progress.
  • router — page navigation.
  • storage — settings saved as TOML in the platform config directory, checked against a schema and optionally repaired; the config and data folders, atomic writes and the one-instance lock every application needs around its own files.
  • document — an application’s own data file: a schema’d TOML document that holds arrays of tables and is never repaired behind the application’s back.

Every loader reports problems as diagnostics::Diagnostics with file, line and column instead of failing, and built-in defaults are always available.

Modules§

animation
One-cell animations: an ordered list of frames, each with a glyph per glyph mode and an optional colour, played at a theme or literal frame time.
color
Colours: parsing, blending, contrast and perceptual distance, and reduction to the 256- and 16-colour palettes for terminals without 24-bit colour.
date
Calendar dates in the proleptic Gregorian calendar, times of day, and the two together.
desktop
Which programs open a file, read from the desktop’s own databases, and starting one of them.
diagnostics
Problems found while loading theme, icon, locale and keymap files.
document
An application’s own data file: a TOML document with a declared shape, which can hold arrays of tables and is never repaired behind the application’s back.
env
The environment widgets draw in: active theme, icons, language, keymap and colour depth, together with everything a settings screen needs to list the alternatives.
event
Input events delivered to widgets.
geometry
Cell geometry: rectangles, sizes and padding.
graphics
Which way the terminal can show a picture: the Graphics an Env reports, and the rules that decide it.
i18n
Localisation: locale files, plural forms, system language detection and t!.
icons
Icon sets: every icon has a Nerd Font, a Unicode and an ASCII glyph, and the terminal’s capabilities decide which one is drawn.
keymap
Keymaps: named actions bound to key chords, overridable from files.
motion
Motion: easing, values that move over time, and cell-stepped progress.
prelude
The names almost every application uses: use qframe::prelude::*;.
router
Page navigation as a stack.
runtime
Running applications: the App trait, Commands, the terminal Runtime and the test Harness.
storage
Settings storage: an application’s preferences in a TOML file in the platform config directory.
style
Drawing styles: what a cell looks like, and theme styles resolved for one frame.
text
Measuring text in terminal cells: width, truncation with an ellipsis at the end or in the middle, and word wrapping.
theme
Themes: colour tokens, motion timing, typography roles and CSS-like style rules.
uptime
Two monotonic clocks read together, so an application can tell time spent working from time the machine spent asleep.
widget
The widget model: the Widget trait, view nodes, layout properties and the contexts widgets measure, paint and handle events with.
widgets
Ready-made widgets. Every one takes its look from the theme and works with keyboard and mouse.

Macros§

t
Translates a key with the active translator.