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

feat: add Java API for setting insertMode #21

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ default Registration addLineListener(ComponentEventListener<LineEvent> listener)
Component terminal = getElement().getComponent().get();
return ComponentUtil.addListener(terminal, LineEvent.class, listener);
}

/** Set the insert mode. */
default void setInsertMode(boolean insertMode) {
((XTermBase) this).executeJs("this.insertMode=$0", insertMode);
}

}
8 changes: 7 additions & 1 deletion src/main/java/com/flowingcode/vaadin/addons/xterm/XTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@
@Tag("fc-xterm")
@JsModule("./fc-xterm/xterm.ts")
public class XTerm extends XTermBase
implements ITerminalFit, ITerminalConsole, ITerminalClipboard {}
implements ITerminalFit, ITerminalConsole, ITerminalClipboard {

public XTerm() {
setInsertMode(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TerminalMixin, TerminalAddon } from '@vaadin/flow-frontend/fc-xterm/xte

interface IConsoleMixin extends TerminalMixin {
escapeEnabled: Boolean;
insertMode: Boolean;
}

class ConsoleAddon extends TerminalAddon<IConsoleMixin> {
Expand Down Expand Up @@ -145,12 +146,7 @@ class ConsoleAddon extends TerminalAddon<IConsoleMixin> {
this.$node.customKeyEventHandlers.register(ev=> ev.key=='Delete', ()=> terminal.write('\x1b[<D')),

this.$node.customKeyEventHandlers.register(ev=> ev.key=='Insert', ev=>{
let ins = inputHandler._coreService.modes.insertMode;
if (ins) {
terminal.write('\x1b[4l\x1b[2 q');
} else {
terminal.write('\x1b[4h\x1b[3 q');
}
this.$.insertMode = !this.$.insertMode;
}),

this.$node.customKeyEventHandlers.register(ev=> ev.key=='Enter', ()=>{
Expand Down Expand Up @@ -193,5 +189,19 @@ export function XTermConsoleMixin<TBase extends Constructor<TerminalMixin>>(Base
addon.$=this;
this.node.terminal.loadAddon(addon);
}
}
}

get insertMode(): Boolean {
return this.node.terminal.modes.insertMode;
}

set insertMode(value: Boolean) {
if (value) {
this.node.terminal.write('\x1b[4h\x1b[3 q');
} else {
this.node.terminal.write('\x1b[4l\x1b[2 q');
}
}

}
}