module Lolcat::Lol

Overview

The Lol module contains the core functionality for colorizing text with rainbow colors.

This module provides methods to process text input (from strings or IO) and apply rainbow colors to each character. It handles ANSI escape sequences, animation effects, and various customization options.

Extended Modules

Direct including types

Defined in:

lolcat.cr
lolcat/lol.cr

Constant Summary

ANSI_ESCAPE = /((?:\e(?:[ -\/]+.|[\]PX^_][^\a\e]*|\[[0-?]*.|.))*)(.?)/m

Regular expression to match ANSI escape sequences and visible characters

ESCAPE_SEQUENCES = /\e\[[0-?]*[@JKPX]/

Regular expression to match ANSI escape sequences for cursor movement

HIDE_CURSOR = "\e[?25l"

ANSI escape sequence to hide the cursor

INCOMPLETE_ESCAPE = /\e(?:[ -\/]*|[\]PX^_][^\a\e]*|\[[0-?]*)$/

Regular expression to match incomplete ANSI escape sequences at the end of a buffer

RESET_ATTRIBUTES = "\e[m"

ANSI escape sequence to reset all terminal attributes

RESET_TERMINAL_MODES = "\e[?1;5;2004l"

ANSI escape sequence to reset terminal modes

SHOW_CURSOR = "\e[?25h"

ANSI escape sequence to show the cursor

Instance Method Summary

Instance Method Detail

def lol(input : String, options : Options, &) #

Processes a string input and yields each colorized line.

This is a convenience overload that converts a string to an IO::Memory and delegates to the IO version of this method.

input: The string to process options: Configuration options for the colorization yield: Each processed line is yielded to the block


[View source]
def lol(input : IO, options : Options, &) #

Processes an IO input and yields each colorized line.

This method reads from the input IO in chunks, processes each line, and yields the colorized output. It handles ANSI escape sequences and maintains line numbering for proper rainbow color progression.

input: The IO to read from options: Configuration options for the colorization yield: Each processed line is yielded to the block


[View source]
def lol_cat(input : IO | String, options : Options) #

Processes input and prints it with rainbow colors.

This is the main function for displaying colorized text to the terminal. It handles both string and IO inputs, applies rainbow colors, and manages terminal state (cursor visibility, etc.).

input: The text to colorize (either a String or IO) options: Configuration options for the colorization


[View source]
def rainbow_color(freq : Float64, offset : Float64) : Tuple(UInt8, UInt8, UInt8) #

Calculates RGB color values for a rainbow effect based on frequency and offset.

This function uses sine waves with different phase shifts to generate smooth transitions between colors in the rainbow spectrum.

freq: Controls how quickly the colors change offset: Position in the color cycle

Returns a tuple of RGB values as UInt8 (0-255)


[View source]
def rainbow_line(line : String, options : Options, index : Int32, pos : Int32) : String #

Applies rainbow colors to a line of text based on line number and position.

This overload calculates the appropriate offset based on line number and position, then delegates to the offset-based version of this method.

line: The line of text to colorize options: Configuration options for the colorization index: The line number (used for color progression) pos: The cursor position (used for color progression)

Returns a string with rainbow colors applied


[View source]
def rainbow_line(line : String, options : Options, offset : Float64) : String #

Applies rainbow colors to a line of text based on a specific offset.

This is the core method that applies rainbow colors to each character in a line. It handles ANSI escape sequences and applies colors to visible characters only.

line: The line of text to colorize options: Configuration options for the colorization offset: The color offset to use (determines the starting color)

Returns a string with rainbow colors applied


[View source]