# Some questions about console



## freethread (Aug 23, 2012)

I have some hard questions about consoles, both ttyvN and pts/N, and also some curses (system curses) functionality. I have to say that I still did not try them, the system is compiling and installing ports.

What I wish to do is to add key maps, that is shift+numpad keys (and also twins non numpad keys) in ttyvN consoles. I read termcap(5), kbdmap(5), atkbd(4), kbdcontrol(1) and the keybord map file I'm using /usr/share/syscons/keymaps/it.iso.kbd.

In that file I can define *fkeyN*s where N is a number from 65 to 96, that are spare, then assign them a string using the command

`# kbdcontrol -f N 'string'`

1. Is there any other way to specify that keys? That is, in some configuration file (rc.conf).

I never digged inside termcap and terminfo, so yesterday I take time to read at least termcap after looking at /etc/ttys, /etc/gettytab and /usr/share/misc/termcap. I understood few things, but... one is that a termcap entry must not exceed 1023 bytes and that *xterm*, *xterm-color*, *xterm-16color* both has 8 colors and this match with my curses test program.

In any *xterm*, both in ttyv and pts, the shift+numpad keys are not mapped, well in pts using my curses test program, they are trapped but not translated to KEY_xxx constants. I thought they can be inserted in termcap but perhaps the item will exceed the size limit, otherwise I can add them with the curses function [MAN=3X]define_key[/MAN] and it works as expected. However, in termcap database I read this in the comment:


```
# $XTermId: termcap,v 1.78 2009/11/09 00:24:26 tom Exp $
#
# Note:
#   termcap format is limited to 1023 characters.  This set of descriptions
#   is a subset of the terminfo, since not all features can be fit into
#   that limit.  The 'xterm' description supports color.  The monochrome
#   'xterm-mono' drops color in favor of additional function keys. [B][color="DarkOrange"]If you
#   need both, use terminfo[/color][/B].
# 
#   The 1023-character limit applies to each entry after resolving the
#   "tc=" strings.  Some implementations may discount all or part of the
#   formatting characters in the entry (i.e., the backslash newline tab
#   colon).  GNU termcap does not have this limit.
# 
#   I checked the limits using ncurses "captoinfo -CrTUvx", which prints
#   the resolved length of each entry in a comment at the end - T.*beep**beep**beep**beep*ey
```

2. How to use terminfo instead of termcap?

Last question is about system ncurses (v5.7) and multibyte/unicode translation. The [MAN=3X]get_wch[/MAN] function does not translate UTF-8 characters, i.e. pressing the 'Ã¬' char it give me 2 chars:


```
Key: M-C [195]
Key: M-, [172]
```

the function does not translate it in one call. I set the locale before to call [MAN=3X]initscr[/MAN] with


```
setlocale (LC_ALL, NULL);
```

and also with


```
setlocale (LC_ALL, "UTF-8");
```

3. Which is the right way to get UTF-8 chars to be translated in one get_wch (or getch) call?

Perhaps using terminfo instead of termcap resolves the troubles I run in th epast with devel/ncurses port.

Thanks for your help.


----------



## freethread (Aug 24, 2012)

The keybord mapping is done (at 99%). I set all new function keys in rc.conf in the variable *keychange*. Actually they are set as "s_keyname_" for the shift variant and "c_keyname_" for the ctrl variant (no shift+ctrl variant, not enough fn keys, but perhaps I can avoid mapping NumPad_5 key). The name must at least start with 'ESC' char, I'm trying to insert it as '\033', '\x1B' or whatever other way it works, it's not specified in rc.conf man page, in the while I check this part as solved. Pressing that new keys, the string is displayed in ttyv consoles.

In ncurses I'm still looking for a method to mapping that keys. In curses.h the key KEY_SUP, KEY_SDOWN and many others are not defined, also in the last version of ncurses downloaded from T. D!ckey site. I'm not compiled it, I looked inside the file include/Caps.keys, some definitions, if not all, are present but they has no value associated, perhaps I will have to ask to maintainers if I can assign any non clashing number to them.


----------

