module RemiCharms

Overview

RemiCharms is an interface to libcurses for Crystal. It provides both a raw, low-level interface to libcurses via C bindings, and a more higher-level interface.

It is intended to be a bit easier to use than straight-up ncurses bindings. It is based on cl-charms, a similar interface to ncurses for Common Lisp.

Currently, the low-level interface (the NCurses module) is pretty close to ncurses itself. The high-level interface can be used directly alongside the low-level interface for those instances where the high level interface is missing functionality.

Defined in:

remicharms.cr
remicharms/errors.cr
remicharms/window.cr

Constant Summary

VERSION = "0.1.0"

The current version of the library.

Class Method Summary

Instance Method Summary

Class Method Detail

def self.beep : Nil #

Audibly beep to alert the user.


[View source]
def self.cursesVersion : String #

Return a string representing the version of the underlying curses implementation.


[View source]
def self.deinit : Nil #

Finalizes ncurses

This function must be called before exiting. Consider using RemiCharms.withCurses instead to ensure proper initialization and cleanup.


[View source]
def self.disableRawInput : Nil #

Disables raw input mode. This undoes the action of RemiCharms.enableRawInput.


[View source]
def self.echoing=(value : Bool) : Nil #

Enables or disables the echoing of input.


[View source]
def self.enableRawInput(interpretControlChars : Bool = false) : Nil #

Enables raw input mode. This disables line buffering and will make characters available as soon as they're typed.

If interpretControlChars is true, then control characters like Ctrl-C will be interpreted as usual.


[View source]
def self.flash : Nil #

Visually flash the console.


[View source]
def self.init : Window #

Initializes ncurses and the terminal for drawing. This then returns the standard window (i.e. RemiCharms.standardWindow).

This function must be called before using curses functions. Consider using RemiCharms.withCurses instead to ensure proper initialization and cleanup.


[View source]
def self.inputMode #

The current InputMode.


[View source]
def self.inputMode=(mode : InputMode) : Nil #

Changes the input mode. See RemiCharms.enableRawInput and RemiCharms.disableRawInput for more information.


[View source]
def self.standardWindow #

The equivalent to stdscr in ncurses.


[View source]
def self.standardWindow? #

The equivalent to stdscr in ncurses.


[View source]
def self.withCurses(&) : Nil #

Flushes standard input, output, standard error, initializes ncurses via RemiCharms.init, then yields the standard window. This ensures RemiCharms.deinit is called before returning.


[View source]

Instance Method Detail

def attributeOff(attrs : Attribute) : Nil #

Turn off the attributes without affecting any others.


[View source]
def attributeOff(*attrs : Attribute) : Nil #

Turn off the attributes without affecting any others.


[View source]
def attributeOn(attrs : Attribute) : Nil #

Turn on the attributes without affecting any others.


[View source]
def attributeOn(*attrs : Attribute) : Nil #

Turn on the attributes without affecting any others.


[View source]
def cursorVisibility=(vis : Visibility) : Nil #

Sets the visibility of the cursor.


[View source]
def enableColors : Bool #

Attempts to enable color support. On success, this returns true, otherwise it returns false if the terminal does not support color.


[View source]
def getColorPair(num : Int16) : Int16 #

Given a color pair represented by num, returns a new integer that can be used with an attribute function.


[View source]
def initColor(color : Int16, r : Int16, g : Int16, b : Int16) : Bool #

Attempts to change the definition of the color represented by color to the given RGB values. On success, this returns true, otherwise if the terminal does not support the changing of colors, this returns false.

When #initColor is called, all occurences of color are immediately changed.


[View source]
def initColor(color : Int16, rgb : Tuple(Int16, Int16, Int16)) : Bool #

Attempts to change the definition of the color represented by color to the given RGB values. On success, this returns true, otherwise if the terminal does not support the changing of colors, this returns false.

When #initColor is called, all occurences of color are immediately changed.


[View source]
def initColorPair(pair : Int16, fg : Color, bg : Color) : Nil #

Initializes a color pair that will be represented by pair.


[View source]
def useEnterAsNewline=(value : Bool) : Nil #

Controlls whether the underlying display device translates the return key into newline on input.


[View source]
def withAttributes(attrs : Attribute, &) : Nil #

Temporarily turns on the given attributes in the block, then turns them off before returning.


[View source]