module Lime

Overview

The main module of lime.

All x and y arguments are zero-based.

An IndexError will be raised if:

NOTE Sometimes you might come across the terms "cell" and "pixel":

Extended Modules

Defined in:

lime.cr
lime/drawables.cr
lime/modules.cr

Instance Method Summary

Instance Method Detail

def buffer(x, y) : Char | Colorize::Object(Char) #

Returns the character of the buffer at x, y.


[View source]
def buffer : Array(Char | Colorize::Object(Char)) #

Returns the buffer as an array of characters.


[View source]
def buffer=(buffer : Array(Char | Colorize::Object(Char))) #

Sets the buffer to buffer.


[View source]
def buffer_height=(height) #

Sets the height of the buffer to height.


[View source]
def clear #

Clears the buffer.


[View source]
def draw #

Draws the content of the buffer to the screen.

NOTE This should not be called concurrently.


[View source]
def get_key : Symbol | String #

Waits until a key has been pressed and returns it compactly as a symbol.

  • :up if up arrow has been pressed.
  • :down if down arrow has been pressed.
  • :left if left arrow has been pressed.
  • :right if right arrow has been pressed.
  • :enter if enter has been pressed.
  • :tab if tab has been pressed.
  • :backspace if backspace has been pressed.
  • :escape if escape has been pressed.
  • :ctrl_c if Ctrl+C has been pressed.

If none of the above keys are pressed, the key is returned as-is.

NOTE Ctrl+C is caught by this method and will not be handled by the system.


[View source]
def get_key_raw : String #

Waits until a key has been pressed and returns it.

NOTE Ctrl+C is caught by this method and will not be handled by the system.


[View source]
def line(x1 : Int32, y1 : Int32, x2 : Int32, y2 : Int32, color : Colorize::Color = Colorize::ColorANSI::Default) #

Inserts a line from x1, y1 to x2, y2 with color into the buffer.

Lime.line(0, 0, 5, 5)
▀▄
  ▀▄
    ▀▄
Lime.line(0, 0, 10, 5)
▀▀▄▄
    ▀▀▄▄
        ▀▀▄

This method uses Bresenham's line algorithm.


[View source]
def loop(&) #

The order of the loop is as follows:

1. Executes the given block.

2. Draws the content of the buffer to the screen.

3. Clears the buffer.


[View source]
def peek_key : Symbol | String | Nil #

Returns the key that is down in the moment this method is called compactly as a symbol or nil if no key is down.

  • :up if up arrow is down.
  • :down if down arrow is down.
  • :left if left arrow is down.
  • :right if right arrow is down.
  • :enter if enter is down.
  • :tab if tab is down.
  • :backspace if backspace is down.
  • :escape if escape is down.
  • :ctrl_c if Ctrl+C is down.

If none of the above keys are down, the key is returned as-is.

NOTE Ctrl+C is caught by this method and will not be handled by the system.


[View source]
def peek_key_raw : String | Nil #

Returns the key that is down in the moment this method is called or nil if no key is down.

NOTE Ctrl+C is caught by this method and will not be handled by the system.


[View source]
def pixel(x : Int32, y : Int32, color : Colorize::Color = Colorize::ColorANSI::Default) #

Inserts a pixel at x, y with color into the buffer.

Lime.pixel(2, 2)
Lime.pixel(2, 2)
Lime.pixel(2, 3)

[View source]
def print(char : Char | Colorize::Object(Char), x : Int32, y : Int32) #

Inserts char into the buffer at x, y.


[View source]
def print(string : String, x : Int32, y : Int32) #

Inserts string into the buffer at x, y.


[View source]
def print(string : Colorize::Object(String), x : Int32, y : Int32) #

Inserts string into the buffer at x, y.


[View source]
def printf(string : String, x : Int32, y : Int32) #

Inserts string formatted into the buffer at x, y.

This method properly aligns each line in the string beneath each other.

Lime.printf("hello\nworld", 2, 2)


  hello
  world

[View source]
def printf(string : Colorize::Object(String), x : Int32, y : Int32) #

Inserts string formatted into the buffer at x, y.

This method properly aligns each line in the string beneath each other.

Lime.printf("hello\nworld", 2, 2)


  hello
  world

[View source]