Skip to content

Commit

Permalink
fix(webshell): fixing webshell multiline paste issue. Fixes #311
Browse files Browse the repository at this point in the history
  • Loading branch information
notthetup committed Jun 29, 2024
1 parent c1932ec commit f7f391f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/arl/fjage/shell/ConsoleShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

import java.io.*;
import java.util.logging.Logger;

import org.arl.fjage.connectors.ConnectionListener;
import org.arl.fjage.connectors.Connector;
import org.arl.fjage.connectors.WebSocketConnector;
import org.jline.reader.*;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
Expand All @@ -37,6 +39,9 @@ public class ConsoleShell implements Shell, ConnectionListener {
private AttributedStyle errorStyle = null;
private Logger log = Logger.getLogger(getClass().getName());

private static final String FORCE_BRACKETED_PASTE_ON = "FORCE_BRACKETED_PASTE_ON";
private static final String BRACKETED_PASTE_ON = "\033[?2004h";

/**
* Create a console shell attached to the system terminal.
*/
Expand Down Expand Up @@ -86,6 +91,8 @@ public ConsoleShell(Connector connector) {
public void connected(Connector connector) {
try {
if (console != null) {
// force bracketed paste mode on for websockets based shells
if (connector instanceof WebSocketConnector) console.callWidget(FORCE_BRACKETED_PASTE_ON);
console.callWidget(LineReader.REDRAW_LINE);
console.callWidget(LineReader.REDISPLAY);
}
Expand Down Expand Up @@ -134,6 +141,13 @@ public boolean isEscapeChar(char ch) {
console = LineReaderBuilder.builder().parser(parser).terminal(term).build();
console.setVariable(LineReader.DISABLE_COMPLETION, true);
console.setOpt(LineReader.Option.ERASE_LINE_ON_FINISH);
console.getWidgets().put(FORCE_BRACKETED_PASTE_ON, new Widget() {
@Override
public boolean apply() {
console.getTerminal().writer().write(BRACKETED_PASTE_ON);
return true;
}
});
}
}

Expand Down

0 comments on commit f7f391f

Please sign in to comment.