Reznor
Reznor

Reputation: 1285

Using node-ncurses client-side through server-side script?

I wrote a small node.js netServer chat application. I want to work on creating an ncurses user-interface for it. Problem is, the chat application is written server-side, and people connect via netcat, so the question is how I would go about manipulating ncurses on the client-side through it?

Upvotes: 6

Views: 1442

Answers (3)

toksea
toksea

Reputation: 101

You can write a net.server wraps your server-side node-ncurse app, let users telnet to the server, pipe your app's output to the connection and pipe the connection to your app.

#!/usr/bin/env node


/**
 * widget.js is in node-ncurses's examples
 */
var net = require('net'),
    child = require('child_process'),
    bin = child.spawn('./widget.js', ['InputBox']);

var server = net.createServer(function(c) {

    console.log('server connected');
    c.on('end', function() {
        console.log('server disconnected');
    });

    c.pipe(bin.stdin);
    bin.stdout.pipe(c);

}).listen(8124, function() {
    console.log('server bound 8124');
});

// and let users:
// $ telnet localhost 8124

Upvotes: 0

fadedbee
fadedbee

Reputation: 44739

What you need is a telnet (or ssh) server which is written as a NodeJS module.

It needs to understand the telnet protocol, which is richer than a simple character stream. (e.g. it sends messages for terminal (re)sizes and many other events). http://en.wikipedia.org/wiki/Telnet - see the RFCs.

This is confusing because the telnet client is often used to connect to services which just use plain character streams.

As far as I have found, there are no such working modules. Please correct me if you find one.

Netcat does not send any information on terminal type, terminal size or terminal events. These are all necessary for an ncurses-type application.

Upvotes: 2

Maks
Maks

Reputation: 7935

ncurses is a C library that you need to link to in order to call it functions so I don't think its what you can use for your use case.

I'm guessing that by "manipulating ncurses" what you are really after is a way to change the colour of text you are writing to the users, moving up and down the screen, etc.

You maybe able to achieve some of what you want by getting your users to connect via a telnet client that supports ANSI color escape codes for example. Answer to simliar question for producing colour codes here.

Upvotes: 1

Related Questions