Skip to content

Commit

Permalink
Implement POSIX Curses Soft Label Key functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
roy authored and rofl0r committed Feb 19, 2017
1 parent 35699f1 commit 9423d34
Show file tree
Hide file tree
Showing 25 changed files with 1,176 additions and 13 deletions.
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ CU_SRCS_=acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
printw.c putchar.c refresh.c resize.c scanw.c screen.c scroll.c \
scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \
tstp.c tty.c unctrl.c underscore.c immedok.c syncok.c ripoffline.c
tstp.c tty.c unctrl.c underscore.c immedok.c syncok.c ripoffline.c \
slk.c


ifndef DISABLE_WCHAR
Expand Down
16 changes: 12 additions & 4 deletions libcurses/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.83 2017/01/11 20:43:03 roy Exp $
# $NetBSD: Makefile,v 1.84 2017/01/24 17:27:30 roy Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94

.include <bsd.own.mk>
Expand All @@ -23,7 +23,7 @@ SRCS= acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
insertln.c instr.c keypad.c keyname.c leaveok.c line.c meta.c move.c \
mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
printw.c putchar.c refresh.c resize.c ripoffline.c scanw.c screen.c \
scroll.c scrollok.c setterm.c standout.c syncok.c timeout.c \
scroll.c scrollok.c setterm.c slk.c standout.c syncok.c timeout.c \
toucholap.c touchwin.c tstp.c tty.c unctrl.c underscore.c

MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
Expand All @@ -34,8 +34,8 @@ MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
curses_inch.3 curses_input.3 curses_insertch.3 curses_insertln.3 \
curses_insdelln.3 curses_keyname.3 curses_line.3 curses_pad.3 \
curses_print.3 curses_refresh.3 curses_scanw.3 curses_screen.3 \
curses_scroll.3 curses_standout.3 curses_termcap.3 curses_touch.3 \
curses_tty.3 curses_underscore.3 curses_window.3
curses_scroll.3 curses_slk.3 curses_standout.3 curses_termcap.3 \
curses_touch.3 curses_tty.3 curses_underscore.3 curses_window.3
INCS= curses.h unctrl.h
INCSDIR=/usr/include

Expand Down Expand Up @@ -150,6 +150,14 @@ MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \
curses_cursor.3 setsyx.3 \
curses_input.3 set_escdelay.3 curses_screen.3 set_tabsize.3 \
curses_screen.3 set_term.3 curses_screen.3 setterm.3 \
curses_slk.3 slk_attroff.3 curses_slk.3 slk_attr_off.3 \
curses_slk.3 slk_attron.3 curses_slk.3 slk_attr_on.3 \
curses_slk.3 slk_attrset.3 curses_slk.3 slk_attr_set.3 \
curses_slk.3 slk_clear.3 curses_slk.3 slk_color.3 \
curses_slk.3 slk_init.3 curses_slk.3 slk_label.3 \
curses_slk.3 slk_noutrefresh.3 curses_slk.3 slk_refresh.3 \
curses_slk.3 slk_restore.3 curses_slk.3 slk_set.3 \
curses_slk.3 slk_touch.3 curses_slk.3 slk_wset.3 \
curses_standout.3 standend.3 curses_standout.3 standout.3 \
curses_color.3 start_color.3 curses_pad.3 subpad.3 \
curses_window.3 subwin.3 curses_touch.3 syncok.3 \
Expand Down
20 changes: 19 additions & 1 deletion libcurses/curses.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: curses.h,v 1.120 2017/01/10 10:13:24 roy Exp $ */
/* $NetBSD: curses.h,v 1.121 2017/01/24 17:27:30 roy Exp $ */

/*
* Copyright (c) 1981, 1993, 1994
Expand Down Expand Up @@ -920,6 +920,24 @@ int wchgat(WINDOW *, int, attr_t, short, const void *);
int mvchgat(int, int, int, attr_t, short, const void *);
int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *);

/* Soft Label Keys. */
int slk_attroff(const chtype);
int slk_attr_off(const attr_t, void *);
int slk_attron(const chtype);
int slk_attr_on(const attr_t, void *);
int slk_attrset(const chtype);
int slk_attr_set(const attr_t, short, void *);
int slk_clear(void);
int slk_color(short);
int slk_init(int);
char *slk_label(int);
int slk_noutrefresh(void);
int slk_refresh(void);
int slk_restore(void);
int slk_set(int, const char *, int);
int slk_touch(void);
int slk_wset(int, const wchar_t *, int);

/* wide-character support routines */
/* return ERR when HAVE_WCHAR is not defined */
/* add */
Expand Down
35 changes: 34 additions & 1 deletion libcurses/curses_private.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: curses_private.h,v 1.59 2017/01/11 20:43:03 roy Exp $ */
/* $NetBSD: curses_private.h,v 1.60 2017/01/24 17:27:30 roy Exp $ */

/*-
* Copyright (c) 1998-2000 Brett Lymn
Expand Down Expand Up @@ -190,6 +190,22 @@ struct __pair {

typedef struct keymap keymap_t;

/* POSIX allows up to 8 columns in a label. */
#define MAX_SLK_COLS 8
#ifdef HAVE_WCHAR
#define MAX_SLK_LABEL sizeof(wchar_t) * MAX_SLK_COLS
#else
#define MAX_SLK_LABEL MAX_SLK_COLS
#endif
struct __slk_label {
char *text;
int justify;
#define SLK_JUSTIFY_LEFT 0
#define SLK_JUSTIFY_CENTER 1
#define SLK_JUSTIFY_RIGHT 2
char label[MAX_SLK_LABEL + 1];
int x;
};

#define MAX_RIPS 5
struct __ripoff {
Expand Down Expand Up @@ -269,6 +285,18 @@ struct __screen {
int unget_len, unget_pos;
int filtered;
int checkfd;

/* soft label key */
bool is_term_slk;
WINDOW *slk_window;
int slk_format;
#define SLK_FMT_3_2_3 0
#define SLK_FMT_4_4 1
int slk_nlabels;
int slk_label_len;
bool slk_hidden;
struct __slk_label *slk_labels;

#ifdef HAVE_WCHAR
#ifndef MB_LEN_MAX
#define MB_LEN_MAX 8
Expand Down Expand Up @@ -360,6 +388,10 @@ void __set_color(WINDOW *win, attr_t attr);
void __set_stophandler(void);
void __set_winchhandler(void);
void __set_subwin(WINDOW *, WINDOW *);
int __slk_init(SCREEN *);
void __slk_free(SCREEN *);
int __slk_resize(SCREEN *, int cols);
int __slk_noutrefresh(SCREEN *);
void __startwin(SCREEN *);
void __stop_signal_handler(int);
int __stopwin(void);
Expand All @@ -368,6 +400,7 @@ void __sync(WINDOW *);
int __timeout(int);
int __touchline(WINDOW *, int, int, int);
int __touchwin(WINDOW *);
int __unripoffline(int (*)(WINDOW *, int));
void __unsetattr(int);
void __unset_color(WINDOW *win);
int __waddch(WINDOW *, __LDATA *);
Expand Down
244 changes: 244 additions & 0 deletions libcurses/curses_slk.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
.\" $NetBSD: curses_slk.3,v 1.1 2017/01/24 17:27:30 roy Exp $
.\"
.\" Copyright (c) 2017 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Roy Marples.
.\"
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.\"
.Dd January 12, 2017
.Dt CURSES_SLK 3
.Os
.Sh NAME
.Nm slk_attroff ,
.Nm slk_attr_off ,
.Nm slk_attron ,
.Nm slk_attr_on ,
.Nm slk_attrset ,
.Nm slk_attr_set ,
.Nm slk_clear ,
.Nm slk_color ,
.Nm slk_init ,
.Nm slk_label ,
.Nm slk_noutrefresh ,
.Nm slk_refresh ,
.Nm slk_restore ,
.Nm slk_set ,
.Nm slk_touch ,
.Nm slk_wset
.Nd Curses soft label key routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn slk_attroff "const chtype attr"
.Ft int
.Fn slk_attr_off "const attr_t attr" "void *opt"
.Ft int
.Fn slk_attron "const chtype attr"
.Ft int
.Fn slk_attr_on "const attr_t attr" "void *opt"
.Ft int
.Fn slk_attrset "const chtype attr"
.Ft int
.Fn slk_attr_set "const attr_t attr" "void *opt"
.Ft void
.Fn slk_clear "void"
.Ft int
.Fn slk_color "short pair"
.Ft int
.Fn slk_init "int fmt"
.Ft char *
.Fn slk_label "int labnum"
.Ft int
.Fn slk_noutrefresh "void"
.Ft int
.Fn slk_refresh "void"
.Ft int
.Fn slk_restore "void"
.Ft int
.Fn slk_set "int labnum" "const char *label" "int justify"
.Ft int
.Fn slk_touch "void"
.Ft int
.Fn slk_wset "int labnum" "const wchar_t *label" "int justify"
.Sh DESCRIPTION
This Curses interface manipulates the set of soft function-key labels that
exist on some terminals.
For those terminals that do not have soft labels, Curses takes over the bottom
line of
.Dv stdstr ,
reducing the size of
.Dv stdscr
and the value of the
.Dv LINES
external variable.
There can be up to eight labels of up to eight display columns each.
.Pp
To use soft labels,
.Fn slk_init
must be called before
.Xr initscr 3 ,
.Xr newterm 3 ,
or
.Xr ripoffline 3
is called.
If
.Xr newterm 3
eventually uses a line from
.Dv stdscr
to emulate the soft labels, then
.Fa fmt
determines how the labels are arranged on the screen from the following list:
.Bl -tag -width ERR -compact
.It 0
indicates a 3-2-3 arrangement.
.It 1
indicates a 4-4 arrangement.
.El
.Pp
The
.Fn slk_set
and
.Fn slk_wset
functions specify the text of soft label number
.Fa labnum ,
within the range from 1 to 8 inclusive.
The
.Fa label
argument is the string to be put on the label.
The
.Fa justify
argument can have the following values to indicate how to justify
.Fa label
within the space reserved for it:
.Bl -tag -width ERR -compact
.It 0
Left align.
.It 1
Center align.
.It 2
Right align.
.El
.Pp
The
.Fn slk_refresh
and
.Fn slk_noutrefresh
functions correspond to the
.Xr wrefresh 3
and
.Xr wnoutrefresh 3
functions.
.Pp
The
.Fn slk_label
function returns a pointer to the text displayed in the label.
.Pp
The
.Fn slk_clear
function immediately clears the soft labels from the screen.
.Pp
The
.Fn slk_restore
function immediately restores the soft labels to the screen after a call to
.Fn slk_clear .
.Pp
The
.Fn slk_touch
function forces all soft labels to be output the next time
.Fn slk_noutrefresh
or
.Fn slk_refresh
is called.
.Pp
The
.Fn slk_attron ,
.Fn slk_attrset
and
.Fn slk_attroff
functions correspond to
.Xr attron 3 ,
.Xr attrset 3
and
.Xr attroff 3 .
The have an effect only if soft labels are simulated on the bottom line of the
screen.
.Pp
The
.Fn slk_attr_on ,
.Fn slk_attr_set ,
.Fn slk_color
and
.Fn slk_attr_off
functions correspond to
.Xr attr_on 3 ,
.Xr attr_set 3 ,
.Xr color_set 3
and
.Xr attr_off 3
and thus support the attribute constants with the WA_ prefix and color.
The have an effect only if soft labels are simulated on the bottom line of the
screen.
.Pp
The
.Fa opt
argument is reserved for future use.
Currently the application must provide a NULL pointer as
.Fa opt .
.Sh RETURN VALUES
Functions returning pointers will return
.Dv NULL
if an error is detected.
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr terminfo 5
.Sh NOTES
This has not been tested on a terminal with real soft label keys.
.Dv label_height ,
.Dv label_width ,
.Dv label_format
and
.Dv lab_f*
are currently not used.
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .
The soft label key functions were added in
.Nx 8.0 .
Loading

0 comments on commit 9423d34

Please sign in to comment.