🎵RMP Framework

Terminal-based UI Framework with Audio Playback - API v1.0.0

🔍

📖Overview

The RMP (Ray Music Player) framework is a comprehensive terminal-based UI framework with audio playback capabilities designed for Lua 5.4. It provides rich terminal applications with features including window management, text styling, audio control, and cross-platform support.

Core Features

Platform Support

License

Copyright © 2024-2025 Ray Den. Licensed under the MIT License.

🏗️Classes

RMP.Table

Advanced table management class for data manipulation.

  • constructor(data)
    Creates new table instance
  • addRow(row)
    Adds a row to the table
  • getRow(index)
    Retrieves a specific row
  • removeRow(index)
    Removes a row by index
  • clear()
    Clears all table data
  • size()
    Returns table size
RMP.Text

Text rendering and styling class with position control.

  • constructor(text, style, fg, bg)
    Creates styled text object
  • setPosition(x, y)
    Sets text position
  • getColoredText()
    Returns styled text string
  • getText()
    Gets raw text content
  • getStyle()
    Gets text style
  • getFGColor()
    Gets foreground color
  • getBGColor()
    Gets background color
RMP.Window

Window management with borders, titles, and callbacks.

  • constructor(id)
    Creates window with ID
  • setId(id)
    Sets window identifier
  • getId()
    Gets window identifier
  • createWindow(title, width, height, x, y, border_color, background_color, border_style, callback)
    Creates and configures window
RMP.VirtualTerminal

Core virtual terminal for rendering and event handling.

  • constructor(width, height)
    Creates virtual terminal
  • clear()
    Clears terminal content
  • setChar(x, y, char, fg, bg, style)
    Sets character at position
  • writeText(x, y, text, fg, bg, style)
    Writes text at position
  • drawBox(title, x, y, width, height, border_style, fg, bg)
    Draws bordered box
  • render()
    Renders terminal to screen
  • merge(thatTerm, offsetX, offsetY)
    Merges another terminal
RMP.Sound

Comprehensive audio playback and playlist management.

  • constructor(files)
    Creates audio instance with files
  • setPlaylist(files)
    Sets audio playlist
  • play()
    Starts audio playback
  • pause()
    Pauses audio playback
  • stop()
    Stops audio playback
  • setVolume(volume)
    Sets playback volume (0.0-1.0)
  • setSpeed(speed)
    Sets playback speed
  • seek(seconds)
    Seeks to position in seconds
  • nextTrack()
    Advances to next track
  • prevTrack()
    Goes to previous track
RMP.Input

User text input handling with cursor management.

  • constructor(label, x, y, width, defaultText, cancelKey)
    Creates input field
  • start()
    Activates input field
  • stop()
    Deactivates input field
  • processKey(key)
    Processes keyboard input
  • getText()
    Gets input text
  • setText(text)
    Sets input text
  • clearText()
    Clears input text
RMP.Options

Interactive option menu system with selection tracking.

  • constructor(options)
    Creates options menu
  • setOptions(options)
    Sets menu options
  • next(block)
    Moves to next option
  • prev(block)
    Moves to previous option
  • getSelected()
    Gets selected option
  • focusPos(position)
    Sets focus position
  • parse()
    Parses options for rendering
RMP.Popup

Modal dialog system for notifications and messages.

  • run(message, title, border_color, bg_color, poslayout)
    Shows popup dialog
RMP.Scroller

Content scrolling mechanism for large lists.

  • constructor(visible_height, options_obj)
    Creates scroller with options
  • nextLine()
    Scrolls down one line
  • prevLine()
    Scrolls up one line
  • nextContent()
    Scrolls down by page
  • prevContent()
    Scrolls up by page
  • getVisible()
    Gets visible items
RMP.Draw

Drawing primitives for shapes and graphics.

  • rectangle(x, y, width, height, color)
    Draws rectangle
  • circle(centerX, centerY, r, color)
    Draws circle
  • triangle(height, pos_x, pos_y, color)
    Draws triangle
  • line(x, y, width, color)
    Draws horizontal line
  • column(x, y, height, color)
    Draws vertical line
RMP.Terminal

Terminal manipulation and cursor control.

  • clearWindow()
    Clears terminal window
  • moveTo(x, y)
    Moves cursor to position
  • hideCursor()
    Hides terminal cursor
  • showCursor()
    Shows terminal cursor
  • getSize()
    Gets terminal dimensions
  • handleKey()
    Handles keyboard input
RMP.EventListener

Event handling system for user interactions.

  • constructor()
    Creates event listener
  • addEventListener(event, callback)
    Adds event listener
  • onKeyboard(callback)
    Adds keyboard event listener
  • onMouse(callback)
    Adds mouse event listener
  • onSound(callback)
    Adds sound event listener
  • handleEvent(key, mouse, sound)
    Processes events
RMP.Path

File system operations and path manipulation.

  • constructor(path)
    Creates path object
  • getCurrentPath()
    Gets current directory
  • getHomePath()
    Gets home directory
  • listDir()
    Lists directory contents
  • makeDir(dir_name)
    Creates directory
  • find(pattern, is_find_file)
    Finds files/directories
RMP.Config

Configuration management with cross-platform support.

  • constructor(confPath)
    Creates config manager
  • load()
    Loads configuration file
  • getThemePath(themeName)
    Gets theme file path
  • getPluginPath(pluginName)
    Gets plugin file path
  • isValidConfig()
    Validates configuration
RMP.Frame

High-level frame management with FPS control.

  • constructor(width, height)
    Creates frame instance
  • setFps(fps)
    Sets frame rate
  • add(component)
    Adds component to frame
  • run(key, mouse, sound)
    Runs frame update cycle

🎨Constants & Symbols

Text Styles

  • TextStyle.Bold
  • TextStyle.Italic
  • TextStyle.Underline
  • TextStyle.Strike
  • TextStyle.Reverse
  • TextStyle.Blink
  • TextStyle.Regular

Foreground Colors

  • FGColors.NoBrights.Black
  • FGColors.NoBrights.Red
  • FGColors.NoBrights.Green
  • FGColors.NoBrights.Yellow
  • FGColors.NoBrights.Blue
  • FGColors.NoBrights.Magenta
  • FGColors.NoBrights.Cyan
  • FGColors.NoBrights.White

Background Colors

  • BGColors.NoBrights.Black
  • BGColors.NoBrights.Red
  • BGColors.NoBrights.Green
  • BGColors.NoBrights.Yellow
  • BGColors.NoBrights.Blue
  • BGColors.NoBrights.Magenta
  • BGColors.NoBrights.Cyan
  • BGColors.NoBrights.White

Border Styles

  • BoxDrawing.LightBorder
  • BoxDrawing.HeavyBorder
  • BoxDrawing.RoundedCorners
  • BoxDrawing.RoundedBorder

Unicode Symbols

  • File_pos ➯
  • Pause_start ⏯
  • Next ⏵
  • Prev ⏴
  • Volume_max 🔊
  • Volume_mute 🔇
  • Search_emo 🔎

Progress Bars

  • Bar_l_to_r_25_per ▎
  • Bar_l_to_r_50_per ▌
  • Bar_l_to_r_75_per ▊
  • Bar_100_per █
  • Bar_Shading_25_per ░
  • Bar_Shading_50_per ▒
  • Bar_Shading_75_per ▓

🔢Enumerations

Platform Types

  • PlatformType.LINUX
  • PlatformType.WINDOWS
  • PlatformType.MAC
  • PlatformType.UNKNOWN

Playback Modes

  • PlaybackMode.ONCE
  • PlaybackMode.LOOP_SINGLE
  • PlaybackMode.LOOP_PLAYLIST
  • PlaybackMode.SHUFFLE

Audio States

  • State.STOPPED
  • State.PLAYING
  • State.PAUSED
  • State.LOADING
  • State.ERROR

Event Types

  • EventType.Keyboard
  • EventType.Mouse
  • EventType.Focus
  • EventType.Sound
  • EventType.TransformDataGet
  • EventType.TransformDataPut

Popup Positions

  • PopupPosition.CENTER
  • PopupPosition.TOP_LEFT
  • PopupPosition.TOP_RIGHT
  • PopupPosition.BOTTOM_LEFT
  • PopupPosition.BOTTOM_RIGHT

Key Constants

  • KEY_ENTER
  • KEY_ESCAPE
  • KEY_UP, KEY_DOWN
  • KEY_LEFT, KEY_RIGHT
  • KEY_CTRL_A to KEY_CTRL_Z
  • KEY_A to KEY_Z
  • KEY_0 to KEY_9

🛠️Utility Functions

Global Functions
  • RMP.enum(reset, value, start)
    Creates enumeration values
  • RMP.getOs()
    Returns platform type
  • RMP.sleep(time)
    Sleeps for specified time
  • RMP.colorFromHex(hex, fg_or_bg)
    Converts hex to ANSI color
  • RMP.quickRoutine(func)
    Creates coroutine
Duration Class
  • Duration.new(time)
    Creates duration object
  • fromSec()
    Converts to milliseconds
  • fromMilsec()
    Returns milliseconds
Mouse Class
  • Mouse.new(x, y, button, action)
    Creates mouse object
  • getX(), getY()
    Gets mouse coordinates
  • getButton()
    Gets mouse button
  • getAction()
    Gets mouse action
Menu System
  • Menu.new(title, options)
    Creates menu
  • MenuItem.new(label, action)
    Creates menu item
  • addOption(option)
    Adds menu option
  • execute()
    Executes menu action

📋Code Examples

Basic Window Creation

            
local RMP = require("rmp.rmp") -- Create a basic window local window = RMP.Window.new(1) local vterm = window:createWindow( RMP.Text.new("My Window", RMP.TextStyle.Bold, RMP.FGColors.Brights.White), 80, 24, 1, 1, RMP.FGColors.NoBrights.Blue, RMP.BGColors.NoBrights.Black, RMP.BoxDrawing.LightBorder, function(x, y, width, height) local content = RMP.VirtualTerminal.new() content:writeText(x + 2, y + 2, "Hello, RMP Framework!", RMP.FGColors.Brights.Green) return content end ) vterm:render()

Audio Playbook Management

local RMP = require("rmp.rmp") -- Create audio player local sound = RMP.Sound.new() -- Set playlist sound:setPlaylist({ "music/song1.mp3", "music/song2.wav", "music/song3.ogg" }) -- Configure playback sound:setPlayBackMode(RMP.PlaybackMode.LOOP_PLAYLIST) sound:setVolume(0.8) -- Play music sound:play() -- Event loop for auto-advance while true do sound:update() RMP.sleep(100) -- 100ms end

Interactive Input Form

local RMP = require("rmp.rmp") -- Create input field local input = RMP.Input.new( "Enter name: ", 5, 5, 30, "", RMP.KEY_ESCAPE ) -- Create frame for rendering local frame = RMP.Frame.new() frame:setFps(30) -- Event handling frame:addEventListener(RMP.EventType.Keyboard, function(key) if not input:processKey(key) then if key == RMP.KEY_ESCAPE then return false -- Exit end end if input:wasSubmitted() then print("User entered: " .. input:getText()) input:reset() end end) -- Main loop local terminal = RMP.Terminal.new() terminal:rawMode(true) while true do input:render() frame:add(input:getVterm()) local key = terminal:handleKey() frame:run(key, nil, nil) end

Options Menu

local RMP = require("rmp.rmp") -- Create options menu local options = RMP.Options.new({ "Start Game", "Load Game", "Settings", "Exit" }) options:setColorFocus(RMP.FGColors.Brights.Yellow) options:setSymblFocus("► ") -- Handle selection local frame = RMP.Frame.new() frame:addEventListener(RMP.EventType.Keyboard, function(key) if key == RMP.KEY_UP then options:prev() elseif key == RMP.KEY_DOWN then options:next() elseif key == RMP.KEY_ENTER then local selected = options:getSelected() print("Selected: " .. selected) end end) -- Render loop local vterm = RMP.VirtualTerminal.new() while true do vterm:clear() local parsed_options = options:parse() for i, option in ipairs(parsed_options) do vterm:writeText( 5, 5 + i, option.text, option.fg, option.bg, option.style ) end frame:add(vterm) local key = RMP.Terminal:handleKey() frame:run(key, nil, nil) end

Drawing Graphics

local RMP = require("rmp.rmp") -- Create drawing surface local draw = RMP.Draw.new() local vterm = RMP.VirtualTerminal.new() -- Draw shapes local rect = draw:rectangle( 10, 5, 20, 10, RMP.BGColors.NoBrights.Red ) local circle = draw:circle( 30, 15, 5, RMP.BGColors.NoBrights.Blue ) local line = draw:line( 5, 20, 40, RMP.BGColors.NoBrights.Green ) -- Merge all drawings vterm:merge(rect) vterm:merge(circle, 25, 0) -- Offset circle vterm:merge(line) -- Add text overlay vterm:writeText( 15, 25, "RMP Graphics Demo", RMP.FGColors.Brights.White, RMP.BGColors.NoBrights.Black, RMP.TextStyle.Bold ) -- Render vterm:render()

File Browser Implementation

local RMP = require("rmp.rmp") -- Create path and file listing local path = RMP.Path.new() local files = path:listDir() -- Convert to options local file_names = {} for _, file_info in ipairs(files) do local prefix = file_info.is_file and "📄 " or "📁 " table.insert(file_names, prefix .. file_info.name) end -- Create scrollable file list local options = RMP.Options.new(file_names) local scroller = RMP.Scroller.new(20, options) -- Show 20 items -- Handle navigation local frame = RMP.Frame.new() frame:addEventListener(RMP.EventType.Keyboard, function(key) if key == RMP.KEY_UP then scroller:prevLine() elseif key == RMP.KEY_DOWN then scroller:nextLine() elseif key == RMP.KEY_ENTER then local selected_file = files[scroller:getCursorPosition()] if not selected_file.is_file then -- Navigate to directory path:setPath( path:getPath() .. "/" .. selected_file.name ) -- Refresh file list... end end end) -- Render file browser local vterm = RMP.VirtualTerminal.new() while true do vterm:clear() -- Draw current path vterm:writeText( 1, 1, "Path: " .. path:getPath(), RMP.FGColors.Brights.Cyan ) -- Draw file list local visible_items = scroller:getVisible() for i, item in ipairs(visible_items) do vterm:writeText( 3, 3 + i, item.text, item.fg, item.bg, item.style ) end vterm:render() local key = RMP.Terminal:handleKey() frame:run(key, nil, nil) end