Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing webshell multiline paste issue #313

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading