Skip to content

Commit eaebaca

Browse files
javier-godoypaodb
authored andcommitted
refactor: add bellSound and bellStyle as properties of fc-xterm
Close #73
1 parent a6ca802 commit eaebaca

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/main/java/com/flowingcode/vaadin/addons/xterm/XTermBase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ private CompletableFuture<JsonValue> invoke(boolean hasResult, String name, Obje
124124
} else {
125125
arg = (Serializable) args[0];
126126
}
127-
return executeJs(false, "this.terminal.options[$0]=$1", name, arg);
127+
if (name.equals("bellStyle") || name.equals("bellSound")) {
128+
return executeJs(false, "this[$0]=$1", name, arg);
129+
} else {
130+
return executeJs(false, "this.terminal.options[$0]=$1", name, arg);
131+
}
128132
} else if (args == null || args.length == 0) {
129133
return executeJs(hasResult, "return this.terminal[$0]()", name);
130134
} else if (args.length == 1) {

src/main/resources/META-INF/frontend/fc-xterm/xterm-element.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ export class XTermElement extends LitElement implements TerminalMixin {
136136
terminal: Terminal;
137137
disabled: boolean = false;
138138
node: XTermElement;
139-
139+
140+
bellSound: string;
141+
bellStyle: 'none' | 'sound'
142+
140143
customKeyEventHandlers: CustomKeyEventHandlerRegistry;
141144

142145
render(): TemplateResult {
@@ -150,6 +153,12 @@ export class XTermElement extends LitElement implements TerminalMixin {
150153
this.customKeyEventHandlers = new CustomKeyEventHandlerRegistry();
151154
this.terminal = new Terminal();
152155
this.node = this;
156+
157+
//https://gist.github.com/literallylara/7ece1983fab47365108c47119afb51c7
158+
//(C) Lara Sophie Schütt 2016, CC0
159+
for(var i=44100*0.1,d="";i--;)d+=String.fromCharCode(~~((Math.sin(i/44100*2*Math.PI*800)+1)*128));
160+
this.bellSound = "data:Audio/WAV;base64,"+btoa("RIFFdataWAVEfmt "+atob("EAAAAAEAAQBErAAARKwAAAEACABkYXRh/////w==")+d);
161+
this.bellStyle = 'none';
153162
}
154163

155164
connectedCallback() {
@@ -163,11 +172,12 @@ export class XTermElement extends LitElement implements TerminalMixin {
163172
term.onData(e => {
164173
term.write(e.replace(/\r/g,'\x1b[<N\n'));
165174
});
166-
167-
//https://gist.github.com/literallylara/7ece1983fab47365108c47119afb51c7
168-
//(C) Lara Sophie Schütt 2016, CC0
169-
for(var i=44100*0.1,d="";i--;)d+=String.fromCharCode(~~((Math.sin(i/44100*2*Math.PI*800)+1)*128));
170-
term.options.bellSound = "data:Audio/WAV;base64,"+btoa("RIFFdataWAVEfmt "+atob("EAAAAAEAAQBErAAARKwAAAEACABkYXRh/////w==")+d);
175+
176+
term.onBell(() => {
177+
if (this.bellStyle == 'sound') {
178+
new Audio(this.bellSound).play();
179+
}
180+
});
171181

172182
term.attachCustomKeyEventHandler(ev => {
173183
if (ev.type!=='keydown') return false;

0 commit comments

Comments
 (0)