WebRust 1.1.0 — Python-like Rust for the Browser Terminal
WebRust brings Python-style ergonomics to Rust, with a zero-setup web UI: styled printing, validated inputs, rich text (with LaTeX), tables/charts, and now canvas-powered turtle graphics. It’s great for teaching, demos, dashboards, and quick interactive tools—without giving up Rust’s type safety.
✨ Highlights
- One macro to start:
#[gui(...)]spins up the UI automatically. - Fluent styled printing:
print("...").color("crimson").radius(8).at(x, y). - Shared coordinate system:
coord("css" | "cartesian")applies to text and turtle. - Absolute placement with
.at(x, y)and screen helpersCW/CH. - Inline styling
@(bold, color:navy)and LaTeX$( ... ). - Inputs with validation shown inline in the terminal.
- Tables & charts (ECharts) for quick dashboards.
- Turtle graphics: multiple turtles, animation,
penup/pendown, CSS colors.
📦 Install
# Cargo.toml
[]
= "1.1.0"
🚀 Quick Start
use *;
Run:
🧭 Coordinates & Layout
-
coord("css")(default): origin top-left, +x→right, +y→down.
In this mode,.at(x, y)supports right anchoring: ifxis negative, it means “from the right” (e.g..at(-20.0, 8.0)→ 20px from right edge). -
coord("cartesian"): origin center, +x→right, +y→up.
Screen helpers:
CW,CH— layout width/height used by the terminal (exported asLazyLock<u32>).
Example:
coord;
// top-center banner
println
.background
.radius
.at;
// two columns
println.width.align;
println.width.align;
🖍️ Styled Printing
Chain CSS-like styles:
println
.weight
.style // solid | dashed | dotted | double
.radius
.color // border color
.background
.align // left | center | right | justify
.at; // absolute placement
Inline text syntax:
- Colors & decorations:
@(red, bold, italic, underline, strike) - Custom CSS style tokens:
@(color:crimson, background:mintcream) - LaTeX:
$(x = \frac{-b \pm \sqrt{b^2-4ac}}{2a})(auto inline/display)
⌨️ Inputs
let age: i32 = input;
let price: f64 = input;
let ready: bool = input;
println;
Inputs render inline in the terminal; values are validated and echoed.
📊 Tables & Charts (Optional)
Build simple tables and ECharts-powered charts from your data structures.
(If you’ve used earlier versions, your existing code continues to work.)
🐢 Turtle Graphics (NEW)
Draw animated scenes on a canvas inside the terminal. Multiple turtles can move independently. The turtle system respects the global coord("css" | "cartesian").
Example: mixed text + drawing
use PI;
use *;
Turtle API (overview)
setColor(name: &str)— any CSS color name or hex.setPenSize(px: f64)speed(px_per_s: f64)— affectsforwardanimation speed.angle(deg: f64)— absolute heading (0° = east, CCW positive).setPos(x, y)— jump without drawing.forward(d)— move with drawing if pen is down.line(x1, y1, x2, y2)— immediate segment.point()— filled point at current position.circle(r)— outline circle centered at current position.penup()/pendown()— toggle drawing while moving.
🧪 Example: Playground
🧩 Version 1.1.0 — What’s New
- Unified coordinate system:
coord("css" | "cartesian")affects both text and turtle. .at(x, y)everywhere: one method for absolute placement; in CSS mode, negativex= from right edge.- Turtle graphics module:
- Multi-turtle support with independent queues.
- New
penup()/pendown()for gapless rays, dotted paths, etc. - CSS color names and hex strings for
setColor(...).
- CW/CH integration across I/O and graphics for consistent sizing.
- Internal performance & robustness improvements.
🖥️ Platform Notes
- On Windows,
CW/CHdefault to half the primary screen size (PowerShell detection, with a fallback to 800×600). - Runs in the browser automatically; assets live under
webrust/static/(e.g.,style.css,script.js).
📚 Examples
📜 License
MIT. See LICENSE for details.
🧭 Contributing
Issues and PRs are welcome! If you’re adding features, keep the API Python-friendly, chainable, and consistent with the shared coordinate model.