graphix-shell 0.1.17

A dataflow language for UIs and network programming
Documentation

Graphix

A reactive dataflow programming language for building user interfaces and network applications.

Graphix TUI Example

What is Graphix?

Graphix is a statically-typed functional programming language that compiles to reactive dataflow graphs. Unlike traditional imperative languages, Graphix programs automatically propagate changes through dependencies—when a value updates, all computations that depend on it update automatically.

This makes Graphix particularly well-suited for:

  • User Interfaces - Rich, interactive applications
  • Network Programming - Reactive data streams with netidx
  • Real-time Data Processing - Automatic updates when data changes

Key Features

  • Reactive at the Language Level - Changes propagate automatically through the dataflow graph
  • Strong Static Typing - Type inference with structural type discipline
  • Parametric Polymorphism - Generic types with constraints
  • Algebraic Data Types - Structs, variants, and pattern matching
  • First-Class Functions - Closures and higher-order functions
  • Comprehensive TUI Library - Built on ratatui with full widget support
  • Module System - Load code from files, netidx, or dynamically at runtime

Quick Example

Here's a simple reactive counter that updates every second:

use tui;
use tui::text;

let count = 0;
let timer = time::timer(duration:1.s, true);
count <- timer ~ (count + 1);

text(&"Count: [count]")

The <- operator (connect) schedules updates for the next cycle. When timer fires, count increments, and the text widget automatically displays the new value. The sample operator ~ returns the rhs when the lhs updates.

Installation

Prerequisites

Rust - Install from rustup.rs

Linux only:

  • Debian/Ubuntu: clang, libkrb5-dev
  • Fedora: clang-devel, krb5-devel

Install Graphix

cargo install graphix-shell

Optional: Netidx

For full networking capabilities, install and set up netidx:

cargo install netidx-tools

Getting Started

Interactive REPL

Start the Graphix shell:

graphix

Try some expressions:

〉2 + 2
-: i64
4

〉"Hello, [10 * 5]!"
-: string
"Hello, 50!"

Press Ctrl+C to stop running expressions.

Run a File

Create hello.gx:

use tui;
use tui::text;

let count = 0;
let timer = time::timer(duration:1.s, true);
count <- timer ~ (count + 1);

text(&"Count: [count]")

Run it:

graphix hello.gx

Press Ctrl+C to exit.

TUI Examples

Graphix includes a comprehensive terminal UI library with support for:

Interactive Tables

Table Example

Dynamic Charts

Canvas Animation

Scrollable Content

Paragraph Scrolling

Focus Management

Layout Focus

Documentation

📚 Full Documentation (or build locally with mdbook)

Quick Links

Language Highlights

Pattern Matching with Select

let status: [i64, string, null] = 42;

select status {
  i64 as n if n > 0 => "positive number: [n]",
  i64 as n => "non positive number: [n]",
  string as s => "got string: [s]",
  null as _ => "no value"
}

Error Handling with Try/Catch

try
  let arr = [1, 2, 3];
  arr[10]?
catch(e) => println("Error: [e]")

Reactive Network Subscriptions

let value = cast<i64>(net::subscribe("/sensor/temperature")?)?;
let fahrenheit = value * ((9 / 5) + 32);

text(&"Temperature: [fahrenheit]°F")

Recursive Types

type List<'a> = [`Cons('a, List<'a>), `Nil];

let rec map = |l: List<'a>, f: fn('a) -> 'b| -> List<'b>
  select l {
    `Cons(v, tl) => `Cons(f(v), map(tl, f)),
    `Nil => `Nil
  }

Project Structure

This is a Rust workspace with four main crates:

  • graphix-compiler - The compiler (parsing, type checking, graph generation)
  • graphix-rt - General-purpose runtime for executing dataflow graphs
  • graphix-stdlib - Standard library
  • graphix-shell - REPL, CLI tool, and TUI widgets

Building from Source

# Clone the repository
git clone https://github.com/graphix-lang/graphix.git
git clone https://github.com/netidx/netidx.git
cd graphix

# Build the workspace
cargo build --release

# Run tests
cargo test

# Build documentation
cd book
mdbook build -d ../docs

Contributing

Graphix is under active development. Contributions are welcome!

Examples

The book/src/examples/ directory contains runnable examples:

# Run a TUI example
graphix book/src/examples/tui/barchart_basic.gx

# Check syntax without running
graphix --check book/src/examples/tui/chart_multi.gx

License

This project is licensed under the MIT License - see the LICENSE file for details.