Browse Source

Add color support.

master
lbeckman314 2 years ago
parent
commit
b3a2e9ddd9
8 changed files with 592 additions and 237 deletions
  1. 2
    0
      .gitignore
  2. 8
    0
      .npmignore
  3. 59
    0
      README.html
  4. 191
    191
      demo.js
  5. 156
    40
      package-lock.json
  6. 2
    1
      package.json
  7. 6
    5
      server.js
  8. 168
    0
      tmp

+ 2
- 0
.gitignore View File

@@ -4,3 +4,5 @@ config.js
*.sw*
programs/
files/
virtual/
tags

+ 8
- 0
.npmignore View File

@@ -0,0 +1,8 @@
*.pem
node_modules/
config.js
*.sw*
programs/
files/
virtual/
tags

+ 59
- 0
README.html View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>README.html</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

</head>

<body>

<h1><img src="demo-logo.png" alt="demo logo" /> demo</h1>

<p>A fake terminal cleans up user input and sends it to the server. The server then parses the input, and if it matches a predefined command, spawns a child process of that command/program. I really liked the ability to try out haskell interactively <a href="https://www.haskell.org/">here</a> and <a href="https://tryhaskell.org/">here</a>, so this is something like that.</p>

<p><img src="demo.png" alt="demo screenshot" /></p>

<h1>installation and running</h1>

<p>```sh</p>

<h1>install dependencies</h1>

<p>npm install</p>

<h1>copy example config</h1>

<p>cp config-example.js config.js</p>

<h1>edit key, certificate, and passphrase information</h1>

<p>nano config.js</p>

<h1>run server (if no port number is provided, 12345 in this example, the server will default to port 8181)</h1>

<p>node server.js 12345</p>

<h1>edit server information</h1>

<p>nano demo.js</p>

<h1>then you can connect to the server from a client (e.g. client-example.html)</h1>

<p>```</p>

<h1>uninstallation</h1>

<p>```sh</p>

<h1>remove this directory</h1>

<p>rm -rfI demo
```</p>

</body>
</html>

+ 191
- 191
demo.js View File

@@ -13,199 +13,199 @@ const socket = new WebSocket('wss://liambeckman.com:8181');
const userPrompt = "devilish";

var MYLIBRARY = MYLIBRARY || (function(){
var _args = {}; // private
return {
init : function(Args) {
_args = Args;
// some other initialising
},
helloWorld : function() {
//alert('Hello World! :: ' + _args[0]);
//console.log('Hello World! :: ' + _args[0]);
return _args[0];
}
};
var _args = {}; // private
return {
init : function(Args) {
_args = Args;
// some other initialising
},
helloWorld : function() {
//alert('Hello World! :: ' + _args[0]);
//console.log('Hello World! :: ' + _args[0]);
return _args[0];
}
};
}());


document.addEventListener('DOMContentLoaded', function () {
let terminal = document.getElementById("terminal");
terminal.spellcheck = false;
console.log("terminal:", terminal);
console.log("Connecting to server...");
terminal.value = "Connecting...\n";
// Connection opened
socket.onopen = function (event) {
console.log("Success!");
//terminal.value += "OK\n";
//command = readline.question(": ");
console.log("Sending initial message to server.");
//terminal.value += "Sending initial message to server.\n";
terminal.value = "Press ENTER to blast off!\n\n";
let userPrompt = MYLIBRARY.helloWorld();
terminal.value += "> " + userPrompt;
//socket.send("devilish");
let message = "";
let messages = [];
let commands = [];
let commNum = 0;
let up = 0;
let down = 0;
let ctrl = false;
// Listen for messages
socket.onmessage = function(event) {
//console.log("MESSAGE:", event.data);
terminal.value += event.data;
message = event.data.toString();
console.log("MESSAGE:", message);
messages = message.split("\n");
terminal.scrollTop = terminal.scrollHeight;
console.log("MESSAGES:", messages);
console.log("COMMAND:", comm);
}
// https://stackoverflow.com/questions/22092762/how-to-detect-ctrlc-and-ctrlv-key-pressing-using-regular-expression/22092839
document.getElementById('terminal').addEventListener("keydown",function(e){
e = e || window.event;
var key = e.which || e.keyCode; // keyCode detection
var ctrl = e.ctrlKey ? e.ctrlKey : ((key === 17) ? true : false); // ctrl detection
if ( key == 76 && ctrl ) {
console.log("Ctrl + L Pressed !");
terminal.value = "> ";
event.preventDefault();
e.preventDefault();
terminal.focus();
}
else if ( key == 67 && ctrl ) {
console.log("Ctrl + C Pressed !");
//e.preventDefault();
//event.preventDefault();
socket.send("SIGINT");
terminal.value += "\n";
//terminal.value = terminal.value.replace(/.*$/ ,"> ");
}
else if ( key == 85 && ctrl ) {
console.log("Ctrl + U Pressed !");
e.preventDefault();
//event.preventDefault();
terminal.value = terminal.value.replace(/.*$/ ,"> ");
}
},false);
document.getElementById('terminal').onkeydown = function (event) {
let key = event.keyCode;
let lines = terminal.value.split("\n");
console.log("key:", key);
if (key == 8) {
console.log(lines[lines.length - 1].length);
if (lines[lines.length - 1].length <= 2) {
console.log("backspace detected");
event.preventDefault();
}
}
else if (key == 46) {
console.log("delete detected");
//terminal.value += "\n> ";
}
else if (key == 9) {
event.preventDefault();
terminal.value += "TAB detected";
terminal.value += "\n> ";
console.log("TAB detected");
//socket.send("TAB");
//terminal.value += "\n> ";
}
else if (key == 38) {
console.log("up arrow detected");
event.preventDefault();
if ((up - down) < commands.length && down <= up) {
up += 1;
console.log("up:", up);
console.log("down:", down);
console.log("commands.length:", commands.length);
terminal.value = terminal.value.replace(/.*$/ ,"> " + commands[commands.length - up + down]);
}
console.log("commands:", commands);
//terminal.value += "\n> ";
}
else if (key == 40) {
console.log("down arrow detected");
event.preventDefault();
if (down < up && (up - down) <= commands.length) {
down += 1;
console.log("up:", up);
console.log("down:", down);
if (down == up) {
terminal.value = terminal.value.replace(/.*$/ ,"> ");
}
else {
terminal.value = terminal.value.replace(/.*$/ ,"> " + commands[commands.length - up + down]);
}
}
console.log("commands:", commands);
//terminal.value += "\n> ";
}
else if (key == 13)
{
event.preventDefault();
terminal.value += "\n";
up = 0;
down = 0;
for (let i = 0; i < lines.length; i++)
{
//console.log(lines[i]);
}
console.log("message:", message);
comm = lines[lines.length-1];
//console.log("you entered:", comm);
console.log("messages.length:", messages.length);
if (messages.length > 0) {
comm = comm.substring(messages[messages.length - 1].length - 1);
}
//console.log("you entered:", comm);
comm = comm.replace(/([>:]+ *)/g, "");
comm = comm.replace(/^[ ]*/g, "");
console.log("you entered:", comm);
if (comm == "clear") {
event.preventDefault();
terminal.value = "> ";
commands[commNum] = comm;
commNum += 1;
}
else if (comm == "") {
event.preventDefault();
terminal.value += "\n> ";
}
else {
socket.send(comm);
commands[commNum] = comm;
commNum += 1;
}
terminal.scrollTop = terminal.scrollHeight;
}
}
}
let terminal = document.getElementById("terminal");
terminal.spellcheck = false;
console.log("terminal:", terminal);
console.log("Connecting to server...");
terminal.value = "Connecting...\n";
// Connection opened
socket.onopen = function (event) {
console.log("Success!");
//terminal.value += "OK\n";
//command = readline.question(": ");
console.log("Sending initial message to server.");
//terminal.value += "Sending initial message to server.\n";
terminal.value = "Press ENTER to blast off!\n\n";
let userPrompt = MYLIBRARY.helloWorld();
terminal.value += "> " + userPrompt;
//socket.send("devilish");
let message = "";
let messages = [];
let commands = [];
let commNum = 0;
let up = 0;
let down = 0;
let ctrl = false;
// Listen for messages
socket.onmessage = function(event) {
//console.log("MESSAGE:", event.data);
terminal.value += event.data;
message = event.data.toString();
console.log("MESSAGE:", message);
messages = message.split("\n");
terminal.scrollTop = terminal.scrollHeight;
console.log("MESSAGES:", messages);
console.log("COMMAND:", comm);
}
// https://stackoverflow.com/questions/22092762/how-to-detect-ctrlc-and-ctrlv-key-pressing-using-regular-expression/22092839
document.getElementById('terminal').addEventListener("keydown",function(e){
e = e || window.event;
var key = e.which || e.keyCode; // keyCode detection
var ctrl = e.ctrlKey ? e.ctrlKey : ((key === 17) ? true : false); // ctrl detection
if ( key == 76 && ctrl ) {
console.log("Ctrl + L Pressed !");
terminal.value = "> ";
event.preventDefault();
e.preventDefault();
terminal.focus();
}
else if ( key == 67 && ctrl ) {
console.log("Ctrl + C Pressed !");
//e.preventDefault();
//event.preventDefault();
socket.send("SIGINT");
terminal.value += "\n";
//terminal.value = terminal.value.replace(/.*$/ ,"> ");
}
else if ( key == 85 && ctrl ) {
console.log("Ctrl + U Pressed !");
e.preventDefault();
//event.preventDefault();
terminal.value = terminal.value.replace(/.*$/ ,"> ");
}
},false);
document.getElementById('terminal').onkeydown = function (event) {
let key = event.keyCode;
let lines = terminal.value.split("\n");
console.log("key:", key);
if (key == 8) {
console.log(lines[lines.length - 1].length);
if (lines[lines.length - 1].length <= 2) {
console.log("backspace detected");
event.preventDefault();
}
}
else if (key == 46) {
console.log("delete detected");
//terminal.value += "\n> ";
}
else if (key == 9) {
event.preventDefault();
terminal.value += "TAB detected";
terminal.value += "\n> ";
console.log("TAB detected");
//socket.send("TAB");
//terminal.value += "\n> ";
}
else if (key == 38) {
console.log("up arrow detected");
event.preventDefault();
if ((up - down) < commands.length && down <= up) {
up += 1;
console.log("up:", up);
console.log("down:", down);
console.log("commands.length:", commands.length);
terminal.value = terminal.value.replace(/.*$/ ,"> " + commands[commands.length - up + down]);
}
console.log("commands:", commands);
//terminal.value += "\n> ";
}
else if (key == 40) {
console.log("down arrow detected");
event.preventDefault();
if (down < up && (up - down) <= commands.length) {
down += 1;
console.log("up:", up);
console.log("down:", down);
if (down == up) {
terminal.value = terminal.value.replace(/.*$/ ,"> ");
}
else {
terminal.value = terminal.value.replace(/.*$/ ,"> " + commands[commands.length - up + down]);
}
}
console.log("commands:", commands);
//terminal.value += "\n> ";
}
else if (key == 13)
{
event.preventDefault();
terminal.value += "\n";
up = 0;
down = 0;
for (let i = 0; i < lines.length; i++)
{
//console.log(lines[i]);
}
console.log("message:", message);
comm = lines[lines.length-1];
//console.log("you entered:", comm);
console.log("messages.length:", messages.length);
if (messages.length > 0) {
comm = comm.substring(messages[messages.length - 1].length - 1);
}
//console.log("you entered:", comm);
comm = comm.replace(/([>:]+ *)/g, "");
comm = comm.replace(/^[ ]*/g, "");
console.log("you entered:", comm);
if (comm == "clear") {
event.preventDefault();
terminal.value = "> ";
commands[commNum] = comm;
commNum += 1;
}
else if (comm == "") {
event.preventDefault();
terminal.value += "\n> ";
}
else {
socket.send(comm);
commands[commNum] = comm;
commNum += 1;
}
terminal.scrollTop = terminal.scrollHeight;
}
}
}
});

+ 156
- 40
package-lock.json View File

@@ -1,5 +1,5 @@
{
"name": "hello-world",
"name": "demo-lbeckman314",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
@@ -13,11 +13,27 @@
"negotiator": "0.6.1"
}
},
"align-text": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",
"integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=",
"optional": true,
"requires": {
"kind-of": "^3.0.2",
"longest": "^1.0.1",
"repeat-string": "^1.5.2"
}
},
"amdefine": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
},
"ansi_up": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/ansi_up/-/ansi_up-4.0.3.tgz",
"integrity": "sha512-ub+xzfB7Mkikx6u0/iHx97Cvs5SJRNjh3yoQpuRaAvC9L2t8ZghlqG6jXIQ7XkbtQyHJU/EP2AnPvwcib0vu6A=="
},
"array-flatten": {
"version": "1.1.1",
"resolved": "http://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@@ -28,12 +44,6 @@
"resolved": "https://registry.npmjs.org/asap/-/asap-1.0.0.tgz",
"integrity": "sha1-sqRdpf36ILBJb8N2jMJ8EvqRan0="
},
"async": {
"version": "0.2.10",
"resolved": "http://registry.npmjs.org/async/-/async-0.2.10.tgz",
"integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=",
"optional": true
},
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
@@ -80,6 +90,41 @@
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
},
"camelcase": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz",
"integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=",
"optional": true
},
"center-align": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz",
"integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=",
"optional": true,
"requires": {
"align-text": "^0.1.3",
"lazy-cache": "^1.0.3"
}
},
"cliui": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz",
"integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=",
"optional": true,
"requires": {
"center-align": "^0.1.1",
"right-align": "^0.1.1",
"wordwrap": "0.0.2"
},
"dependencies": {
"wordwrap": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz",
"integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=",
"optional": true
}
}
},
"colors": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz",
@@ -133,6 +178,12 @@
"ms": "2.0.0"
}
},
"decamelize": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=",
"optional": true
},
"deep-equal": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz",
@@ -218,15 +269,46 @@
}
},
"express-handlebars": {
"version": ">=4.0.0",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/express-handlebars/-/express-handlebars-2.0.1.tgz",
"integrity": "sha1-l1Zh/+vW55RjIwukyODKXNBSL7E=",
"requires": {
"glob": "^5.0.0",
"graceful-fs": "^3.0.2",
"handlebars": ">=4.0.0",
"handlebars": "^3.0.0",
"object.assign": "^1.1.1",
"promise": "^6.0.0"
},
"dependencies": {
"handlebars": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-3.0.6.tgz",
"integrity": "sha512-LxzdOvkYFsdL6ZT92igXthJIZLYKBSowtrM3oxfMdOwjv0dRWk6EK4PygNgXc0xwjH38BWMCSnktrOpKbec+Qw==",
"requires": {
"optimist": "^0.6.1",
"source-map": "^0.1.40",
"uglify-js": "^2.6"
}
},
"uglify-js": {
"version": "2.8.29",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz",
"integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=",
"optional": true,
"requires": {
"source-map": "~0.5.1",
"uglify-to-browserify": "~1.0.0",
"yargs": "~3.10.0"
},
"dependencies": {
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
"integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
"optional": true
}
}
}
}
},
"express-session": {
@@ -311,16 +393,6 @@
"natives": "^1.1.0"
}
},
"handlebars": {
"version": ">=4.0.0",
"resolved": "http://registry.npmjs.org/handlebars/-/handlebars-4.0.0.tgz",
"integrity": "sha1-DgllGi8Ps8lJFgWDcQ1VH5Lm0q0=",
"requires": {
"optimist": "^0.6.1",
"source-map": "^0.1.40",
"uglify-js": "~2.3"
}
},
"http-errors": {
"version": "1.6.3",
"resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
@@ -369,6 +441,12 @@
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",
"integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"optional": true
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
@@ -379,6 +457,27 @@
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
},
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
"integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=",
"optional": true,
"requires": {
"is-buffer": "^1.1.5"
}
},
"lazy-cache": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz",
"integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=",
"optional": true
},
"longest": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
"integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=",
"optional": true
},
"media-typer": {
"version": "0.3.0",
"resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@@ -632,11 +731,26 @@
"resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.9.tgz",
"integrity": "sha1-PtqOZfI80qF+YTAbHwADOWr17No="
},
"repeat-string": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=",
"optional": true
},
"revalidator": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz",
"integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs="
},
"right-align": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz",
"integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=",
"optional": true,
"requires": {
"align-text": "^0.1.1"
}
},
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
@@ -758,27 +872,11 @@
"mime-types": "~2.1.18"
}
},
"uglify-js": {
"version": ">=2.6.0",
"resolved": "http://registry.npmjs.org/uglify-js/-/uglify-js-2.3.6.tgz",
"integrity": "sha1-+gmEdwtCi3qbKoBY9GNV0U/vIRo=",
"optional": true,
"requires": {
"async": "~0.2.6",
"optimist": "~0.3.5",
"source-map": "~0.1.7"
},
"dependencies": {
"optimist": {
"version": "0.3.7",
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz",
"integrity": "sha1-yQlBrVnkJzMokjB00s8ufLxuwNk=",
"optional": true,
"requires": {
"wordwrap": "~0.0.2"
}
}
}
"uglify-to-browserify": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz",
"integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=",
"optional": true
},
"uid-safe": {
"version": "2.1.5",
@@ -828,6 +926,12 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"window-size": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz",
"integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=",
"optional": true
},
"winston": {
"version": "2.1.1",
"resolved": "http://registry.npmjs.org/winston/-/winston-2.1.1.tgz",
@@ -876,6 +980,18 @@
"requires": {
"async-limiter": "~1.0.0"
}
},
"yargs": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz",
"integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=",
"optional": true,
"requires": {
"camelcase": "^1.0.2",
"cliui": "^2.1.0",
"decamelize": "^1.0.0",
"window-size": "0.1.0"
}
}
}
}

+ 2
- 1
package.json View File

@@ -1,5 +1,5 @@
{
"name": "hello-world",
"name": "demo-lbeckman314",
"version": "1.0.0",
"description": "Hello world with express and node.js",
"main": "app.js",
@@ -9,6 +9,7 @@
"author": "OSU",
"license": "ISC",
"dependencies": {
"ansi_up": "^4.0.3",
"body-parser": "^1.13.3",
"exec": "^0.2.1",
"express": "^4.16.3",

+ 6
- 5
server.js View File

@@ -1,9 +1,12 @@
const WebSocket = require('ws');
const https = require('https');
const fs = require('fs');

const server = require('./config.js');

const AU = require('ansi_up');
const ansi_up = new AU.default;


function noop() {}

function heartbeat() {
@@ -25,7 +28,7 @@ const wss = new WebSocket.Server({ server });
//console.log("Waiting for clients...");

wss.on('connection', function connection(ws) {
//console.log("Client connected!");
console.log("Client connected!");

ws.isAlive = true;
ws.on('pong', heartbeat);
@@ -203,9 +206,7 @@ wss.on('connection', function connection(ws) {

//let res = ""
child.stdout.on('data', (data) => {


let sendData = data.toString();
let sendData = ansi_up.ansi_to_html(data)

console.log(`stdout: ${data}`);
//console.log("SENDING TO CLIENT:", data.toString());

+ 168
- 0
tmp View File

@@ -0,0 +1,168 @@
[
{
"city": "Portland",
"country": "United States",
"lon": "-122.67",
"lat": "45.52",
"id": 6782,
"population": 1207757,
"mbps": "25.86",
"beach": false,
"airport": true,
"elevation": 61,
"pollution": "27.61514529",
"palms": false,
"totalhomicides": "5.4",
"femalehomicides": "1.0",
"tempjan": 40,
"tempfeb": 60,
"tempmar": 78,
"tempapr": 99,
"tempmay": 131,
"tempjun": 165,
"tempjul": 192,
"tempaug": 193,
"tempsep": 165,
"tempoct": 117,
"tempnov": 73,
"tempdec": 43,
"precipjan": 167,
"precipfeb": 120,
"precipmar": 112,
"precipapr": 74,
"precipmay": 60,
"precipjun": 44,
"precipjul": 18,
"precipaug": 29,
"precipsep": 50,
"precipoct": 86,
"precipnov": 162,
"precipdec": 179,
"uvjan": 29,
"uvfeb": 43,
"uvmar": 72,
"uvapr": 106,
"uvmay": 72,
"uvjun": 151,
"uvjul": 151,
"uvaug": 136,
"uvsep": 99,
"uvoct": 61,
"uvnov": 35,
"uvdec": 26,
"purchasingpower": "1",
"povertyindex": 0,
"image": "https://d13k13wj6adfdf.cloudfront.net/urban_areas/portland-or-90f71ea149.jpg"
},
{
"city": "Portland",
"country": "United States",
"lon": "-70.24",
"lat": "43.67",
"id": 5446,
"population": 99504,
"mbps": "25.86",
"beach": true,
"airport": true,
"elevation": 1,
"pollution": "10.39126601",
"palms": false,
"totalhomicides": "5.4",
"femalehomicides": "1.0",
"tempjan": -58,
"tempfeb": -46,
"tempmar": 5,
"tempapr": 64,
"tempmay": 123,
"tempjun": 176,
"tempjul": 207,
"tempaug": 199,
"tempsep": 154,
"tempoct": 96,
"tempnov": 39,
"tempdec": -28,
"precipjan": 94,
"precipfeb": 88,
"precipmar": 102,
"precipapr": 102,
"precipmay": 92,
"precipjun": 86,
"precipjul": 78,
"precipaug": 80,
"precipsep": 83,
"precipoct": 101,
"precipnov": 125,
"precipdec": 111,
"uvjan": 22,
"uvfeb": 36,
"uvmar": 65,
"uvapr": 100,
"uvmay": 65,
"uvjun": 144,
"uvjul": 145,
"uvaug": 129,
"uvsep": 94,
"uvoct": 56,
"uvnov": 29,
"uvdec": 19,
"purchasingpower": "1",
"povertyindex": 0,
"image": null
},
{
"city": "Portland",
"country": "Australia",
"lon": "141.59",
"lat": "-38.33",
"id": 6742,
"population": 10325,
"mbps": "11.69",
"beach": true,
"airport": true,
"elevation": 4,
"pollution": "19.18740067",
"palms": false,
"totalhomicides": "0.9",
"femalehomicides": "0.7",
"tempjan": 172,
"tempfeb": 176,
"tempmar": 167,
"tempapr": 144,
"tempmay": 123,
"tempjun": 106,
"tempjul": 99,
"tempaug": 104,
"tempsep": 116,
"tempoct": 130,
"tempnov": 142,
"tempdec": 158,
"precipjan": 33,
"precipfeb": 27,
"precipmar": 44,
"precipapr": 66,
"precipmay": 84,
"precipjun": 97,
"precipjul": 111,
"precipaug": 110,
"precipsep": 81,
"precipoct": 68,
"precipnov": 54,
"precipdec": 45,
"uvjan": 207,
"uvfeb": 181,
"uvmar": 131,
"uvapr": 77,
"uvmay": 131,
"uvjun": 29,
"uvjul": 32,
"uvaug": 51,
"uvsep": 86,
"uvoct": 128,
"uvnov": 166,
"uvdec": 195,
"purchasingpower": "1.0894169998",
"povertyindex": 0,
"image": null
}
]


Loading…
Cancel
Save