Skip to content

Commit

Permalink
Telnet, auto-scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed May 13, 2024
1 parent e3e4629 commit dca57e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Protest/Front/mono/scroll.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 20 additions & 8 deletions Protest/Front/telnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Telnet extends Window {
constructor(params) {
super();

this.params = params ? params : {host:"", isAnsi:true, bell:true};
this.params = params ? params : {host:"", ansi:true, autoScroll:true, bell:true};

this.cursor = {x:0, y:0};
this.chars = {};
Expand Down Expand Up @@ -36,8 +36,8 @@ class Telnet extends Window {
this.connectButton = this.AddToolbarButton("Connect", "mono/connect.svg?light");
this.optionsButton = this.AddToolbarButton("Options", "mono/wrench.svg?light");
this.AddToolbarSeparator();
this.sendKeyButton = this.AddToolbarButton("Send key", "mono/keyboard.svg?light");
this.pasteButton = this.AddToolbarButton("Paste", "mono/clipboard.svg?light");
this.sendKeyButton = this.AddToolbarButton("Send key", "mono/keyboard.svg?light");

this.content.tabIndex = 1;
this.content.classList.add("terminal-content");
Expand All @@ -55,8 +55,8 @@ class Telnet extends Window {

this.connectButton.onclick = ()=> this.ConnectDialog(this.params.host);
this.optionsButton.onclick = ()=> this.OptionsDialog();
this.sendKeyButton.onclick = ()=> this.CustomKeyDialog();
this.pasteButton.onclick = ()=> this.ClipboardDialog();
this.sendKeyButton.onclick = ()=> this.CustomKeyDialog();

this.ConnectDialog(this.params.host, true);

Expand Down Expand Up @@ -125,7 +125,7 @@ class Telnet extends Window {
}

OptionsDialog() {
const dialog = this.DialogBox("168px");
const dialog = this.DialogBox("200px");
if (dialog === null) return;

const okButton = dialog.okButton;
Expand All @@ -138,7 +138,7 @@ class Telnet extends Window {

const ansiCheckbox = document.createElement("input");
ansiCheckbox.type = "checkbox";
ansiCheckbox.checked = this.params.isAnsi;
ansiCheckbox.checked = this.params.ansi;
innerBox.appendChild(ansiCheckbox);
this.AddCheckBoxLabel(innerBox, ansiCheckbox, "Escape ANSI codes");

Expand All @@ -151,9 +151,19 @@ class Telnet extends Window {
innerBox.appendChild(bellCheckbox);
this.AddCheckBoxLabel(innerBox, bellCheckbox, "Play bell sound");

innerBox.appendChild(document.createElement("br"));
innerBox.appendChild(document.createElement("br"));

const autoScrollCheckbox = document.createElement("input");
autoScrollCheckbox.type = "checkbox";
autoScrollCheckbox.checked = this.params.autoScroll;
innerBox.appendChild(autoScrollCheckbox);
this.AddCheckBoxLabel(innerBox, autoScrollCheckbox, "Auto-scroll");

okButton.onclick = ()=> {
this.params.isAnsi = ansiCheckbox.checked;
this.params.ansi = ansiCheckbox.checked;
this.params.bell = bellCheckbox.checked;
this.params.autoScroll = autoScrollCheckbox.checked;
dialog.Close();
};
}
Expand Down Expand Up @@ -444,7 +454,7 @@ class Telnet extends Window {
break;

case "\x1b": //esc
if (this.params.isAnsi) {
if (this.params.ansi) {
i += this.HandleEscSequence(data, i) - 1;
}
else {
Expand Down Expand Up @@ -488,7 +498,9 @@ class Telnet extends Window {
this.cursorElement.style.left = Telnet.CURSOR_WIDTH * this.cursor.x + "px";
this.cursorElement.style.top = Telnet.CURSOR_HEIGHT * this.cursor.y + "px";

this.cursorElement.scrollIntoView();
if (this.params.autoScroll) {
this.cursorElement.scrollIntoView();
}
}

HandleEscSequence(data, index) { //Control Sequence Introducer
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const MENU = {
{ t:"Watchdog", i:"mono/watchdog.svg?light", g:"documentation", h:false, f:params=> new Watchdog(params), k:"" },
{ t:"Team chat", i:"mono/chat.svg?light", g:"documentation", h:false, f:params=> new Chat(), k:"messages" },

{ t:"Telnet", i:"mono/telnet.svg?light", g:"tools", h:true, f:params=> new Telnet({host:"", isAnsi:true, bell:true}) },
{ t:"Telnet", i:"mono/telnet.svg?light", g:"tools", h:true, f:params=> new Telnet({host:"", ansi:true, autoScroll:true, bell:true}) },
//{ t:"Secure shell", i:"mono/ssh.svg?light", g:"tools", h:true, f:params=> {} },
{ t:"WMI client", i:"mono/wmi.svg?light", g:"tools", h:false, f:params=> new Wmi(params), k:"windows management instrumentation viewer" },
{ t:"SNMP polling", i:"mono/snmp.svg?light", g:"tools", h:false, f:params=> new Snmp(params) },
Expand Down

0 comments on commit dca57e1

Please sign in to comment.