-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
517 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "tui-qrcode" | ||
version = "0.1.0" | ||
description = "A Ratatui widget for displaying QR codes in the terminal" | ||
documentation = "https://docs.rs/tui-qrcode" | ||
|
||
authors.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
categories.workspace = true | ||
keywords.workspace = true | ||
|
||
[dependencies] | ||
color-eyre.workspace = true | ||
qrcode = { version = "0.14.1", default-features = false } | ||
ratatui.workspace = true | ||
|
||
[dev-dependencies] | ||
ratatui = { workspace = true, features = ["crossterm"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# TUI QR Code | ||
|
||
<!-- cargo-rdme start --> | ||
|
||
TUI QR Code is a library for rendering QR codes in a terminal using the [Ratatui] crate. | ||
|
||
[![Crate badge]][tui-qrcode] | ||
[![Docs.rs Badge]][API Docs] | ||
[![Deps.rs Badge]][Dependency Status] | ||
[![License Badge]](./LICENSE-MIT) | ||
[![Discord Badge]][Ratatui Discord] | ||
|
||
[GitHub Repository] · [API Docs] · [Examples] · [Changelog] · [Contributing] | ||
|
||
 | ||
|
||
## 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. | ||
|
||
```shell | ||
cargo add qrcode tui-qrcode --no-default-features | ||
``` | ||
|
||
## Example | ||
|
||
This example can be found in the `examples` directory of the repository. | ||
|
||
```rust | ||
use qrcode::QrCode; | ||
use ratatui::{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: | ||
|
||
```text | ||
█████████████████████████████████ | ||
█████████████████████████████████ | ||
████ ▄▄▄▄▄ █▄ ▄▄▄ ████ ▄▄▄▄▄ ████ | ||
████ █ █ █▄▄▄█▀▄██ █ █ █ ████ | ||
████ █▄▄▄█ █▀ ▄▀ ███ █▄▄▄█ ████ | ||
████▄▄▄▄▄▄▄█▄▀▄█ ▀▄▀ █▄▄▄▄▄▄▄████ | ||
████ █▄▀▀▀▄▄▀▄▄ ▄█▀▄█▀ █▀▄▀ ████ | ||
██████▀█ ▄▀▄▄▀▀ ▄ ▄█ ▄▄█ ▄█▄████ | ||
████▄▀▀▀▄▄▄▄▀█▄▄█ ▀ ▀ ▀███▀ ████ | ||
████▄▄ ▀█▄▄▀▄▄ ▄█▀█▄▀█▄▀▀ ▄█▄████ | ||
████▄▄█▄██▄█ ▄▀▄ ▄█ ▄▄▄ ██▄▀████ | ||
████ ▄▄▄▄▄ █▄▄▄▀ ▄ ▀ █▄█ ███ ████ | ||
████ █ █ ██ ███ ▄▄ ▄▄ █▀ ▄████ | ||
████ █▄▄▄█ █▄▀ ▄█▀█▀ ▄█ ▄█▄▄████ | ||
████▄▄▄▄▄▄▄█▄▄█▄▄▄██▄█▄██▄██▄████ | ||
█████████████████████████████████ | ||
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | ||
``` | ||
|
||
[Ratatui]: https://crates.io/crates/ratatui | ||
[Crate badge]: https://img.shields.io/crates/v/tui-qrcode.svg?style=for-the-badge | ||
[tui-qrcode]: https://crates.io/crates/tui-qrcode | ||
[Docs.rs Badge]: https://img.shields.io/badge/docs.rs-tui--qrcode-blue?style=for-the-badge | ||
[API Docs]: https://docs.rs/tui-qrcode | ||
[Deps.rs Badge]: https://deps.rs/repo/github/joshka/tui-qrcode/status.svg?style=for-the-badge | ||
[Dependency Status]: https://deps.rs/repo/github/joshka/tui-qrcode | ||
[License Badge]: https://img.shields.io/crates/l/tui-qrcode?style=for-the-badge | ||
[Discord Badge]: | ||
https://img.shields.io/discord/1070692720437383208?label=ratatui+discord&logo=discord&style=for-the-badge | ||
[Ratatui Discord]: https://discord.gg/pMCEU9hNEj | ||
[GitHub Repository]: https://github.com/joshka/tui-widgets | ||
[Examples]: https://github.com/joshka/tui-widgets/tree/main/tui-qrcode/examples | ||
[Changelog]: https://github.com/joshka/tui-widgets/blob/main/tui-qrcode/CHANGELOG.md | ||
[Contributing]: https://github.com/joshka/tui-widgets/blob/main/CONTRIBUTING.md | ||
|
||
<!-- cargo-rdme end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use qrcode::QrCode; | ||
use ratatui::{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()); | ||
} |
Oops, something went wrong.