1088b4f5fSWarner Losh-- 2088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3088b4f5fSWarner Losh-- All rights reserved. 4088b4f5fSWarner Losh-- 5088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 6088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 7088b4f5fSWarner Losh-- are met: 8088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 9088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 10088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 11088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 12088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 13088b4f5fSWarner Losh-- 14088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24088b4f5fSWarner Losh-- SUCH DAMAGE. 25088b4f5fSWarner Losh-- 26088b4f5fSWarner Losh-- $FreeBSD$ 27088b4f5fSWarner Losh-- 28088b4f5fSWarner Losh 29088b4f5fSWarner Loshlocal screen = {}; 30088b4f5fSWarner Losh 31088b4f5fSWarner Loshlocal color = require("color"); 32088b4f5fSWarner Loshlocal core = require("core"); 33088b4f5fSWarner Losh 34*901d96e3SKyle Evans-- XXX TODO: This should be fixed in the interpreter to not print decimals 35*901d96e3SKyle Evansfunction intstring(num) 36*901d96e3SKyle Evans local str = tostring(num) 37*901d96e3SKyle Evans local decimal = string.find(str, "[.]") 38*901d96e3SKyle Evans 39*901d96e3SKyle Evans if decimal then 40*901d96e3SKyle Evans return string.sub(str, 1, decimal - 1) 41*901d96e3SKyle Evans end 42*901d96e3SKyle Evans return str 43*901d96e3SKyle Evansend 44*901d96e3SKyle Evans 45088b4f5fSWarner Loshfunction screen.clear() 46088b4f5fSWarner Losh if core.bootserial() then 47088b4f5fSWarner Losh return; 48088b4f5fSWarner Losh end 49088b4f5fSWarner Losh loader.printc("\027[H\027[J"); 50088b4f5fSWarner Loshend 51088b4f5fSWarner Losh 52088b4f5fSWarner Loshfunction screen.setcursor(x, y) 53088b4f5fSWarner Losh if core.bootserial() then 54088b4f5fSWarner Losh return; 55088b4f5fSWarner Losh end 56*901d96e3SKyle Evans 57*901d96e3SKyle Evans loader.printc("\027["..intstring(y)..";"..intstring(x).."H"); 58088b4f5fSWarner Loshend 59088b4f5fSWarner Losh 60088b4f5fSWarner Loshfunction screen.setforeground(c) 61088b4f5fSWarner Losh if color.disabled then 62088b4f5fSWarner Losh return c; 63088b4f5fSWarner Losh end 64088b4f5fSWarner Losh loader.printc("\027[3"..c.."m"); 65088b4f5fSWarner Loshend 66088b4f5fSWarner Losh 67088b4f5fSWarner Loshfunction screen.setbackground(c) 68088b4f5fSWarner Losh if color.disabled then 69088b4f5fSWarner Losh return c; 70088b4f5fSWarner Losh end 71088b4f5fSWarner Losh loader.printc("\027[4"..c.."m"); 72088b4f5fSWarner Loshend 73088b4f5fSWarner Losh 74088b4f5fSWarner Loshfunction screen.defcolor() 75088b4f5fSWarner Losh loader.printc(color.default()); 76088b4f5fSWarner Loshend 77088b4f5fSWarner Losh 78088b4f5fSWarner Loshfunction screen.defcursor() 79088b4f5fSWarner Losh if core.bootserial() then 80088b4f5fSWarner Losh return; 81088b4f5fSWarner Losh end 82088b4f5fSWarner Losh loader.printc("\027[25;0H"); 83088b4f5fSWarner Loshend 84088b4f5fSWarner Losh 85088b4f5fSWarner Loshreturn screen 86