module

Lime

The main module of lime.

All x and y arguments are zero-based.

An IndexError will be raised if:

  • An x argument is greater than Window.width.
  • An x argument is lower than -Window.width_cells.
  • A y argument is greater than Window.height.
  • A y argument is lower than -Window.height_cells.

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

  • A "cell" refers to one place of a character on the console: █.
  • A "pixel" does not refer to a pixel of a display. It refers to the half of a "cell": ▀ and ▄.

Instance methods

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

Returns the character of the buffer at x, y.

Source
buffer

Returns the buffer as an array of characters.

Source
buffer=(buffer : Array(Char | Colorize::Object(Char)))

Sets the buffer to buffer.

Source
buffer_height=(height)

Sets the height of the buffer to height.

Source
clear

Clears the buffer.

Source
draw

Draws the content of the buffer to the screen.

NOTE: This should not be called concurrently.

Source
get_key

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.

Source
get_key_raw

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.

Source
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.

Source
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.

Source
peek_key

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.

Source
peek_key_raw

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.

Source
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)

  █
Source
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
Source
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
Source

Nested types