Changeset 31225 in project


Ignore:
Timestamp:
08/17/14 21:55:17 (5 years ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [88.159.209.23]:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/termbox

    r31223 r31225  
    1717none
    1818
     19=== Example
     20
     21<enscript highlight="scheme">
     22(use termbox)
     23
     24;; Little function that gives a random colour.
     25(define (random-colour)
     26  (let ((colours
     27         (list black red green yellow blue magenta cyan white)))
     28    (list-ref colours (random (length colours)))))
     29
     30;; Initialise termbox
     31(init)
     32
     33;; Needed to stop the script when a key is pressed.
     34(define running (make-parameter #t))
     35
     36;; Create a list of cells of every character in the string "Hello world !!!!!!"
     37;; all with a black underlined foreground and a yellow background.
     38(define cells (create-cells "Hello world !!!!!!" (black underline) yellow))
     39
     40(let loop ()
     41  ;; Blit all the cells of the string "Hello world !!!!!!"
     42  ;; at position (5 5) inside a box with a size of (6 3).
     43  (blit 5 5 6 3 cells)
     44
     45  ;; Present all made changes to the screen.
     46  (present)
     47
     48  ;; Poll for events
     49  (poll (lambda (mod key ch)
     50          (cond
     51
     52           ;; When enter is pressed, clear the screen to a random colour.
     53           ((eq? key key-enter) (clear black (random-colour)))
     54
     55           ;; When escape is pressed stop the script.
     56           ((eq? key key-esc) (running #f))))
     57
     58        (lambda (w h)
     59          ;; When screen is resized, print the screensize at the top-left corner
     60          (bprintf 0 0 black white "screen size ~a, ~a" w h)
     61          ))
     62
     63  ;; Continue running the loop when enter was not pressed.
     64  (when (running) (loop)))
     65
     66;; Close termbox
     67(shutdown)
     68</enscript>
     69
    1970=== Documentation
    2071
    21 ==== Initialisation
    22 
     72==== Syntax
     73<syntax>(create-cell char fg bg)</syntax><br/>
     74<syntax>(create-cell char (fg attributes ...) bg)</syntax><br/>
     75Creates a cell containing a character with specific foreground and
     76background colours/attributes. These can then be put on screen with
     77the functions ''(put-cell!)'' or ''(blit)''.
     78
     79
     80''fg'' and ''bg'' can be a list starting with a colour
     81plus zero or more attributes: bold, underline or reversed.
     82
     83
     84Example:
     85        ; Create a letter ''H'' with black text and a white background.
     86        (create-cell #\H black white)
     87        ; Create a letter ''H'' with black underlines text and a white background.
     88        (create-cell #\H (create-attributes (black underline) white)
     89
     90==== Procedures
     91
     92<procedure>(init)</procedure></br>
     93<procedure>(shutdown)</procedure></br>
    2394Initializes the termbox library. This function should be called before any
    2495other functions. After successful initialization, the library must be
    25 finalized using the ``(shutdown)`` function.
    26 
    27 <procedure>(init)</procedure></br>
    28 <procedure>(shutdown)</procedure></br>
     96finalized using the ''(shutdown)'' function.
     97
     98<procedure>(width)</procedure></br>
     99<procedure>(height)</procedure></br>
     100Returns the size of the internal back buffer (which is the same as
     101terminal's window size in characters). The internal buffer can be resized
     102after ''(clear)'' or ''(present)'' function calls. Both dimensions have an
     103unspecified negative value when called before ''(init)'' or after ''(shutdown)''.
     104
     105
     106<procedure>(clear [fg bg])</procedure></br>
     107Clears the interbal back buffer to specific foreground and background
     108color/attributes which default to ''color-default''
     109
     110<procedure>(present)</procedure></br>
     111Syncronizes the internal back buffer with the terminal.
     112
     113<procedure>(cursor-set! x y)</procedure></br>
     114Sets the position of the cursor. Upper-left character is (0, 0).
     115
     116<procedure>(hide-cursor!)</procedure></br>
     117Hides the cursor. If ''(cursor-set!)'' is called after this the
     118cursor will be visible again. Cursor is hidden by default.
     119
     120<procedure>(put-cell!)</procedure></br>
     121Changes cell's parameters in the internal back buffer at the specified
     122position.
     123
     124<procedure>(blit x y w h cells)</procedure></br>
     125Copies the buffer from 'cells' at the specified position, assuming the
     126buffer is a two-dimensional list of size ('w' x 'h'), represented as a
     127one-dimensional list containing lines of cells starting from the top.
     128
     129<procedure>(bprintf x y fg bg formatstring ... args)</procedure><br/>
     130Prints a formated string (like printf) at position (x y).
     131Using a specific foreground and background style.
     132
     133<procedure>(input-mode [mode])</procedure></br>
     134Sets the termbox input mode. Termbox has two input modes:</br>
     135
     136
     137* ''esc'' input mode: When ESC sequence is in the buffer and it doesn't match any known
     138ESC sequence.
     139* ''alt'' input mode: When ESC sequence is in the buffer and it doesn't match any known
     140sequence => ESC enables ''mod-alt'' modifier for the next keyboard event.
     141
     142
     143Returns the current mode if node ''mode'' is given.
     144
     145<procedure>(output-mode [mode])</procedure></br>
     146Sets the termbox output mode. Termbox has three output options:
     147
     148
     149* ''normal'' [1..8]:  This mode provides 8 different colors: black, red, green, yellow, blue, magenta, cyan, white.
     150Attributes: bold, underline, reversed
     151
     152
     153Example usage:
     154       (change_cell! x y #\@ (create-attribute color-black bold) red)
     155
     156* ''256'' [0..256]:  In this mode you can leverage the 256 terminal mode:
     157** 0x00 - 0x07: the 8 colors as in ''normal''
     158** 0x08 - 0x0f: (create-attribute colour-* bold)
     159** 0x10 - 0xe7: 216 different colors
     160** 0xe8 - 0xff: 24 different shades of grey
     161
     162Example usage:
     163       (change_cell! x y #\@ 184 240)
     164       (change_cell! x y #\@ #xb8 #xf0)
     165
     166* ''216'' [0..216]: This mode supports the 3rd range of the 256 mode only. But you dont need to provide an offset.
     167
     168* ''grayscale'' [0..23]: This mode supports the 4th range of the 256 mode only. But you dont need to provide an offset.
     169
     170
     171Returns the current mode if node ''mode'' is given.
     172
     173<procedure>(poll on-keypress on-resize)</procedure></br>
     174Waits until there is an event availiable. If there is it
     175will call, if it is a key event, ''on-keypress'' which must
     176be of form (lambda (mod key ch) ...).
     177If the event is a resize event it will kall ''on-resize'' which
     178must be of form (lambda (w h) ...).
     179
     180
     181==== Constants
     182
     183===== Keys
     184
     185<constant>key-f1</constant><br/>
     186<constant>key-f2</constant><br/>
     187<constant>key-f3</constant><br/>
     188<constant>key-f4</constant><br/>
     189<constant>key-f5</constant><br/>
     190<constant>key-f6</constant><br/>
     191<constant>key-f7</constant><br/>
     192<constant>key-f8</constant><br/>
     193<constant>key-f9</constant><br/>
     194<constant>key-f10</constant><br/>
     195<constant>key-f11</constant><br/>
     196<constant>key-f12</constant><br/>
     197<constant>key-insert</constant><br/>
     198<constant>key-delete</constant><br/>
     199<constant>key-home</constant><br/>
     200<constant>key-end</constant><br/>
     201<constant>key-pgup</constant><br/>
     202<constant>key-pgdn</constant><br/>
     203<constant>key-arrow-up</constant><br/>
     204<constant>key-arrow-down</constant><br/>
     205<constant>key-arrow-left</constant><br/>
     206<constant>key-arrow-right</constant><br/>
     207<constant>key-ctrl-tilde</constant><br/>
     208<constant>key-ctrl-2</constant><br/>
     209<constant>key-ctrl-a</constant><br/>
     210<constant>key-ctrl-b</constant><br/>
     211<constant>key-ctrl-c</constant><br/>
     212<constant>key-ctrl-d</constant><br/>
     213<constant>key-ctrl-e</constant><br/>
     214<constant>key-ctrl-f</constant><br/>
     215<constant>key-ctrl-g</constant><br/>
     216<constant>key-backspace</constant><br/>
     217<constant>key-ctrl-h</constant><br/>
     218<constant>key-tab</constant><br/>
     219<constant>key-ctrl-i</constant><br/>
     220<constant>key-ctrl-j</constant><br/>
     221<constant>key-ctrl-k</constant><br/>
     222<constant>key-ctrl-l</constant><br/>
     223<constant>key-enter</constant><br/>
     224<constant>key-ctrl-m</constant><br/>
     225<constant>key-ctrl-n</constant><br/>
     226<constant>key-ctrl-o</constant><br/>
     227<constant>key-ctrl-p</constant><br/>
     228<constant>key-ctrl-q</constant><br/>
     229<constant>key-ctrl-r</constant><br/>
     230<constant>key-ctrl-s</constant><br/>
     231<constant>key-ctrl-t</constant><br/>
     232<constant>key-ctrl-u</constant><br/>
     233<constant>key-ctrl-v</constant><br/>
     234<constant>key-ctrl-w</constant><br/>
     235<constant>key-ctrl-x</constant><br/>
     236<constant>key-ctrl-y</constant><br/>
     237<constant>key-ctrl-z</constant><br/>
     238<constant>key-esc</constant><br/>
     239<constant>key-ctrl-lsq-bracket</constant><br/>
     240<constant>key-ctrl-3</constant><br/>
     241<constant>key-ctrl-4</constant><br/>
     242<constant>key-ctrl-backslash</constant><br/>
     243<constant>key-ctrl-5</constant><br/>
     244<constant>key-ctrl-rsq-bracket</constant><br/>
     245<constant>key-ctrl-6</constant><br/>
     246<constant>key-ctrl-7</constant><br/>
     247<constant>key-ctrl-slash</constant><br/>
     248<constant>key-ctrl-underscore</constant><br/>
     249<constant>key-space</constant><br/>
     250<constant>key-backspace2</constant><br/>
     251<constant>key-ctrl-8</constant><br/>
     252
     253===== Key modifiers
     254
     255<constant>d-alt</constant><br/>
     256
     257===== Colours
     258
     259<constant>black</constant><br/>
     260<constant>red</constant><br/>
     261<constant>green</constant><br/>
     262<constant>yellow</constant><br/>
     263<constant>blue</constant><br/>
     264<constant>magenta</constant><br/>
     265<constant>cyan</constant><br/>
     266<constant>white</constant><br/>
     267
     268===== Attributes
     269
     270<constant>bold</constant><br/>
     271<constant>underline</constant><br/>
     272<constant>reversed</constant><br/>
Note: See TracChangeset for help on using the changeset viewer.