Skip to content

Latest commit

 

History

109 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xt — Cross-Platform Native Terminal & Shell

A single, self-contained Rust binary that is simultaneously a terminal emulator, interactive shell, command runtime, scripting environment, and cross-platform OS abstraction layer.

Zero external crates. Zero runtime dependencies. One executable (~618 KB).


1. Product Overview

Traditional workflows rely on a stack of disconnected layers:

GUI Terminal Emulator (Alacritty / WezTerm / Windows Terminal)
      ↓
Shell Binary (Bash / Zsh / PowerShell / CMD)
      ↓
Core Utilities (coreutils / findutils / procps)
      ↓
Operating System APIs

xt unifies the entire execution environment into a single executable:

 ┌──────────────────────────────────────────────┐
 │                     xt                       │
 │                 ONE BINARY                   │
 ├──────────────────────────────────────────────┤
 │  Terminal Emulator   │  Interactive Shell    │
 │  VT100 / ANSI Engine │  Command Runtime      │
 │  Typed Pipelines     │  Scripting Engine     │
 │  GPU / CPU Renderer  │  Job Manager          │
 │  OS Abstraction      │  History & Completion │
 └──────────────────────┬───────────────────────┘
                        │
 ┌──────────────────────▼───────────────────────┐
 │              Native OS Backend               │
 ├──────────────────────┬───────────────────────┤
 │  Windows NT APIs     │  Linux / Unix Syscall │
 │  Win32 Console FFI   │  POSIX termios        │
 │  Toolhelp32 Snapshot │  /proc Virtual FS     │
 │  Direct3D / DXGI     │  DRM / DRI & Metal    │
 └──────────────────────┴───────────────────────┘

2. Core Architectural Principles

  • Zero Crates Policy: Built entirely from the Rust standard library (std) and raw platform FFI. No Tokio, no Clap, no Serde, no Crossterm, no Ratatui, no libc, no windows crate.
  • True Multithreaded Architecture: Decoupled domains for interactive input handling, AST execution, worker pool thread processing, and damage-driven rendering.
  • Dual Rendering Backends:
    • GPU Accelerated: Probes hardware adapters (Direct3D / DXGI / Vulkan on Windows, DRM/DRI on Linux, Metal on macOS) dynamically without crashing.
    • CPU Software Fallback: Clean ANSI differential updating engine redrawing only dirty rows to prevent flickering and conserve CPU cycles.
  • Consistent Cross-Platform Semantics: Standard commands (ls, ps, cat, cd, pwd, cp, mv, rm, mkdir, clear) behave identically across Windows, Linux, and macOS.
  • Structured Data Pipelines: First-class Value objects (File, Process, Directory, Map, List) allow filtering and projection (ps | where cpu > 10 | select pid name) without brittle text parsing hacks (grep | awk | cut).

3. Directory Layout

xt/
├── Cargo.toml                  # Zero dependencies
├── README.md                   # Project documentation
├── bp.md                       # Architecture specification
├── test_script.xt              # Demo scripting file
└── src/
    ├── lib.rs                  # Module declarations & public API
    ├── main.rs                 # CLI entrypoint, argument dispatch, interactive loop
    ├── terminal/
    │   ├── mod.rs              # Terminal coordinator & TerminalSink trait
    │   ├── cell.rs             # Cell, Color (16/256/TrueColor), CellFlags
    │   ├── cursor.rs           # Cursor state, shapes, save/restore
    │   ├── screen.rs           # Virtual grid, scrollback, damage tracking
    │   ├── ansi.rs             # Incremental VT100/VT220/ECMA-48 escape parser
    │   ├── input.rs            # Raw key event decoding (arrows, function, ctrl)
    │   ├── render.rs           # Renderer trait, CpuRenderer, GpuRenderer, AutoRenderer
    │   └── selection.rs        # Screen grid text selection
    ├── shell/
    │   ├── mod.rs              # Interactive REPL, prompt formatting, line editor, completion
    │   ├── lexer.rs            # Deterministic character scanner (no regex)
    │   ├── parser.rs           # Recursive descent AST parser
    │   ├── ast.rs              # Statements, expressions, pipelines, functions, loops
    │   ├── expand.rs           # Variable interpolation ($VAR), tilde (~), globs (*)
    │   ├── variable.rs         # Nested lexical scopes & variable environment
    │   ├── history.rs          # Disk-persisted history navigation (~/.xt_history)
    │   └── eval.rs             # AST evaluation engine
    ├── runtime/
    │   ├── mod.rs              # Runtime coordinator (working dir, env, aliases)
    │   ├── value.rs            # Structured Value enum & tabular formatters
    │   ├── stream.rs           # Pipeline streams (Text, Binary, Values)
    │   ├── command.rs          # Resolution: builtins -> aliases -> PATH executables
    │   ├── pipeline.rs         # Concurrent pipeline execution & file redirections
    │   ├── process.rs          # OS process spawning & stream piping
    │   ├── jobs.rs             # Background job control (&, jobs, fg, bg, wait)
    │   └── threadpool.rs       # Native worker thread pool using std::sync primitives
    ├── builtin/
    │   ├── mod.rs              # Builtin registry & dispatcher
    │   ├── filesystem.rs       # ls, cd, pwd, cp, mv, rm, mkdir, touch, cat, head, tail, find, stat
    │   ├── process.rs          # ps, kill, jobs, fg, bg, wait
    │   ├── environment.rs      # env, set, unset, which
    │   ├── shell.rs            # echo, printf, history, alias, unalias, where, select, sort, count, exit
    │   └── system.rs           # clear, title, sleep, date, whoami, sysinfo
    ├── platform/
    │   ├── mod.rs              # Platform trait and unified API
    │   ├── windows/            # Win32 Console, Toolhelp32 process snapshotting, GPU probe
    │   ├── unix/               # POSIX termios, /proc inspection, DRM probe
    │   └── macos/              # macOS fallback implementations
    ├── config/
    │   └── mod.rs              # Configuration loader (config.xt)
    └── util/
        └── mod.rs              # Table formatter, recursive globbing, byte formatting

4. Building & Installation

Prerequisites

  • Rust compiler and toolchain (stable, edition 2021).

Build Commands

# Verify build
cargo check

# Run test suite
cargo test

# Build optimized release binary
cargo build --release

The resulting executable will be located at target/release/xt (or target/release/xt.exe on Windows).


5. Usage

Standalone Native Window Mode (Default)

Launch xt directly without arguments or double-click xt.exe:

./target/release/xt

xt opens its own dedicated standalone native window with dark titlebar, Consolas monospace typography, and double-buffered GPU-accelerated rendering. It does not run inside or depend on cmd.exe or external consoles.

Console CLI Mode (--cli)

If you prefer running inside an existing terminal emulator or headless environment:

xt --cli

Execute Single Commands (-c)

xt -c "echo 'Hello from xt'"
xt -c "ps | select pid name | first 5"
xt -c "ls | where size > 1000"

Run Script Files

xt script.xt

6. Shell Language Reference

xt provides an ergonomic, shell-like language without legacy quirks:

Variables & Expressions

let name = "developer"
let count = 42
let total = $count * 2
echo "User: $name, Total: $total"

Functions

fn greet(user) {
    echo "Welcome," $user
}

greet("Ada")

Conditionals

if exists("Cargo.toml") {
    echo "Found Rust project"
} else {
    echo "No Cargo manifest found"
}

if success {
    echo "Previous command succeeded"
}

Loops

for file in glob("src/**/*.rs") {
    echo "Found source:" $file
}

for item in ["alpha", "beta", "gamma"] {
    echo "Item:" $item
}

7. Typed Pipelines

Traditional shells treat all output as raw byte streams that must be sliced and grepped. xt commands can pass typed structured data directly:

Process Filtering & Projection

ps | where cpu > 10 | select pid name cpu

Output:

PID    NAME         CPU    
1824   firefox      17.4%  
2911   rust-analyzer 13.1%  

Filesystem Queries

ls | where size > 5000 | sort size

Text & Binary Pipelines

cat Cargo.toml | where name

Pipeline Redirection

ps | select pid name > processes.txt
cargo build 2> errors.log
echo "appended line" >> output.txt

8. Built-in Commands Reference

xt separates command execution into Exported Builtins (xtsh exports + native builtins) and the full xtsh UNIX/POSIX Bridge:

Resolution Order (Bare):  PATH -> builtin -> not_found
Resolution Order (xtsh):  PATH -> xtsh -> builtin -> not_found
Category Commands Description
Exported (xtsh exports + builtins) alias, cat, cd, clear, cp, echo, env, exit, head, help, history, kill, ls, mkdir, mv, printf, ps, pwd, rm, select, set, sleep, sort, syscmd, tail, touch, unalias, unset, where, xtenv, xtpkg, xtsh All 32 commands resolvable bare in standard PATH -> builtin order
xtsh-Only Applets dirs, caller, compgen, compopt, popd, pushd, test, [, export, declare, local, readonly, read, eval, exec, grep, sed, awk, cut, uniq, wc, tr, tee, chmod, ln, rmdir, du, df, base64, sha256, md5, uname, etc. Commands isolated strictly to xtsh (require xtsh <cmd> or shell scripts)
Diagnostics (xtenv) xtenv Outputs single platform signature string: "platform arch physical/logical" (e.g. "windows x86_64 8/16")

9. Configuration (config.xt)

xt uses its own shell language for configuration:

  • Linux / macOS: ~/.config/xt/config.xt
  • Windows: %APPDATA%\xt\config.xt

Example configuration:

alias ll = ls
alias gs = git status
let author = "Engineer"

10. Design Law

Terminal semantics are completely independent from windowing, rendering, fonts, and OS process management.

xt is a unified runtime rather than a terminal emulator wrapped around someone else's shell.


11. Note on the commit history

This project began purely as an experiment. Because I initially didn't expect it to evolve into a fully functional project, the commit history serves as an unfiltered, raw log of my debugging journey. I chose to leave this history intact to showcase the actual, unpolished problem-solving process involved in wrestling with systems.

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages