Skip to content

Latest commit

 

History

History
86 lines (60 loc) · 1.81 KB

readme.md

File metadata and controls

86 lines (60 loc) · 1.81 KB

Luabox

Luabox is a rewrite of Termion for Lua using Luv.

Features

  • Raw mode
  • TrueColor
  • Special key event support (modifiers, special keys)
  • Async I/O
  • Mouse support
  • And more!

Installation

[sudo] luarocks install luabox
[sudo] luarocks install luabitop # For Lua versions >5.3

Quick example

This quick example shows how you can use mouse support to plot points on your terminal.

local box = require('luabox')

local util = box.util
local event = box.event
local clear = box.clear
local cursor = box.cursor

local f = string.format

local stdin, stdout = util.getHandles()

local console = box.Console.new(stdin, stdout)

console:setMode(1)
console:intoMouseMode()

console:write(f('%s%s', cursor.hide, clear.all))

console.onData = function(data)
   local first
   local rest = {}

   for char in data:gmatch('.') do
      if not first then
         first = char
      else
         table.insert(rest, char)
      end
   end

   local iter = util.StringIterator(table.concat(rest))

   local keyData = event.parse(first, iter)

   if keyData.key == 'ctrl' and keyData.char == 'c' then
      console:write(cursor.show)
      console:setMode(0)
      console:exitMouseMode()
      console:close()

      os.exit()
   elseif keyData.key == 'char' and keyData.char == 'c' then
      console:write(clear.all)
   elseif keyData.event and keyData.event ~= 'press' then
      local x, y = keyData.x, keyData.y

      console:write(f('%sX', cursor.goTo(x, y)))
   end
end

console.run()

For a larger example run tl run examples/minesweeper/main.tl. This example is a (terrible) clone of minesweeper.

You will need teal in-order to compile.

TODO

  • - Cleanup event.lua
  • - Write tests