Changeset 31225 in project

08/17/14 21:55:17 (6 years ago)

Anonymous wiki edit for IP []:

1 edited


  • wiki/eggref/4/termbox

    r31223 r31225  
     19=== Example
     21<enscript highlight="scheme">
     22(use termbox)
     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)))))
     30;; Initialise termbox
     33;; Needed to stop the script when a key is pressed.
     34(define running (make-parameter #t))
     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))
     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)
     45  ;; Present all made changes to the screen.
     46  (present)
     48  ;; Poll for events
     49  (poll (lambda (mod key ch)
     50          (cond
     52           ;; When enter is pressed, clear the screen to a random colour.
     53           ((eq? key key-enter) (clear black (random-colour)))
     55           ;; When escape is pressed stop the script.
     56           ((eq? key key-esc) (running #f))))
     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          ))
     63  ;; Continue running the loop when enter was not pressed.
     64  (when (running) (loop)))
     66;; Close termbox
    1970=== Documentation
    21 ==== Initialisation
     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)''.
     80''fg'' and ''bg'' can be a list starting with a colour
     81plus zero or more attributes: bold, underline or reversed.
     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)
     90==== Procedures
    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.
    27 <procedure>(init)</procedure></br>
    28 <procedure>(shutdown)</procedure></br>
     96finalized using the ''(shutdown)'' function.
     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)''.
     106<procedure>(clear [fg bg])</procedure></br>
     107Clears the interbal back buffer to specific foreground and background
     108color/attributes which default to ''color-default''
     111Syncronizes the internal back buffer with the terminal.
     113<procedure>(cursor-set! x y)</procedure></br>
     114Sets the position of the cursor. Upper-left character is (0, 0).
     117Hides the cursor. If ''(cursor-set!)'' is called after this the
     118cursor will be visible again. Cursor is hidden by default.
     121Changes cell's parameters in the internal back buffer at the specified
     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.
     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.
     133<procedure>(input-mode [mode])</procedure></br>
     134Sets the termbox input mode. Termbox has two input modes:</br>
     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.
     143Returns the current mode if node ''mode'' is given.
     145<procedure>(output-mode [mode])</procedure></br>
     146Sets the termbox output mode. Termbox has three output options:
     149* ''normal'' [1..8]:  This mode provides 8 different colors: black, red, green, yellow, blue, magenta, cyan, white.
     150Attributes: bold, underline, reversed
     153Example usage:
     154       (change_cell! x y #\@ (create-attribute color-black bold) red)
     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
     162Example usage:
     163       (change_cell! x y #\@ 184 240)
     164       (change_cell! x y #\@ #xb8 #xf0)
     166* ''216'' [0..216]: This mode supports the 3rd range of the 256 mode only. But you dont need to provide an offset.
     168* ''grayscale'' [0..23]: This mode supports the 4th range of the 256 mode only. But you dont need to provide an offset.
     171Returns the current mode if node ''mode'' is given.
     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) ...).
     181==== Constants
     183===== Keys
     253===== Key modifiers
     257===== Colours
     268===== Attributes
Note: See TracChangeset for help on using the changeset viewer.