You are looking at historical revision 23921 of this page. It may differ significantly from its current revision.
Mojo ist a high-level API for the infamous ncurses library. It's fairly incomplete but does a few useful things already so that it may be interesting to others. As a real world example see the Chicken implementation of the board game kalaha which is based on Mojo.
Mojo basically provides a window layout API (window as in ncurses WINDOW), i.e. it allows specifying dimensions and relations of windows in relative and absolute terms. Everything else (like displaying text, coloring etc.) has to be done through the low-level ncurses API at the time being.
General[procedure] (initialize #!key temrinal)
Initializes terminal for ncurses operation. By default this is the terminal connected to (current-output-port). Usually this procedure has to be called once before the program's main loop.[procedure] (redraw)
Draws all Mojo windows. This should usually be called at the beginning of the program's main loop.[parameter] width
The current terminal width.[parameter] height
The current terminal height.[procedure] (get-char)
Reads a character using ncurses' getch and implicitly handles KEY_RESIZE.
Windows in Mojo are represented as coops objects.[class] <win>
This is the class that represents a Mojo window. It has the following public slots:
- the distance from the left
- the distance from the right
- the distance from the top
- the distance from the bottom
- the ncurses window pointer
[procedure] (win-right win)
[procedure] (win-top win)
[procedure] (win-bottom win)
[procedure] (win-pointer win)
Accessors for the respective <win> slots.[procedure] (make-win #!key width height left right top bottom left-of right-of below above box background)
Convenience constructor function so you don't have to (use coops) in your program to create window objects.
box is a boolean indicating whether to draw a border box around the window. The default is #t.
background is a boolean indicating whether to fill the window's background with the foreground color. It does not work very well. The default is #f.
All other arguments are used for specifying dimension, position and relation of the window. In the simplest case, a width and a height is given as well as absolute top/bottom and left/right positions:
(make-win width: 10 height: 5 left: 2 top: 2)
However, almost all combinations are possible, e.g. one could leave out the width and only specify the positions from the left and right borders of the terminal. This will result in a variable width window that is resized when the terminal is resized, maintaining its distance from the left and right borders:
(make-win height: 5 top: 2 left: 2 right: 2)
The left-of, right-of, above and below arguments can take other windows as values. All positions and distances are then relative to the outer borders of that window. For example:
(define foo (make-win width: 2 height: 1 left: 2 top: 2)) (define bar (make-win right-of: foo width: 2 height: 1 left 1))
This will draw bar on the right of foo with 1 unit distance between them. Since no vertical positioning of bar is given its upper border will align with that of foo.
Character values of arrow keys as returned by get-char.
Copyright (c) 2010-2011, Moritz Heidkamp All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.