Adding the ability to use ESC to enter scroll mode, ESC twice to exit and T or ENTER to return to chat
This commit is contained in:
parent
cc3f62dfbf
commit
7d3ab3e2ee
59
sshChat.js
59
sshChat.js
@ -52,6 +52,12 @@ const screen = blessed.screen({
|
|||||||
fastCSR: true
|
fastCSR: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Debug ONLY
|
||||||
|
// screen.on('keypress', function(ch, key){
|
||||||
|
// console.log(JSON.stringify(key));
|
||||||
|
// });
|
||||||
|
|
||||||
let mainBox = blessed.box({
|
let mainBox = blessed.box({
|
||||||
parent: screen,
|
parent: screen,
|
||||||
top: 0,
|
top: 0,
|
||||||
@ -125,10 +131,10 @@ sidebarBox.setLabel("Peers since connection: 0")
|
|||||||
|
|
||||||
const originalLog = console.log;
|
const originalLog = console.log;
|
||||||
console.log = (...args) => {
|
console.log = (...args) => {
|
||||||
mainBox.setContent(mainBox.getContent() + `\n${args.join(' ')}`);
|
mainBox.setContent(mainBox.getContent() + `\n${args.join(' ')}`);
|
||||||
updateScroll()
|
updateScroll()
|
||||||
stdinBox.clearValue();
|
stdinBox.clearValue();
|
||||||
screen.render()
|
screen.render()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +145,7 @@ const publicKey = crypto.randomBytes(32)
|
|||||||
// Create the swarm and pass in the public key
|
// Create the swarm and pass in the public key
|
||||||
const swarm = new Hyperswarm()
|
const swarm = new Hyperswarm()
|
||||||
|
|
||||||
const commandDir = __dirname +'/commands/';
|
const commandDir = __dirname + '/commands/';
|
||||||
const commandFiles = fs.readdirSync(commandDir);
|
const commandFiles = fs.readdirSync(commandDir);
|
||||||
|
|
||||||
const commands = {}
|
const commands = {}
|
||||||
@ -195,21 +201,21 @@ async function handleCommand(input) {
|
|||||||
console.log("Command not found.")
|
console.log("Command not found.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DISCORD_USERID.length !== 0){
|
if (DISCORD_USERID.length !== 0) {
|
||||||
|
for (const conn of conns)
|
||||||
|
conn.write(`${DISCORD_USERID[0]}: ${input}`)
|
||||||
|
} else {
|
||||||
for (const conn of conns)
|
for (const conn of conns)
|
||||||
conn.write(`${DISCORD_USERID[0]}: ${input}`)
|
|
||||||
} else {
|
|
||||||
for (const conn of conns)
|
|
||||||
conn.write(`${USERNAME}: ${input}`)
|
conn.write(`${USERNAME}: ${input}`)
|
||||||
}
|
}
|
||||||
if (DISCORD_USERID.length !== 0){
|
if (DISCORD_USERID.length !== 0) {
|
||||||
console.log(`${DISCORD_USERID[0]}: ${input}`)
|
console.log(`${DISCORD_USERID[0]}: ${input}`)
|
||||||
} else {
|
} else {
|
||||||
console.log(`${USERNAME}: ${input}`)
|
console.log(`${USERNAME}: ${input}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -309,6 +315,23 @@ stdinBox.focus();
|
|||||||
screen.render()
|
screen.render()
|
||||||
|
|
||||||
// Quit on Escape, q, or Control-C.
|
// Quit on Escape, q, or Control-C.
|
||||||
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
|
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
|
||||||
return process.exit(0);
|
console.log("Sending close message...")
|
||||||
|
for (let conn of conns) {
|
||||||
|
conn.write(`CLOSED: ${publicKey.toString('hex')}`)
|
||||||
|
}
|
||||||
|
(async () => {
|
||||||
|
|
||||||
|
await sleep(2000)
|
||||||
|
process.exit()
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
let scrollCount = 0
|
||||||
|
|
||||||
|
// Return to chat
|
||||||
|
screen.key(['t', 'enter'], function (ch, key) {
|
||||||
|
stdinBox.focus();
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user