Etch - A Gleam TUI Backend Library

Package Version Hex Docs

Etch is a powerful terminal user interface (TUI) backend library for Gleam, designed to help you build rich, interactive terminal applications with ease. It provides a comprehensive set of tools for managing terminal output, handling events, and styling text, with no third-party dependencies.

This project was inspired by crossterm.

Features

Terminal Control

Cursor Management

Event Handling

Text Styling

Command System

Getting Started

Here’s a basic template to get you started with Etch:

import etch/command
import etch/terminal
import etch/style
import etch/stdout.{type Queue, execute, flush, queue}

pub fn main() {
  // Use execute to execute `Commands`
  execute([
    command.EnterRaw,
    command.EnterAlternateScreen,
    command.HideCursor,
    command.Clear(terminal.All)
  ])

  // Queue `Commands`
  let q = Queue([
    command.SetForegroundColor(style.Red),
    command.SetBackgroundColor(style.Black),
  ])
  let text = "Styled text"
  let q = queue(q, [command.Println(text)])
  
  // Flush queued `Commands`
  flush(q)
}

Examples

Check out the examples in the examples/ directory for more advanced usage:

To run the use this command:

gleam run -m examples/{example_name}

Documentation

For detailed API documentation, see the documentation for the Etch package.

Building and Shipping Your App

To build the app into single executable:

  1. Add Etch and gleescript to your project:

    gleam add etch
    gleam add --dev gleescript
    
  2. Build your application:

    gleam build
    gleam run -m gleescript
    

You will get an executable file in your project’s root directory. Users must have Erlang installed in order to run your executable.

Contributing.

Feel free to open issues and make pull requests.

Authors

License

This project is licensed under MIT License. See LICENSE file for details.

Search Document