xref: /freebsd/stand/lua/screen.lua (revision 604919c47fa4092db08dadd282851afc9cba0a90)
1088b4f5fSWarner Losh--
24d846d26SWarner Losh-- SPDX-License-Identifier: BSD-2-Clause
372e39d71SKyle Evans--
4088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5088b4f5fSWarner Losh-- All rights reserved.
6088b4f5fSWarner Losh--
7088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without
8088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions
9088b4f5fSWarner Losh-- are met:
10088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright
11088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer.
12088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright
13088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer in the
14088b4f5fSWarner Losh--    documentation and/or other materials provided with the distribution.
15088b4f5fSWarner Losh--
16088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19088b4f5fSWarner Losh-- ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26088b4f5fSWarner Losh-- SUCH DAMAGE.
27088b4f5fSWarner Losh--
28088b4f5fSWarner Losh
29aedd6be5SKyle Evanslocal color = require("color")
30aedd6be5SKyle Evanslocal core = require("core")
31088b4f5fSWarner Losh
32aedd6be5SKyle Evanslocal screen = {}
331f5696c7SKyle Evans
34b5746545SKyle Evans-- Module exports
35*604919c4SWarner Loshscreen.default_x = 1
36ed1d0954SKyle Evansscreen.default_y = 25
37ed1d0954SKyle Evans
38088b4f5fSWarner Loshfunction screen.clear()
39223e9874SKyle Evans	printc(core.KEYSTR_CSI .. "H" .. core.KEYSTR_CSI .. "J")
40088b4f5fSWarner Loshend
41088b4f5fSWarner Losh
42088b4f5fSWarner Loshfunction screen.setcursor(x, y)
43223e9874SKyle Evans	printc(core.KEYSTR_CSI .. y .. ";" .. x .. "H")
44088b4f5fSWarner Loshend
45088b4f5fSWarner Losh
465495d73cSKyle Evansfunction screen.setforeground(color_value)
479f71d421SKyle Evans	if color.disabled then
48a6cf4be0SKyle Evans		return
49088b4f5fSWarner Losh	end
508ce1744fSKyle Evans	printc(color.escapefg(color_value))
51088b4f5fSWarner Loshend
52088b4f5fSWarner Losh
535495d73cSKyle Evansfunction screen.setbackground(color_value)
549f71d421SKyle Evans	if color.disabled then
55a6cf4be0SKyle Evans		return
56088b4f5fSWarner Losh	end
578ce1744fSKyle Evans	printc(color.escapebg(color_value))
58088b4f5fSWarner Loshend
59088b4f5fSWarner Losh
60088b4f5fSWarner Loshfunction screen.defcolor()
61223e9874SKyle Evans	printc(color.default())
62088b4f5fSWarner Loshend
63088b4f5fSWarner Losh
64088b4f5fSWarner Loshfunction screen.defcursor()
65ed1d0954SKyle Evans	screen.setcursor(screen.default_x, screen.default_y)
66088b4f5fSWarner Loshend
67088b4f5fSWarner Losh
68aedd6be5SKyle Evansreturn screen
69