apps/system/termcurses: Addition of termcurses libraries in apps/system/termcurses
This commit is contained in:
parent
25c0387c44
commit
fcd15d8786
35
system/termcurses/Kconfig
Normal file
35
system/termcurses/Kconfig
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
if SERIAL || TELNET
|
||||
|
||||
config SYSTEM_TERMCURSES
|
||||
bool "Terminal Curses control support"
|
||||
default n
|
||||
---help---
|
||||
Terminal emulation library for curses support on TTY type consoles
|
||||
such as serial port, CDCACM, telnet, etc.
|
||||
|
||||
config SYSTEM_TERMCURSES_VT100
|
||||
bool "Terminal pdcurses support for VT-100"
|
||||
depends on SYSTEM_TERMCURSES
|
||||
default y
|
||||
|
||||
config SYSTEM_TERMCURSES_VT100_OSX_ALT_CODES
|
||||
bool "Support Mac OSX ALT keycodes in vt100 emulation."
|
||||
depends on SYSTEM_TERMCURSES_VT100
|
||||
default y
|
||||
|
||||
config SYSTEM_TERMCURSES_DEBUG_KEYCODES
|
||||
bool "Print raw terminal escape sequences for debug."
|
||||
depends on SYSTEM_TERMCURSES
|
||||
default n
|
||||
|
||||
config SYSTEM_TERMCURSES_INCLUDE_TERMINFO_NAME
|
||||
bool "Compile in static const 'terminfo' key names (for future use)."
|
||||
depends on SYSTEM_TERMCURSES
|
||||
default n
|
||||
|
||||
endif # SYSTEM_TERMCURSES
|
38
system/termcurses/Make.defs
Normal file
38
system/termcurses/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# apps/system/termcurses/Make.defs
|
||||
#
|
||||
# Copyright (C) 2018 Ken Pettit. All rights reserved.
|
||||
# Author: Ken Pettit <pettitkd@gmail.com>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_SYSTEM_TERMCURSES),)
|
||||
CONFIGURED_APPS += system/termcurses
|
||||
endif
|
42
system/termcurses/Makefile
Normal file
42
system/termcurses/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
############################################################################
|
||||
# apps/system/termcurses/Makefile
|
||||
#
|
||||
# Copyright (C) 2018 Ken Pettit. All rights reserved.
|
||||
# Author: Ken Pettit <pettitkd@gmail.com>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
# Termcurses terminal emulation library
|
||||
|
||||
CSRCS = termcurses.c tcurses_vt100.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
51
system/termcurses/README.txt
Normal file
51
system/termcurses/README.txt
Normal file
@ -0,0 +1,51 @@
|
||||
Termcurses
|
||||
==========
|
||||
|
||||
Terminal emulation library for NuttX
|
||||
Author: Ken Pettit
|
||||
2018-2019
|
||||
|
||||
The Termcurses library provides terminal emulation support for performing common
|
||||
screen actions such as cursor movement, foreground / background color control
|
||||
and keyboard escape sequence mapping. The initial release supports only vt100 /
|
||||
ansi terminal types, but the library architecture has an extensible interface
|
||||
to allow support for additional emulation types if needed.
|
||||
|
||||
The library can be used standalone or in conjunction with the apps/graphics/pdcurses
|
||||
libraries. The pdcurses libraries have been updated with a "termcurses" config
|
||||
option which fully integrates the termcurses library automatically.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To use the termcurses library, the routines must be initialized by calling the
|
||||
termcurses_initterm() function. This routine accepts a terminal type string
|
||||
identifying the type of terminal emulation support requested. If a NULL pointer
|
||||
is passed, then the routine will check for a "TERM" environment variable and set
|
||||
the terminal type based on that string. If the emulation type still cannot be
|
||||
determined, the routine will default to "vt100" emulation type.
|
||||
|
||||
Upon successful initialization, the termcurses_initterm() function will allocate
|
||||
an new terminal context which must be passed with all future termcurses library
|
||||
functions. When this context is no longer needed, the termcurses_deinitterm()
|
||||
routine should be called for proper freeing and terminal teardown.
|
||||
|
||||
Use with telnetd
|
||||
================
|
||||
|
||||
When using termcurses with the telnet daemon, the telnet config option
|
||||
CONFIG_TELNET_SUPPORT_NAWS should be enabled. This option adds code to the
|
||||
telnet library for terminal size negotiation. Wihout this option, the telnet
|
||||
routines have no concept of the terminal size, and therefore the termcurses
|
||||
routines must default to 80x24 screen mode.
|
||||
|
||||
Use with pdcurses
|
||||
=================
|
||||
|
||||
When using the pdcurses termcurses support (i.e you have enabled both the
|
||||
CONFIG_PDCURSES and CONFIG_TERMCURSES options),, the pdcurses input device should
|
||||
be selected to be "TERMINPUT" (i.e. set CONFIG_PDCURSES_TERMINPUT=y). This
|
||||
causes the pdcurses keyboard input logic to use termcurses_getkeycode() routine
|
||||
for curses input.
|
||||
|
||||
|
59
system/termcurses/tcurses_priv.h
Normal file
59
system/termcurses/tcurses_priv.h
Normal file
@ -0,0 +1,59 @@
|
||||
/************************************************************************************
|
||||
* apps/system/termcurses/tcurses_priv.h
|
||||
*
|
||||
* Copyright (C) 2018 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __APPS_SYSTEM_TERMCURSES_TCURSES_PRIV_H
|
||||
#define __APPS_SYSTEM_TERMCURSES_TCURSES_PRIV_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <system/termcurses.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Type Definitions
|
||||
************************************************************************************/
|
||||
|
||||
extern struct termcurses_dev_s g_vt100_tcurs;
|
||||
|
||||
/************************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************************************/
|
||||
|
||||
#endif /* __APPS_SYSTEM_TERMCURSES_TCURSES_PRIV_H */
|
1085
system/termcurses/tcurses_vt100.c
Normal file
1085
system/termcurses/tcurses_vt100.c
Normal file
File diff suppressed because it is too large
Load Diff
274
system/termcurses/termcurses.c
Normal file
274
system/termcurses/termcurses.c
Normal file
@ -0,0 +1,274 @@
|
||||
/************************************************************************************
|
||||
* drivers/termcurses/termcurses.c
|
||||
*
|
||||
* Copyright (C) 2018 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "tcurses_priv.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
|
||||
static struct termcurses_dev_s *g_termcurses_devices[] =
|
||||
{
|
||||
#ifdef CONFIG_SYSTEM_TERMCURSES_VT100
|
||||
&g_vt100_tcurs,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_initterm
|
||||
*
|
||||
* Description:
|
||||
* Allocate and initialize a termcurses_s context based on the provided
|
||||
* term_type string. If the string is NULL, defaults to "vt100".
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_initterm(FAR const char *term_type, int in_fd, int out_fd,
|
||||
FAR struct termcurses_s **dev)
|
||||
{
|
||||
FAR struct termcurses_dev_s *pnext;
|
||||
int c;
|
||||
|
||||
/* Set term_type if NULL provided */
|
||||
|
||||
if (term_type == NULL)
|
||||
{
|
||||
/* Check the "TERM" env variable */
|
||||
|
||||
term_type = getenv("TERM");
|
||||
if (term_type == NULL)
|
||||
{
|
||||
/* Default to vt100 as a last resort */
|
||||
|
||||
term_type = (FAR const char *) "vt100";
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the selected term_type in the list of registered handlers */
|
||||
|
||||
c = 0;
|
||||
pnext = g_termcurses_devices[c];
|
||||
while (pnext != NULL)
|
||||
{
|
||||
/* Test if this item matches the selected term_type */
|
||||
|
||||
if (strstr(pnext->name, term_type) != NULL)
|
||||
{
|
||||
/* Allocate a new structure for this termcurses */
|
||||
|
||||
if (*dev == NULL)
|
||||
{
|
||||
/* Call the termcurses_dev init function */
|
||||
|
||||
*dev = pnext->ops->init(in_fd, out_fd);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* No match. Check next item in linked list */
|
||||
|
||||
pnext = g_termcurses_devices[++c];
|
||||
}
|
||||
|
||||
/* Not found! */
|
||||
|
||||
*dev = NULL;
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_deinitterm
|
||||
*
|
||||
* Description:
|
||||
* Free all space for the termcurses terminal and perform any specific
|
||||
* de-initialization tasks.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_deinitterm(FAR struct termcurses_s *dev)
|
||||
{
|
||||
struct termcurses_colors_s colors;
|
||||
|
||||
/* Ensure terminal has default color scheme */
|
||||
|
||||
colors.fg_red = 255;
|
||||
colors.fg_green = 255;
|
||||
colors.fg_blue = 255;
|
||||
colors.bg_red = 0;
|
||||
colors.bg_green = 0;
|
||||
colors.bg_blue = 0;
|
||||
colors.color_mask = 0xFF;
|
||||
termcurses_setcolors(dev, &colors);
|
||||
|
||||
/* For now, simply free the memory */
|
||||
|
||||
free(dev);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_moveyx
|
||||
*
|
||||
* Description:
|
||||
* Move to location yx (row,col) on terminal
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_moveyx(FAR struct termcurses_s *term, int row, int col)
|
||||
{
|
||||
FAR struct termcurses_dev_s *dev = (FAR struct termcurses_dev_s *) term;
|
||||
|
||||
/* Call the dev function */
|
||||
|
||||
if (dev->ops->move)
|
||||
{
|
||||
return dev->ops->move(term, TCURS_MOVE_YX, col, row);
|
||||
}
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_setcolors
|
||||
*
|
||||
* Description:
|
||||
* Configure output text to render in the specified fg/bg colors.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_setcolors(FAR struct termcurses_s *term,
|
||||
FAR struct termcurses_colors_s *colors)
|
||||
{
|
||||
FAR struct termcurses_dev_s *dev = (FAR struct termcurses_dev_s *) term;
|
||||
|
||||
/* Call the dev function */
|
||||
|
||||
if (dev->ops->setcolors)
|
||||
{
|
||||
return dev->ops->setcolors(term, colors);
|
||||
}
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_setattribute
|
||||
*
|
||||
* Description:
|
||||
* Configure output text to render in the specified fg/bg colors.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_setattribute(FAR struct termcurses_s *term, unsigned long attrib)
|
||||
{
|
||||
FAR struct termcurses_dev_s *dev = (FAR struct termcurses_dev_s *) term;
|
||||
|
||||
/* Call the dev function */
|
||||
|
||||
if (dev->ops->setattrib)
|
||||
{
|
||||
return dev->ops->setattrib(term, attrib);
|
||||
}
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_getwinsize
|
||||
*
|
||||
* Description:
|
||||
* Get size of terminal screen in terms of character rows and cols.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_getwinsize(FAR struct termcurses_s *term, FAR struct winsize *winsz)
|
||||
{
|
||||
FAR struct termcurses_dev_s *dev = (FAR struct termcurses_dev_s *) term;
|
||||
|
||||
/* Call the dev function */
|
||||
|
||||
if (dev->ops->getwinsize)
|
||||
{
|
||||
return dev->ops->getwinsize(term, winsz);
|
||||
}
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: termcurses_getkeycode
|
||||
*
|
||||
* Description:
|
||||
* Get a translated key code from the terminal input.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int termcurses_getkeycode(FAR struct termcurses_s *term, FAR int *specialkey,
|
||||
int *keymodifiers)
|
||||
{
|
||||
FAR struct termcurses_dev_s *dev = (FAR struct termcurses_dev_s *) term;
|
||||
|
||||
/* Call the dev function */
|
||||
|
||||
if (dev->ops->getkeycode)
|
||||
{
|
||||
return dev->ops->getkeycode(term, specialkey, keymodifiers);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user