Skip to content

Commit

Permalink
feat: add Java API for setting insertMode
Browse files Browse the repository at this point in the history
Part of #17
  • Loading branch information
javier-godoy committed Oct 13, 2021
1 parent 7a64e44 commit c5c0ea7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
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);
}

}
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 @@ -54,7 +55,7 @@ class ConsoleAddon extends TerminalAddon<IConsoleMixin> {
this.cursorBackward({params:[1]});
return true;
} else if (buffer.lines.get(buffer.y+buffer.ybase).isWrapped) {
this.cursorPrecedingLine({params:[1]});
this.cursorPrecedingLine({params:[1]});
scanEOL();
return true;
} else {
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 @@ -185,13 +181,27 @@ type Constructor<T = {}> = new (...args: any[]) => T;
export function XTermConsoleMixin<TBase extends Constructor<TerminalMixin>>(Base: TBase) {
return class XTermConsoleMixin extends Base implements IConsoleMixin {
escapeEnabled: Boolean;

connectedCallback() {
super.connectedCallback();

let addon = new ConsoleAddon();
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');
}
}

}
}

0 comments on commit c5c0ea7

Please sign in to comment.