Next: , Previous: , Up: Output functions   [Contents][Index]


4.6.1 The addch procedure

The addch function puts a single rendered character into the current cursor location and advances the position of the cursor. Attributes are explained in detail in later sections of the document. If a character is associated with an attribute (bold, reverse video, etc.), when curses prints the character, it is printed with that rendition.

In order to combine a character with some attributes, you have two options:

  1. You can explicitly construct a rendered character by passing a simple character through the rendition functions for the desired attributes:
    (bold #\x)
    (blink-on (bold-on #\x))
    (color 2 #\x)
    
  2. By using functions like attr-set!, attr-on!, attr-off!, you can manipulate the current attributes of the given window. Once set, the characters printed in the window are associated with the attributes until it is turned off.

Additionally, curses provides some special characters for character-based graphics. You can draw tables, horizontal or vertical lines. Try looking for the procedures beginning with acs-.

4.6.1.1 Moving the cursor addch

The optional key parameters #:y y #:x x can be used to move the cursor to a given point, and then print. Thus the calls

(move stdscr row col)
(addch stdscr ch)

can be replaced by

(addch stdscr ch #:y row #:x col)

4.6.1.2 Complex characters and addch

There are really two version of the NCurses library: a standard version and a wide version. When guile ncurses was compiled, it was associated with either the standard version libncurses or the wide version libncursesw. The wide version has greater capability to print non-Latin characters than the standard version.

For every C function that operates on characters, there is a parallel function that operates on wide characters. The guile ncurses library hides all of that complexity, and presents the same API regardless of whether it used libncurses or libncursew.

At this point, a C programmer familiar with ncurses might be wondering how to call add-wch to print, for example, a Chinese character. The guile ncurses library abstracts both the C ncurses function addch and the C ncurses function add-wch as the Guile function addch.

So, if you version of Guile is capable of Unicode characters (such as Guile version 2.0.x), and if you version of NCurses is the wide version libncursesw, then you can use this library to print non-Latin characters.

First off, if you want to use wide characters, you need to call (setlocale LC_ALL "") before the call to initscr. The locale that is set must be an encoding that has greater than 8-bit characters, such as UTF-8. Also, you terminal must be capable of printing non-Latin characters.

Then, to add a rendered, complex character to the screen, use addch and friends as before

;; Bold U+041B Cyrillic Capital Letter El
(addch stdscr (bold #\Л))

Next: , Previous: , Up: Output functions   [Contents][Index]