Skip to content

Commit

Permalink
ACS characters can now be accessed using the "ACS" property of an ncW…
Browse files Browse the repository at this point in the history
…indow instance.
  • Loading branch information
mscdex committed May 17, 2010
1 parent 4257a88 commit e3fcb94
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 27 deletions.
51 changes: 26 additions & 25 deletions README.md
Expand Up @@ -41,6 +41,7 @@ node-ncurses exposes only one class: **ncWindow**.
* _Attributes_ is an unsigned integer used as a bitmask for holding window attributes (see ncconsts.js for the available values).

* _ACS_Character_ is a special character used when dealing with line graphics. These are automatically determined at runtime by ncurses and thus cannot be defined as constants. Instead, they are accessible statically via the ncWindow class after at least one window has been created (so that ncurses has initialized this special character set). See the **Additional notes** at the bottom for a list of the available characters.
* An _ACS_Character_ can currently be retrieved by using the ACS property of an ncWindow instance (i.e. "win = new ncWindow(); win.hline(win.cols, win.ACS.DIAMOND);")


ncWindow Events
Expand Down Expand Up @@ -215,29 +216,29 @@ ACS_Character descriptions
<pre>
Character Name POSIX Default Description
-------------- ------------- -----------
ACS_ULCORNER + upper left-hand corner
ACS_LLCORNER + lower left-hand corner
ACS_URCORNER + upper right-hand corner
ACS_LRCORNER + lower right-hand corner
ACS_RTEE + right tee
ACS_LTEE + left tee
ACS_BTEE + bottom tee
ACS_TTEE + top tee
ACS_HLINE - horizontal line
ACS_VLINE | vertical line
ACS_PLUS + plus
ACS_S1 - scan line 1
ACS_S9 _ scan line 9
ACS_DIAMOND + diamond
ACS_CKBOARD : checker board (stipple)
ACS_DEGREE ' degree symbol
ACS_PLMINUS # plus/minus
ACS_BULLET o bullet
ACS_LARROW < arrow pointing left
ACS_RARROW > arrow pointing right
ACS_DARROW v arrow pointing down
ACS_UARROW ^ arrow pointing up
ACS_BOARD # board of squares
ACS_LANTERN # lantern symbol
ACS_BLOCK # solid square block
ULCORNER + upper left-hand corner
LLCORNER + lower left-hand corner
URCORNER + upper right-hand corner
LRCORNER + lower right-hand corner
RTEE + right tee
LTEE + left tee
BTEE + bottom tee
TTEE + top tee
HLINE - horizontal line
VLINE | vertical line
PLUS + plus
S1 - scan line 1
S9 _ scan line 9
DIAMOND + diamond
CKBOARD : checker board (stipple)
DEGREE ' degree symbol
PLMINUS # plus/minus
BULLET o bullet
LARROW < arrow pointing left
RARROW > arrow pointing right
DARROW v arrow pointing down
UARROW ^ arrow pointing up
BOARD # board of squares
LANTERN # lantern symbol
BLOCK # solid square block
</pre>
48 changes: 46 additions & 2 deletions ncurses.cc
Expand Up @@ -27,6 +27,7 @@ static int stdin_fd = -1;
static int stdout_fd = -1;

static Persistent<String> inputChar_symbol;
static Persistent<Array> ACS_Chars;

#define ECHO_STATE_SYMBOL String::NewSymbol("echo")
#define SHOWCURSOR_STATE_SYMBOL String::NewSymbol("showCursor")
Expand All @@ -37,6 +38,7 @@ static Persistent<String> inputChar_symbol;
#define HASCOLORS_STATE_SYMBOL String::NewSymbol("hasColors")
#define NUMCOLORPAIRS_STATE_SYMBOL String::NewSymbol("numColorPairs")
#define MAXCOLORPAIRS_STATE_SYMBOL String::NewSymbol("maxColorPairs")
#define ACS_CONSTS_SYMBOL String::NewSymbol("ACS")

#define BKGD_STATE_SYMBOL String::NewSymbol("bkgd")
#define HIDDEN_STATE_SYMBOL String::NewSymbol("hidden")
Expand Down Expand Up @@ -230,7 +232,7 @@ class ncWindow : public EventEmitter {
NODE_SET_PROTOTYPE_METHOD(t, "deleteln", Deleteln);
NODE_SET_PROTOTYPE_METHOD(t, "scroll", Scroll);
NODE_SET_PROTOTYPE_METHOD(t, "setscrreg", Setscrreg);
NODE_SET_PROTOTYPE_METHOD(t, "touchlines", Touchln); // multiple lines
NODE_SET_PROTOTYPE_METHOD(t, "touchlines", Touchln);
NODE_SET_PROTOTYPE_METHOD(t, "is_linetouched", Is_linetouched);
NODE_SET_PROTOTYPE_METHOD(t, "redrawln", Redrawln);
NODE_SET_PROTOTYPE_METHOD(t, "touch", Touchwin);
Expand Down Expand Up @@ -261,6 +263,7 @@ class ncWindow : public EventEmitter {
t->PrototypeTemplate()->SetAccessor(HASCOLORS_STATE_SYMBOL, HascolorsStateGetter);
t->PrototypeTemplate()->SetAccessor(NUMCOLORPAIRS_STATE_SYMBOL, NumcolorpairsStateGetter);
t->PrototypeTemplate()->SetAccessor(MAXCOLORPAIRS_STATE_SYMBOL, MaxcolorpairsStateGetter);
t->PrototypeTemplate()->SetAccessor(ACS_CONSTS_SYMBOL, ACSConstsGetter);

/* Window properties */
t->PrototypeTemplate()->SetAccessor(BKGD_STATE_SYMBOL, BkgdStateGetter, BkgdStateSetter);
Expand All @@ -274,12 +277,14 @@ class ncWindow : public EventEmitter {
t->PrototypeTemplate()->SetAccessor(MAXX_STATE_SYMBOL, MaxxStateGetter);
t->PrototypeTemplate()->SetAccessor(MAXY_STATE_SYMBOL, MaxyStateGetter);
t->PrototypeTemplate()->SetAccessor(WINTOUCHED_STATE_SYMBOL, WintouchedStateGetter);

target->Set(String::NewSymbol("ncWindow"), t->GetFunction());
}

void init(int nlines=-1, int ncols=-1, int begin_y=-1, int begin_x=-1) {
bool firstRun = false;
if (stdin_fd < 0) {
firstRun = true;
stdin_fd = STDIN_FILENO;
int stdin_flags = fcntl(stdin_fd, F_GETFL, 0);
int r = fcntl(stdin_fd, F_SETFL, stdin_flags | O_NONBLOCK);
Expand All @@ -302,6 +307,35 @@ class ncWindow : public EventEmitter {
panel_ = new MyPanel();
else
panel_ = new MyPanel(nlines, ncols, begin_y, begin_x);
if (firstRun) {
// Load runtime-defined ACS_* "constants"
ACS_Chars = Persistent<Array>::New(Array::New(25));
ACS_Chars->Set(String::New("ULCORNER"), Uint32::NewFromUnsigned(ACS_ULCORNER), ReadOnly);
ACS_Chars->Set(String::New("LLCORNER"), Uint32::NewFromUnsigned(ACS_LLCORNER), ReadOnly);
ACS_Chars->Set(String::New("URCORNER"), Uint32::NewFromUnsigned(ACS_URCORNER), ReadOnly);
ACS_Chars->Set(String::New("LRCORNER"), Uint32::NewFromUnsigned(ACS_LRCORNER), ReadOnly);
ACS_Chars->Set(String::New("LTEE"), Uint32::NewFromUnsigned(ACS_LTEE), ReadOnly);
ACS_Chars->Set(String::New("RTEE"), Uint32::NewFromUnsigned(ACS_RTEE), ReadOnly);
ACS_Chars->Set(String::New("BTEE"), Uint32::NewFromUnsigned(ACS_BTEE), ReadOnly);
ACS_Chars->Set(String::New("TTEE"), Uint32::NewFromUnsigned(ACS_TTEE), ReadOnly);
ACS_Chars->Set(String::New("HLINE"), Uint32::NewFromUnsigned(ACS_HLINE), ReadOnly);
ACS_Chars->Set(String::New("VLINE"), Uint32::NewFromUnsigned(ACS_VLINE), ReadOnly);
ACS_Chars->Set(String::New("PLUS"), Uint32::NewFromUnsigned(ACS_PLUS), ReadOnly);
ACS_Chars->Set(String::New("S1"), Uint32::NewFromUnsigned(ACS_S1), ReadOnly);
ACS_Chars->Set(String::New("S9"), Uint32::NewFromUnsigned(ACS_S9), ReadOnly);
ACS_Chars->Set(String::New("DIAMOND"), Uint32::NewFromUnsigned(ACS_DIAMOND), ReadOnly);
ACS_Chars->Set(String::New("CKBOARD"), Uint32::NewFromUnsigned(ACS_CKBOARD), ReadOnly);
ACS_Chars->Set(String::New("DEGREE"), Uint32::NewFromUnsigned(ACS_DEGREE), ReadOnly);
ACS_Chars->Set(String::New("PLMINUS"), Uint32::NewFromUnsigned(ACS_PLMINUS), ReadOnly);
ACS_Chars->Set(String::New("BULLET"), Uint32::NewFromUnsigned(ACS_BULLET), ReadOnly);
ACS_Chars->Set(String::New("LARROW"), Uint32::NewFromUnsigned(ACS_LARROW), ReadOnly);
ACS_Chars->Set(String::New("RARROW"), Uint32::NewFromUnsigned(ACS_RARROW), ReadOnly);
ACS_Chars->Set(String::New("DARROW"), Uint32::NewFromUnsigned(ACS_DARROW), ReadOnly);
ACS_Chars->Set(String::New("UARROW"), Uint32::NewFromUnsigned(ACS_UARROW), ReadOnly);
ACS_Chars->Set(String::New("BOARD"), Uint32::NewFromUnsigned(ACS_BOARD), ReadOnly);
ACS_Chars->Set(String::New("LANTERN"), Uint32::NewFromUnsigned(ACS_LANTERN), ReadOnly);
ACS_Chars->Set(String::New("BLOCK"), Uint32::NewFromUnsigned(ACS_BLOCK), ReadOnly);
}
}

MyPanel* panel() {
Expand Down Expand Up @@ -1528,6 +1562,16 @@ class ncWindow : public EventEmitter {
return scope.Close(Boolean::New(win->panel()->is_wintouched()));
}

static Handle<Value> ACSConstsGetter (Local<String> property, const AccessorInfo& info) {
ncWindow *win = ObjectWrap::Unwrap<ncWindow>(info.This());
assert(win);
assert(property == ACS_CONSTS_SYMBOL);

HandleScope scope;

return scope.Close(ACS_Chars);
}

ncWindow() : EventEmitter() {
panel_ = NULL;
this->init();
Expand Down

0 comments on commit e3fcb94

Please sign in to comment.