Skip to main content

Crate scopekit

Crate scopekit 

Source
Expand description

§scopekit

Build ratatui viewers with a live wgpu view: a medical image, a globe, a plot. The same app runs in two places:

  • in any terminal: the view is rendered offscreen on the GPU and shown with the kitty, iTerm2 or sixel graphics protocol, or as coloured half blocks where the terminal has none;
  • in its own window: ratatui-wgpu draws the text, and the view is composited onto the same surface in the same frame, at full resolution.

You write the text UI once with ratatui, handle crossterm events once (the window translates its input into the same types), and implement one trait for the GPU view. scopekit does the rest: the terminal graphics protocols, the window, fonts, colours, the mouse, animation ticks and read-back.

                   ┌──────────── scopekit::App ─────────────┐
                   │ draw(frame, slot)  event(ev)  tick()    │
                   └───────────────┬─────────────────────────┘
          terminal (crossterm)     │     window (winit + ratatui-wgpu)
  ratatui text ──► terminal cells  │  ratatui text ──► glyph texture ─┐
  GpuView ──► offscreen texture    │  GpuView ─────────────────────── ┼─► surface
          ──► kitty/iTerm2/sixel/  │              (same device, same   │
              half blocks          │               frame, no read-back)┘

It powers dicomscope-tui, the DICOM viewer of hl7v2. Start with HOWTO.md; examples/plasma.rs is a complete app in one file:

cargo run -p scopekit --example plasma             # in this terminal
cargo run -p scopekit --example plasma -- --window # in a window

Features: terminal and window, both on by default. Leave one out to drop its dependencies. Built on wgpu 30, ratatui 0.30, ratatui-wgpu 0.6 and ratatui-image 11; scopekit re-exports wgpu, ratatui and crossterm so apps use the same versions.

Re-exports§

pub use config::Backend;
pub use config::Config;
pub use config::Mode;
pub use config::Palette;
pub use config::Protocol;
pub use gesture::DragAction;
pub use gesture::Gesture;
pub use gesture::GestureKind;
pub use gesture::GestureType;
pub use gesture::Input;
pub use gesture::ScrollAction;
pub use gpu::render_to_rgba;
pub use gpu::share;
pub use gpu::Gpu;
pub use gpu::GpuView;
pub use gpu::PixelRect;
pub use gpu::SharedView;
pub use gpu::Target;
pub use gpu::Views;
pub use crossterm;
pub use ratatui;
pub use wgpu;

Modules§

clipboard
The system clipboard: text and images (feature clipboard).
config
Everything a scopekit app can configure, in one struct with sensible defaults. Build it with struct update syntax:
gesture
Mouse, trackpad and touch input as gestures on GPU views: tap, double tap, long press, pan, zoom and rotate, with bindings in Input.
gpu
The GPU side: the GpuView an app implements, the device it gets, and offscreen rendering with read-back for terminals and exports.
terminal
Terminal mode: ratatui on crossterm, each GPU view rendered offscreen and sent with the terminal’s graphics protocol.
window
Window mode: the same app in a native window. ratatui-wgpu draws the text into a texture; the Compositor puts it on the window surface and then lets each placed GPU view draw into its region, on the same device, in the same frame, at the window’s full resolution.

Structs§

Help
What an app contributes to the help box: its keys, and what each gesture does in its views. Return it from App::help.
ViewSlot
Where the GPU views go this frame, and facts about the screen an app needs to map the mouse into a view.
Waker
Asks the running app for a redraw from any thread: an emulator’s serial reader, a build, a network client. Cheap to clone; wake-ups that arrive faster than frames are drawn coalesce.

Enums§

Flow
What to do after an event.

Traits§

App
A scopekit application.

Functions§

run
Run app as configured: in the terminal or in a window. views are the app’s GPU views by name (see share and Views); Views::new() for a text-only app.