github.com/trans/crt-ncurses

Legacy CRT TUI using Ncurses (instead of ANSI)

0 stars
0 dependents
License: MIT

Nothing has been indexed for 0.6.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  crt-ncurses:
    github: trans/crt-ncurses
    version: ~> 0.6.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.6.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

CRT for Ncurses

A Crystal library of Ncurses widgets for building terminal user interfaces for legacy application.

Please Note: This library is currently on the back burner while devlopment of a new pure ANSI based CRT library is developed. Eventually this library will be modiied to act as an alternate backend for CRT proper.

CRT Ncurses provides 23 ready-to-use widgets — from simple labels and buttons to scrolling lists, text editors, menus, file selectors, and spreadsheet-style grids — all rendered with ncurses.

CRT Ncruses is a heavy modified ported of Ruby CDK, which is itself a port of the CDK C libary.

Widgets

WidgetDescription
LabelStatic text display
DialogMessage box with buttons
EntrySingle-line text input
MultiEntryMulti-line text editor
ButtonStandalone push button
ButtonBoxGroup of buttons
Scale(T)Numeric input with arrow keys — generic over any number type
Slider(T)Slider bar — generic over any number type
ScrollScrolling list
RadioRadio button list
SelectionMulti-select checklist
ItemListCycle through a list of values
TemplateFormatted input with overlay template
HistogramHorizontal/vertical bar chart
GraphLine/plot graph
CalendarDate picker
MarqueeScrolling marquee text
ScrollWindowScrolling text output window
ViewerText file viewer with buttons
MenuMenu bar with pull-down submenus
AlphaListFilterable alphabetical list
FileSelectFile/directory selector
MatrixSpreadsheet-style editable grid

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      crt:
        github: trans/crt
  2. Run shards install

Requires ncurses development headers (libncurses-dev, ncurses-devel, or equivalent for your system).

Usage

require "crt/ncurses"

# Initialize ncurses
CRT::Ncurses.start

# Create a screen
screen = CRT::Ncurses::Screen.new

# Display a label
label = CRT::Ncurses::Label.new(screen,
  x: CRT::Ncurses::CENTER, y: CRT::CENTER,
  message: ["[b]Hello, CRT![/]", "Press any key to exit."],
  box: true, shadow: true)

label.draw
label.wait(0)

# Clean up
label.destroy
screen.destroy
CRT::Ncurses.end

Format Strings

CRT::Ncurses provides a BBCode-style format string system for styled text. Use CRT::Ncurses.fmt to convert a format string into a chtype array for display.

# Bold text
CRT::Ncurses.fmt("[b]Hello![/]")

# Combined attributes and colors
CRT::Ncurses.fmt("[bold #0F]Status:[/] OK")

# Alignment (at string start)
CRT::Ncurses.fmt("[C][b]Centered Title[/]")

Attributes

ShortLongEffect
[b][bold]Bold
[u][underline]Underline
[dim][dim]Dim
[rev][reverse]Reverse video
[so][standout]Standout
[bk][blink]Blink

Multiple attributes can be combined in one tag: [b u]

Colors

Colors use hex palette indices (00-FF, 256-color terminal palette):

NotationMeaning
#XXForeground color
##XXBackground color
#XX/YYForeground / background
##YY/XXBackground / foreground
CRT::Ncurses.fmt("[#0F]green text[/]")
CRT::Ncurses.fmt("[#FF/00]white on black[/]")
CRT::Ncurses.fmt("[b #0F/00]bold green on black[/]")

Alignment

Place at the start of the string:

ShortLong
[C][center]
[R][right]
[L][left]

Style Stack

  • [/] — pop the last style (restores previous attributes/colors)
  • [//] — reset all styles
  • \[ — literal open bracket

Named Styles

Register reusable styles with CRT.style:

CRT::Ncurses.style("error", "bold #FF ##00")
CRT::Ncurses.style("header", "bold underline #0F")

CRT::Ncurses.fmt("[error]Oops![/] Something broke")
CRT::Ncurses.fmt("[header]Welcome[/]")

Development

crystal spec                                   # Run tests
crystal build src/crt/ncurses.cr --no-codegen  # Type-check without building

Contributing

  1. Fork it (https://github.com/trans/crt-ncurses/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

MIT