Terminal-based UI Framework with Audio Playback - API v1.0.0
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.
Copyright © 2024-2025 Ray Den. Licensed under the MIT License.
Advanced table management class for data manipulation.
Text rendering and styling class with position control.
Window management with borders, titles, and callbacks.
Core virtual terminal for rendering and event handling.
Comprehensive audio playback and playlist management.
User text input handling with cursor management.
Interactive option menu system with selection tracking.
Modal dialog system for notifications and messages.
Content scrolling mechanism for large lists.
Drawing primitives for shapes and graphics.
Terminal manipulation and cursor control.
Event handling system for user interactions.
File system operations and path manipulation.
Configuration management with cross-platform support.
High-level frame management with FPS control.
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