Download PDF file (516K bytes)

Transcript
Chapter 4: Curses Tutorial
44
(move-field field top left)
The justification to be done for the field can be fixed using the function set-field-just!
(set-field-just! field justification)
The justification mode value is the either NO_JUSTIFICATION, JUSTIFY_RIGHT, JUSTIFY_
LEFT, or JUSTIFY_CENTER.
The procedure field-just returns the justification mode.
4.15.5 Field Display Attributes
As you have seen, in the above example, display attributes for the fields can be set with
set-field-fore! and set-field-back!. These functions set foreground and background
attributes of the fields. You can also specify a pad character that will be filled in the unfilled
portion of the field. The pad character is set with a call to set-field-pad!. Default pad
value is space. The functions field-fore , field-back, and field-pad can be used to
query the present foreground background attributes and pad character for the field.
Though the functions seem quite simple, using colors with set-field-fore! may be
frustrating in the beginning. Let me first explain about foreground and background attributes of a field. The foreground attribute is associated with the character. That means
a character in the field is printed with the attribute you have set with set-field-fore!.
Background attribute is the attribute used to fill background of field, whether any character
is there or not. So what about colors? Since colors are always defined in pairs, what is the
right way to display colored fields? Here’s an example clarifying color attributes.
#!/usr/bin/guile
!#
(use-modules (srfi srfi-1)
(ncurses curses)
(ncurses form))
;; Initialize curses
(define stdscr (initscr))
(start-color!)
(cbreak!)
(noecho!)
(keypad! stdscr #t)
;; Initialize the color pairs
(init-pair! 1 COLOR_WHITE COLOR_BLUE)
(init-pair! 2 COLOR_WHITE COLOR_BLUE)
;; Initialize the fields
(define field (list
(new-field 1 10 4 18 0 0)
(new-field 1 10 6 18 0 0)))
;; Set field options