Skip to content
Browse files

Added raw support.

  • Loading branch information...
1 parent aa03265 commit e1668f28397fc0d35a27ab2541f3dc02d731fb84 @mscdex committed Aug 2, 2010
Showing with 39 additions and 0 deletions.
  1. +1 −0 README.md
  2. +38 −0 ncurses.cc
View
1 README.md
@@ -175,6 +175,7 @@ ncWindow Properties
* **echo** - _Boolean_ [Read/Write] - Enable/disable local echoing of keyboard input
* **showCursor** - _Boolean_ [Read/Write] - Show/hide the cursor
+* **raw** - _Boolean_ [Read/Write] - Enable/disable terminal's raw mode
* **lines** - _Integer_ [Read-only] - The total number of rows of the terminal
* **cols** - _Integer_ [Read-only] - The total number of columns of the terminal
* **tabsize** - _Integer_ [Read-only] - The terminal's tab size
View
38 ncurses.cc
@@ -39,6 +39,7 @@ static Persistent<Array> ACS_Chars;
#define NUMCOLORPAIRS_STATE_SYMBOL String::NewSymbol("numColorPairs")
#define MAXCOLORPAIRS_STATE_SYMBOL String::NewSymbol("maxColorPairs")
#define ACS_CONSTS_SYMBOL String::NewSymbol("ACS")
+#define RAW_STATE_SYMBOL String::NewSymbol("raw")
#define BKGD_STATE_SYMBOL String::NewSymbol("bkgd")
#define HIDDEN_STATE_SYMBOL String::NewSymbol("hidden")
@@ -84,6 +85,7 @@ class MyPanel : public NCursesPanel {
}
static bool echoInput_;
static bool showCursor_;
+ static bool isRaw_;
public:
MyPanel(int nlines, int ncols, int begin_y = 0, int begin_x = 0) : NCursesPanel(nlines,ncols,begin_y,begin_x) {
this->setup();
@@ -115,6 +117,16 @@ class MyPanel : public NCursesPanel {
static bool showCursor() {
return MyPanel::showCursor_;
}
+ static void raw(bool value) {
+ MyPanel::isRaw_ = value;
+ if (MyPanel::isRaw_)
+ ::raw();
+ else
+ ::noraw();
+ }
+ static bool raw() {
+ return MyPanel::isRaw_;
+ }
bool isStdscr() {
return (w == ::stdscr);
}
@@ -171,6 +183,7 @@ class MyPanel : public NCursesPanel {
bool MyPanel::echoInput_ = false;
bool MyPanel::showCursor_ = true;
+bool MyPanel::isRaw_ = false;
class ncWindow : public EventEmitter {
public:
@@ -264,6 +277,7 @@ class ncWindow : public EventEmitter {
t->PrototypeTemplate()->SetAccessor(NUMCOLORPAIRS_STATE_SYMBOL, NumcolorpairsStateGetter);
t->PrototypeTemplate()->SetAccessor(MAXCOLORPAIRS_STATE_SYMBOL, MaxcolorpairsStateGetter);
t->PrototypeTemplate()->SetAccessor(ACS_CONSTS_SYMBOL, ACSConstsGetter);
+ t->PrototypeTemplate()->SetAccessor(RAW_STATE_SYMBOL, RawStateGetter, RawStateSetter);
/* Window properties */
t->PrototypeTemplate()->SetAccessor(BKGD_STATE_SYMBOL, BkgdStateGetter, BkgdStateSetter);
@@ -1592,6 +1606,30 @@ class ncWindow : public EventEmitter {
return scope.Close(ACS_Chars);
}
+ static Handle<Value> RawStateGetter (Local<String> property, const AccessorInfo& info) {
+ ncWindow *win = ObjectWrap::Unwrap<ncWindow>(info.This());
+ assert(win);
+ assert(property == RAW_STATE_SYMBOL);
+
+ HandleScope scope;
+
+ return scope.Close(Boolean::New(MyPanel::raw()));
+ }
+
+ static void RawStateSetter (Local<String> property, Local<Value> value, const AccessorInfo& info) {
+ ncWindow *win = ObjectWrap::Unwrap<ncWindow>(info.This());
+ assert(win);
+ assert(property == RAW_STATE_SYMBOL);
+
+ if (!value->IsBoolean()) {
+ ThrowException(Exception::TypeError(
+ String::New("raw should be of Boolean value")
+ ));
+ }
+
+ MyPanel::raw(value->BooleanValue());
+ }
+
ncWindow() : EventEmitter() {
panel_ = NULL;
this->init();

0 comments on commit e1668f2

Please sign in to comment.
Something went wrong with that request. Please try again.