xref: /freebsd/stand/lua/screen.lua (revision a6cf4be0421c1df870218105ce590203c285b5a2)
1088b4f5fSWarner Losh--
272e39d71SKyle Evans-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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-- $FreeBSD$
29088b4f5fSWarner Losh--
30088b4f5fSWarner Losh
31aedd6be5SKyle Evanslocal color = require("color")
32aedd6be5SKyle Evanslocal core = require("core")
33088b4f5fSWarner Losh
34aedd6be5SKyle Evanslocal screen = {}
351f5696c7SKyle Evans
36b5746545SKyle Evans-- Module exports
37ed1d0954SKyle Evansscreen.default_x = 0
38ed1d0954SKyle Evansscreen.default_y = 25
39ed1d0954SKyle Evans
40088b4f5fSWarner Loshfunction screen.clear()
41223e9874SKyle Evans	printc(core.KEYSTR_CSI .. "H" .. core.KEYSTR_CSI .. "J")
42088b4f5fSWarner Loshend
43088b4f5fSWarner Losh
44088b4f5fSWarner Loshfunction screen.setcursor(x, y)
45223e9874SKyle Evans	printc(core.KEYSTR_CSI .. y .. ";" .. x .. "H")
46088b4f5fSWarner Loshend
47088b4f5fSWarner Losh
485495d73cSKyle Evansfunction screen.setforeground(color_value)
499f71d421SKyle Evans	if color.disabled then
50*a6cf4be0SKyle Evans		return
51088b4f5fSWarner Losh	end
528ce1744fSKyle Evans	printc(color.escapefg(color_value))
53088b4f5fSWarner Loshend
54088b4f5fSWarner Losh
555495d73cSKyle Evansfunction screen.setbackground(color_value)
569f71d421SKyle Evans	if color.disabled then
57*a6cf4be0SKyle Evans		return
58088b4f5fSWarner Losh	end
598ce1744fSKyle Evans	printc(color.escapebg(color_value))
60088b4f5fSWarner Loshend
61088b4f5fSWarner Losh
62088b4f5fSWarner Loshfunction screen.defcolor()
63223e9874SKyle Evans	printc(color.default())
64088b4f5fSWarner Loshend
65088b4f5fSWarner Losh
66088b4f5fSWarner Loshfunction screen.defcursor()
67ed1d0954SKyle Evans	screen.setcursor(screen.default_x, screen.default_y)
68088b4f5fSWarner Loshend
69088b4f5fSWarner Losh
70aedd6be5SKyle Evansreturn screen
71