Curses bindings for MRuby. Links against PDCurses or NCurses.
You can checkout an example build_config.rb for MRuby + mruby-curses here.
The exact steps are as follows:
- Download/clone MRuby
- Download/clone
mruby-curses - Add the directory containing your system's curses headers to
include_pathsin MRuby'sbuild_config.rbfile.- Ex: Building with NCurses
conf.cc.include_paths << 'PATH/TO/NCURSES/include' - Ex: Building with PDCurses
conf.cc.include_paths << 'PATH/TO/PDCURSES'
- Ex: Building with NCurses
- Add the directory containing your system's curses libraries to
library_paths, then add the library names tolibrariesin MRuby'sbuild_config.rbfile, .- Ex: Build against ncurses
conf.linker.library_paths = ['PATH/TO/NCURSES/lib']
conf.linker.libraries = %w(panel ncurses) - Ex: Building against pdcurses
I renamed pdcurses.a to libpdcurses.a so the linker would find it under the -L directories
conf.linker.library_paths = ['PATH/TO/PDCURSES']
conf.linker.libraries = %w(pdcurses)
- Ex: Build against ncurses
- Run
rakein MRuby's root directory.
You can try running the scripts in the examples/ directory to test your build.
Note for Mac users: If you get errors like "Error opening terminal xterm-256color" that means
ncurses can't find your terminfo files. You can get around this by make install-ing ncurses, or by
setting the environment variable TERMINFO=/usr/shar/terminfo. You can do this within your
appliction, as long as it's set before you call Curses.init.
On windows, building pdcurses with clang (via mingw32-make & cygwin) then linking to MRuby (also building with clang) is very straightforward and "just works."
Basic workflow:
bundle installto install dependenciesbundle exec rake -Tto list buid targetsbundle exec rake mruby:buildto build with this project's included build_config.rb.- All mruby:* tasks expect to find mruby source code at path specified by MRUBY_HOME environment variable.
- If MRUBY_HOME is not set, it looks up one directory from this project's root for mruby.
- The included build_config.rb builds mruby with this mrbgem included, and copies the
build files from mruby's tree to this repo's
build/folder.
./build/bin/mruby examples/hello_world.rbto run the hello_world.rb example.
The main API is 1-to-1 with the C API for curses. Parameters map the way you would expect (char* to String, int to Fixnum, etc). A point of note is that characters in curses are handled as numbers (same as the MRI Curses gem). Though, the *addch family of functions will allow you to pass a single character string as well.
The bound functions are listed below. If you're new to curses development, you can find documentation online. You might start here or here.
There is also a higher-level framework included included called CUI. CUI is roughly based on
Backbone.js. It should probably be moved into it's own repo, as consumers of the raw bindings
should not have to include it in their builds.
CUI features include:
- Easy initialization of curses for raw input
CUI.init - An
Eventsmodule that can be mixed in to any class- Just like Backbone, CUI itself mixis in
Events
- Just like Backbone, CUI itself mixis in
- An event loop
- Triggers all input events on the focused window, if any, and
CUIitself. - Resizes all Windows when the terminal is resized
- Calls the window's
layoutmethod and sets@invalidto true, which you can check in yourWindow#rendermethod.
- Calls the window's
- Re-renders any invalid windows at ~50fps.
- Triggers all input events on the focused window, if any, and
- A
Modelclass, which provides themodel_attrclass macromodel_attrs are just likeattr_accessors, but they trigger change events on changes.- This allows the familiar Backone idiom in your views
@model.on(:change) { @invalid = true } # Make sure we re-render on the next render frame
- A
Windowclass used to create views- Each window is backed by a curses panel, which allows curses to render overlapping windows correctly.
- The
layoutandrendermethods can be overridden to customize interaction with the event loop. - All windows have an
ioproperty, which is aWindowIOobject.
- A
WindowIOclass- Provides higher-level window output routines built on the
Cursesmodule.
- Provides higher-level window output routines built on the
- An example
TextInputclass- A single-line text input window
- Gets input asynchronously from the event loop, rather than in a blocking manner like
Curses.getstr
CUI is meant to provide the basic building blocks that I think all curses applicaitons are going
to need, and nothing more. Have a peek at examples/cui_windows.rb to see it in action. A larger
example is available here. CUI is brand new, so
any bug reports are appreciated!
Curses::addchCurses::addnstrCurses::addstrCurses::assume_default_colorsCurses::attroffCurses::attronCurses::attrsetCurses::baudrateCurses::beepCurses::bkgdCurses::bkgdsetCurses::borderCurses::bottom_panelCurses::boxCurses::can_change_colorCurses::cbreakCurses::clearCurses::clearokCurses::clrtobotCurses::clrtoeolCurses::copywinCurses::curs_setCurses::curses_versionCurses::def_prog_modeCurses::def_shell_modeCurses::del_curtermCurses::del_panelCurses::delay_outputCurses::delchCurses::deletelnCurses::delscreenCurses::delwinCurses::derwinCurses::doupdateCurses::dupwinCurses::echoCurses::echocharCurses::endwinCurses::eraseCurses::erasecharCurses::filterCurses::flashCurses::flushinpCurses::getattrsCurses::getbegxCurses::getbegyCurses::getbkgdCurses::getcurxCurses::getcuryCurses::getmaxxCurses::getmaxyCurses::getnstrCurses::getparxCurses::getparyCurses::getstrCurses::halfdelayCurses::has_colorsCurses::has_icCurses::has_ilCurses::has_keyCurses::hide_panelCurses::hlineCurses::idcokCurses::idlokCurses::immedokCurses::inchCurses::init_colorCurses::init_pairCurses::initscrCurses::innstrCurses::inschCurses::insdellnCurses::insertlnCurses::insnstrCurses::insstrCurses::instrCurses::intrflushCurses::is_linetouchedCurses::is_wintouchedCurses::isendwinCurses::keynameCurses::keypadCurses::killcharCurses::leaveokCurses::longnameCurses::metaCurses::mouseintervalCurses::moveCurses::move_panelCurses::mvaddchCurses::mvaddnstrCurses::mvaddstrCurses::mvcurCurses::mvdelchCurses::mvderwinCurses::mvgetchCurses::mvgetnstrCurses::mvgetstrCurses::mvhlineCurses::mvinchCurses::mvinnstrCurses::mvinschCurses::mvinsnstrCurses::mvinsstrCurses::mvinstrCurses::mvprintwCurses::mvscanwCurses::mvvlineCurses::mvwaddchCurses::mvwaddnstrCurses::mvwaddstrCurses::mvwdelchCurses::mvwgetchCurses::mvwgetnstrCurses::mvwgetstrCurses::mvwhlineCurses::mvwinCurses::mvwinchCurses::mvwinnstrCurses::mvwinschCurses::mvwinsnstrCurses::mvwinsstrCurses::mvwinstrCurses::mvwprintwCurses::mvwscanwCurses::mvwvlineCurses::napmsCurses::new_panelCurses::newpadCurses::newwinCurses::nlCurses::nocbreakCurses::nodelayCurses::noechoCurses::nonlCurses::noqiflushCurses::norawCurses::notimeoutCurses::overlayCurses::overwriteCurses::panel_aboveCurses::panel_belowCurses::panel_hiddenCurses::panel_windowCurses::pechocharCurses::pnoutrefreshCurses::prefreshCurses::printwCurses::putpCurses::qiflushCurses::rawCurses::redrawwinCurses::refreshCurses::replace_panelCurses::reset_prog_modeCurses::reset_shell_modeCurses::resettyCurses::resize_termCurses::savettyCurses::scanwCurses::scr_dumpCurses::scr_initCurses::scr_restoreCurses::scr_setCurses::scrlCurses::scrollCurses::scrollokCurses::set_curtermCurses::set_termCurses::setscrregCurses::show_panelCurses::slk_attroffCurses::slk_attronCurses::slk_attrsetCurses::slk_clearCurses::slk_colorCurses::slk_initCurses::slk_labelCurses::slk_noutrefreshCurses::slk_refreshCurses::slk_restoreCurses::slk_setCurses::slk_touchCurses::standendCurses::standoutCurses::start_colorCurses::subpadCurses::subwinCurses::syncokCurses::termattrsCurses::termnameCurses::tgetentCurses::tgetflagCurses::tgetnumCurses::tgotoCurses::tigetflagCurses::tigetnumCurses::tigetstrCurses::timeoutCurses::top_panelCurses::touchlineCurses::touchwinCurses::tparmCurses::typeaheadCurses::unctrlCurses::ungetmouseCurses::untouchwinCurses::update_panelsCurses::use_default_colorsCurses::use_envCurses::vidattrCurses::vlineCurses::waddchCurses::waddnstrCurses::waddstrCurses::wattroffCurses::wattronCurses::wattrsetCurses::wbkgdCurses::wbkgdsetCurses::wborderCurses::wclearCurses::wclrtobotCurses::wclrtoeolCurses::wcursyncupCurses::wdelchCurses::wdeletelnCurses::wechocharCurses::wencloseCurses::weraseCurses::wgetchCurses::wgetnstrCurses::wgetstrCurses::whlineCurses::winchCurses::winnstrCurses::winschCurses::winsdellnCurses::winsertlnCurses::winsnstrCurses::winsstrCurses::winstrCurses::wmoveCurses::wnoutrefreshCurses::wprintwCurses::wredrawlnCurses::wrefreshCurses::wresizeCurses::wscanwCurses::wscrlCurses::wsetscrregCurses::wstandendCurses::wstandoutCurses::wsyncdownCurses::wsyncupCurses::wtimeoutCurses::wtouchln
