Gathering detailed insights and metrics for node-termios
Gathering detailed insights and metrics for node-termios
Gathering detailed insights and metrics for node-termios
Gathering detailed insights and metrics for node-termios
npm install node-termios
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
87 Commits
1 Forks
2 Watching
5 Branches
2 Contributors
Updated on 01 May 2022
C++ (48.85%)
TypeScript (44.31%)
JavaScript (4.22%)
C (2.14%)
Python (0.47%)
Cumulative downloads
Total Downloads
Last day
200%
9
Compared to previous day
Last week
46.7%
22
Compared to previous week
Last month
70%
85
Compared to previous month
Last year
-56.1%
1,744
Compared to previous year
1
8
The module exports a Termios
class, that encapsulates termios struct data:
c_iflag
: Integer representing the input mode flags.c_oflag
: Integer representing the output mode flags.c_cflag
: Integer representing the control mode flags.c_lflag
: Integer representing the local mode flags.c_cc
: Buffer representing the control code settings.constructor(from?: number | ITermios | null)
Termios
object. from
can be a valid file descriptor (number),
another Termios
object (copy constructor) or null
(all data zeroed out).
Omitting from
will try to load default values from ttydefaults.h
(not supported by all platforms).loadFrom(fd: number): void
fd
.writeTo(fd: number, action?: number): void
fd
. action
should be one of native.ACTION
(default: native.ACTION.TCSAFLUSH
).getInputSpeed(): number
native.BAUD
.getOutputSpeed(): number
native.BAUD
.setInputSpeed(speed: number): void
speed
should be one of the baudrates in native.BAUD
.setOutputSpeed(speed: number): void
speed
should be one of the baudrates in native.BAUD
.setSpeed(speed: number): void
speed
should be one of the baudrates in native.BAUD
.setraw(): void
setcbreak(): void
setcooked(): void
The module further exports known symbols defined by the
underlying termios.h (platform dependent) and low level functions under native
:
ALL_SYMBOLS
: All known symbols.IFLAGS
: Input mode symbols.OFLAGS
: Output mode symbols.CFLAGS
: Character mode symbols.LFLAGS
: Local mode symbols.CC
: Valid symbols defined for control character settings.ACTION
: Actions defined for tcsetattr
.FLUSH
: Symbols for tcflush
.FLOW
: Symbols for tcflow
.BAUD
: Defined baudrates of the platform.EXPLAIN
: struct termios
member alignments and sizes.The low level function are direct mappings of the C functions,
where fd
should be a valid TTY file descriptor
and buffer
is a nodejs buffer of termios struct size (see native.EXPLAIN.size
).
Additional enum like arguments are mapped in native
(see listing above).
Also see termios
manpage for further details.
isatty(fd: number): boolean
fd
is a tty. Might throw if fd
is not valid.ttyname(fd: number): string
fd
, or empty string (invalid file descriptor).ptsname(fd: number): string
fd
, or empty string (invalid file descriptor).
Note that this only works on a master end of a PTY. For slave end use ttyname
.tcgetattr(fd: number, buffer: Buffer): void
fd
in buffer
. The given buffer must have a length
of native.EXPLAIN.size
.tcsetattr(fd: number, action: number, buffer: Buffer): void
buffer
to file descriptor fd
. action
should be one of termios.ACTION
.
The given buffer must have a length of native.EXPLAIN.size
.tcsendbreak(fd: number, duration: number): void
tcdrain(fd: number): void
tcflush(fd: number, queue_selector: number): void
tcflow(fd: number, flowaction: number)
cfgetispeed(buffer: Buffer): void
cfgetospeed(buffer: Buffer)
cfsetispeed(buffer: Buffer, speed: number): void
cfsetospeed(buffer: Buffer, speed: number): void
The example demostrates how to switch off/on echoing on STDIN:
1const { Termios, native: { LFLAGS } } = require('node-termios'); 2 3// load termios data from STDIN 4var t = new Termios(0); 5// disable ECHO (not yet written) 6t.c_lflag &= ~LFLAGS.ECHO; 7// write back to STDIN 8t.writeTo(0); 9// now interactive input does not show up anymore 10... 11 12// switch on again when done 13t.c_lflag |= LFLAGS.ECHO; 14t.writeTo(0);
A typical usage pattern seen in C is to store the settings, do some needed customizations like entering raw mode and restoring old settings afterwards:
1const { Termios } = require('node-termios'); 2 3// save current settings to restore later on 4const initial = new Termios(some_tty_fd); 5// create copy and enter raw mode 6const altered = new Termios(initial); 7altered.setraw(); 8altered.writeTo(some_tty_fd); 9// raw mode, thus every single data event shows up 10... 11// restore old settings 12initial.writeTo(some_tty_fd);
Note that in the interactive nodejs shell the standard file descriptors are already customized by the nodejs env and should not be handled like in the example above, or the terminal might break with the shell expectations.
For a silly yet slightly more advanced example, see example.js.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More