Mojo is 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.
- (initialize #!key terminal) procedure
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.
- (redraw) procedure
Draws all Mojo windows. This should usually be called at the beginning of the program's main loop.
- width parameter
The current terminal width.
- height parameter
The current terminal height.
- (get-char) procedure
Reads a character using ncurses' getch and implicitly handles KEY_RESIZE.
Windows in Mojo are represented as coops objects.
- <win> class
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
- (win-left win) procedure
- (win-right win) procedure
- (win-top win) procedure
- (win-pointer win) procedure
Accessors for the respective <win> slots.
- (make-win #!key width height left right top bottom left-of right-of below above box background) procedure
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.
- key-up constant
- key-down constant
- key-left constant
- key-right constant
Character values of arrow keys as returned by get-char.
Copyright (c) 2010-2012, 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.