Skip to main content

Crate charmed_wasm

Crate charmed_wasm 

Source
Expand description

§charmed-wasm

Terminal UI components for the web, compiled to WebAssembly.

This crate provides WebAssembly bindings for the charmed_rust library, allowing you to use lipgloss styling in web applications.

§Role in charmed_rust

charmed-wasm is the web-facing bridge for the ecosystem:

  • lipgloss is re-exported with WASM-friendly APIs.
  • It enables sharing the same styling model between terminal and web UI.

§Quick Start (JavaScript)

import init, { newStyle, joinVertical, Position } from 'charmed-wasm';

async function main() {
    await init();

    const style = newStyle()
        .foreground("#ff00ff")
        .background("#1a1a1a")
        .bold()
        .padding(1, 2, 1, 2);

    const rendered = style.render("Hello, World!");
    document.body.innerHTML = `<pre>${rendered}</pre>`;
}

main();

§Available APIs

§Styling (from lipgloss)

  • newStyle() - Create a new style builder
  • JsStyle - Chainable style configuration
  • JsColor - Color utilities

§Layout

  • joinHorizontal(position, items) - Join strings horizontally
  • joinVertical(position, items) - Join strings vertically
  • place(width, height, hPos, vPos, content) - Place content in a container

§Utilities

  • stringWidth(s) - Get visible width of a string
  • stringHeight(s) - Get height (line count) of a string
  • borderPresets() - Get available border preset names

Structs§

JsColor
JavaScript-friendly wrapper for Color.
JsStyle
JavaScript-friendly wrapper for Style.

Functions§

border_presets
Available border preset names.
init
Initialize the lipgloss WASM module.
is_ready
Check if the module is properly initialized.
join_horizontal
Join multiple strings horizontally.
join_vertical
Join multiple strings vertically.
new_style
Create a new style builder.
place
Place content at a position within a container.
string_height
Get the height (number of lines) of a string.
string_width
Get the visible width of a string (excluding escape codes).
version
Module version information.