Coder Social home page Coder Social logo

node-termios's Introduction

Build Status

termios bindings for node.js

node-termios is a module for getting and setting terminal attributes.

API

  • an attr object may contain on or more of the following boolean fields:

    • attr.iflag:
      • IGNBRK: ignore BREAK condition
      • BRKINT: map BREAK to SIGINT
      • IGNPAR: ignore (discard) parity errors
      • PARMRK: mark parity and framing errors
      • INPCK: enable checking of parity errors
      • ISTRIP: strip 8th bit off chars
      • INLCR: map NL into CR
      • IGNCR: ignore CR
      • ICRNL: map CR to NL (ala CRMOD)
      • IXON: enable output flow control
      • IXOFF: enable input flow control
      • IXANY: any char will restart after stop
      • IMAXBEL: ring bell on input queue full
    • attr.oflag:
      • OPOST: enable following output processing
      • ONLCR: map NL to CR-NL (ala CRMOD)
      • OCRNL: map CR to NL
      • ONOCR: No CR output at column 0
      • ONLRET: NL performs the CR function
    • attr.cflag:
      • CSIZE: character size mask
      • CS5: 5 bits (pseudo)
      • CS6: 6 bits
      • CS7: 7 bits
      • CS8: 8 bits
      • CSTOPB: send 2 stop bits
      • CREAD: enable receiver
      • PARENB: parity enable
      • PARODD: odd parity, else even
      • HUPCL: hang up on last close
      • CLOCAL: ignore modem status lines
    • attr.lflag:
      • ECHOKE: visual erase for line kill
      • ECHOE: visually erase chars
      • ECHOK: echo NL after line kill
      • ECHO: enable echoing
      • ECHONL: echo NL even if ECHO is off
      • ECHOPRT: visual erase mode for hardcopy
      • ECHOCTL: echo control chars as ^(Char)
      • ISIG: enable signals INTR, QUIT, [D]SUSP
      • ICANON: canonicalize input lines
      • IEXTEN: enable DISCARD and LNEXT
      • EXTPROC: external processing
      • TOSTOP: stop background jobs from output
      • FLUSHO: output being flushed (state)
      • PENDIN: XXX retype pending input (state)
      • NOFLSH: don't flush after interrupt
      • XCASE: canonical upper/lower case
  • .setattr(fd, attr): Sets attributes of the terminal bound to the file descriptor:

    • fd: file descriptor
    • attr: object as described above
    • returns: undefined
  • .getattr(fd): Returns an object describing the current settings of the terminal bound to the file descriptor:

    • fd: file descriptor

Examples

var termios = require('termios'), data = '';
console.log("Please type something:");
process.stdin.on("data", function(d) {data += d.toString()});
setTimeout(function() {
	console.log("Disabling ECHO. You won't see what you type now");
	termios.setattr(process.stdin.fd, {lflag: { ECHO: false }})
	console.log("\nYou typed '"+data+"'");
	data = "";
}, 3000);
setTimeout(function() {
	console.log("Enabling ECHO.");
	termios.setattr(process.stdin.fd, {lflag: { ECHO: false }})
	console.log("\nYou typed '"+data+"'");
}, 6000);

Changelog

  • v0.1 - initial release

node-termios's People

Contributors

dashxdr avatar gottox avatar sputnik13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-termios's Issues

Node v12 support?

Hi! This project's nan dependency was updated to the latest 2.13.2, but it fails to build under Node v12 (I used v12.2.0). It looks like some APIs may have changed? Nan has a v12 tracking ticket at nodejs/nan#849.

I've been using child_pty but wasn't able to update it for Node v12 because of the build errors in this package. I looked around a bit for a nan version migration guide to help, but didn't find one. =/

I was able to install child_pty (and therefore this package) successfully under Node v10.

$ npm install node-termios

> [email protected] install /Users/me/code/xometry/node_modules/termios
> node-gyp rebuild

  CXX(target) Release/obj.target/termios/src/termios.o
../src/termios.cpp:72:39: error: no matching member function for call to 'ToObject'
        v8::Local<v8::Object> obj = info[2]->ToObject();
                                    ~~~~~~~~~^~~~~~~~
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2532:44: note: candidate function not viable: requires single argument 'context', but no arguments were provided
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
                                           ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2546:35: note: candidate function not viable: requires single argument 'isolate', but no arguments were provided
                    Local<Object> ToObject(Isolate* isolate) const);
                                  ^
../src/termios.cpp:82:37: error: too few arguments to function call, single argument 'context' was not specified
        if (tcgetattr(info[0]->Uint32Value(), &t) < 0) {
                      ~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:85:11: error: no matching member function for call to 'Has'
        if (obj->Has(iflag)) {
            ~~~~~^~~
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3449:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
                                    ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3455:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
                                    ^
../src/termios.cpp:86:20: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
                t.c_iflag = obj->Get(iflag)->Uint32Value();
                                 ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:86:44: error: too few arguments to function call, single argument 'context' was not specified
                t.c_iflag = obj->Get(iflag)->Uint32Value();
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:88:11: error: no matching member function for call to 'Has'
        if (obj->Has(oflag)) {
            ~~~~~^~~
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3449:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
                                    ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3455:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
                                    ^
../src/termios.cpp:89:20: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
                t.c_oflag = obj->Get(oflag)->Uint32Value();
                                 ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:89:44: error: too few arguments to function call, single argument 'context' was not specified
                t.c_oflag = obj->Get(oflag)->Uint32Value();
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:91:11: error: no matching member function for call to 'Has'
        if (obj->Has(cflag)) {
            ~~~~~^~~
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3449:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
                                    ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3455:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
                                    ^
../src/termios.cpp:92:20: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
                t.c_cflag = obj->Get(cflag)->Uint32Value();
                                 ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:92:44: error: too few arguments to function call, single argument 'context' was not specified
                t.c_cflag = obj->Get(cflag)->Uint32Value();
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:94:11: error: no matching member function for call to 'Has'
        if (obj->Has(cbaud)) {
            ~~~~~^~~
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3449:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
                                    ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3455:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
                                    ^
../src/termios.cpp:95:56: error: too few arguments to function call, single argument 'context' was not specified
                int mask = baud_to_mask(obj->Get(cbaud)->Uint32Value());
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:95:32: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
                int mask = baud_to_mask(obj->Get(cbaud)->Uint32Value());
                                             ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:103:11: error: no matching member function for call to 'Has'
        if (obj->Has(lflag)) {
            ~~~~~^~~
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3449:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
                                    ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3455:37: note: candidate function not viable: requires 2 arguments, but 1 was provided
  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
                                    ^
../src/termios.cpp:104:20: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
                t.c_lflag = obj->Get(lflag)->Uint32Value();
                                 ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3412:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:104:44: error: too few arguments to function call, single argument 'context' was not specified
                t.c_lflag = obj->Get(lflag)->Uint32Value();
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:106:37: error: too few arguments to function call, single argument 'context' was not specified
        if (tcsetattr(info[0]->Uint32Value(), TCSADRAIN, &t) < 0) {
                      ~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:114:37: error: too few arguments to function call, single argument 'context' was not specified
        if (tcgetattr(info[0]->Uint32Value(), &t) < 0) {
                      ~~~~~~~~~~~~~~~~~~~~ ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:2567:3: note: 'Uint32Value' declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:347:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/termios.cpp:118:7: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        obj->Set(Nan::New<v8::String>("iflag").ToLocalChecked(), Nan::New<v8::Number>(t.c_iflag));
             ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:119:7: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        obj->Set(Nan::New<v8::String>("oflag").ToLocalChecked(), Nan::New<v8::Number>(t.c_oflag));
             ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:120:7: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        obj->Set(Nan::New<v8::String>("cflag").ToLocalChecked(), Nan::New<v8::Number>(t.c_cflag));
             ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:123:8: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
                obj->Set(Nan::New<v8::String>("cbaud").ToLocalChecked(), Nan::New<v8::Number>(baud));
                     ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:125:7: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        obj->Set(Nan::New<v8::String>("lflag").ToLocalChecked(), Nan::New<v8::Number>(t.c_lflag));
             ^
/Users/me/.node-gyp/12.2.0/include/node/v8.h:3358:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/me/.node-gyp/12.2.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/termios.cpp:130:6: error: variable has incomplete type 'void'
void Init(v8::Handle<v8::Object> exports) {
     ^
../src/termios.cpp:130:15: error: no member named 'Handle' in namespace 'v8'
void Init(v8::Handle<v8::Object> exports) {
          ~~~~^
../src/termios.cpp:130:32: error: expected '(' for function-style cast or type construction
void Init(v8::Handle<v8::Object> exports) {
                     ~~~~~~~~~~^
../src/termios.cpp:130:34: error: use of undeclared identifier 'exports'
void Init(v8::Handle<v8::Object> exports) {
                                 ^
../src/termios.cpp:130:42: error: expected ';' after top level declarator
void Init(v8::Handle<v8::Object> exports) {
                                         ^
                                         ;
10 warnings and 19 errors generated.
make: *** [Release/obj.target/termios/src/termios.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/me/.nvm/versions/node/v12.2.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:257:12)
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/Users/me/.nvm/versions/node/v12.2.0/bin/node" "/Users/me/.nvm/versions/node/v12.2.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/me/code/xometry/tmp/node-termios
gyp ERR! node -v v12.2.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open '/Users/me/code/xometry/package.json'
npm WARN xometry No description
npm WARN xometry No repository field.
npm WARN xometry No README data
npm WARN xometry No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2019-05-09T21_26_03_581Z-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.