tui-qrcode

Crates.iotui-qrcode
lib.rstui-qrcode
version
sourcesrc
created_at2025-01-23 03:40:56.992174+00
updated_at2025-03-02 02:44:24.92966+00
descriptionA Ratatui widget for displaying QR codes in the terminal
homepage
repositoryhttps://github.com/joshka/tui-widgets
max_upload_size
id1527439
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Josh McKinney (joshka)

documentation

https://docs.rs/tui-qrcode

README

TUI QR Code

TUI QR Code is a library for rendering QR codes in a terminal using the Ratatui crate.

Crate badge Docs.rs Badge Deps.rs Badge License Badge Discord Badge

GitHub Repository · API Docs · Examples · Changelog · Contributing

Demo

Usage

Add qrcode and tui-qrcode to your Cargo.toml. You can disable the default features of qrcode as we don't need the code which renders the QR code to an image.

cargo add qrcode tui-qrcode --no-default-features

Example

This example can be found in the examples directory of the repository.

use qrcode::QrCode;
use ratatui_core::{crossterm::event, DefaultTerminal, Frame};
use tui_qrcode::{Colors, QrCodeWidget};

fn main() -> color_eyre::Result<()> {
    color_eyre::install()?;
    let terminal = ratatui::init();
    let result = run(terminal);
    ratatui::restore();
    result
}

fn run(mut terminal: DefaultTerminal) -> color_eyre::Result<()> {
    loop {
        terminal.draw(render)?;
        if matches!(event::read()?, event::Event::Key(_)) {
            break Ok(());
        }
    }
}

fn render(frame: &mut Frame) {
    let qr_code = QrCode::new("https://ratatui.rs").expect("failed to create QR code");
    let widget = QrCodeWidget::new(qr_code).colors(Colors::Inverted);
    frame.render_widget(widget, frame.area());
}

Renders the following QR code:

█████████████████████████████████
█████████████████████████████████
████ ▄▄▄▄▄ █▄ ▄▄▄ ████ ▄▄▄▄▄ ████
████ █   █ █▄▄▄█▀▄██ █ █   █ ████
████ █▄▄▄█ █▀   ▄▀ ███ █▄▄▄█ ████
████▄▄▄▄▄▄▄█▄▀▄█ ▀▄▀ █▄▄▄▄▄▄▄████
████ █▄▀▀▀▄▄▀▄▄  ▄█▀▄█▀ █▀▄▀ ████
██████▀█  ▄▀▄▄▀▀ ▄ ▄█ ▄▄█ ▄█▄████
████▄▀▀▀▄▄▄▄▀█▄▄█  ▀ ▀ ▀███▀ ████
████▄▄ ▀█▄▄▀▄▄ ▄█▀█▄▀█▄▀▀ ▄█▄████
████▄▄█▄██▄█ ▄▀▄ ▄█  ▄▄▄ ██▄▀████
████ ▄▄▄▄▄ █▄▄▄▀ ▄ ▀ █▄█ ███ ████
████ █   █ ██ ███  ▄▄ ▄▄ █▀ ▄████
████ █▄▄▄█ █▄▀ ▄█▀█▀ ▄█  ▄█▄▄████
████▄▄▄▄▄▄▄█▄▄█▄▄▄██▄█▄██▄██▄████
█████████████████████████████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Commit count: 360

cargo fmt