Giter VIP home page Giter VIP logo

luabox's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.