2017-09-29 18:29:36 +01:00
|
|
|
/** Script used in the commandline iframe. Communicates with background. */
|
2017-10-02 00:59:51 +01:00
|
|
|
|
2017-10-05 23:11:56 +01:00
|
|
|
import * as Messaging from './messaging'
|
2017-10-12 04:43:56 +01:00
|
|
|
import * as SELF from './commandline_frame'
|
2017-10-05 23:11:56 +01:00
|
|
|
|
2017-10-09 12:09:23 -07:00
|
|
|
let completions = window.document.getElementById("completions") as HTMLElement
|
2017-09-29 18:29:36 +01:00
|
|
|
let clInput = window.document.getElementById("tridactyl-input") as HTMLInputElement
|
2017-10-12 04:02:01 +01:00
|
|
|
|
|
|
|
export let focus = () => clInput.focus()
|
2017-09-29 18:29:36 +01:00
|
|
|
|
2017-10-28 05:11:10 +01:00
|
|
|
async function sendExstr(exstr) {
|
|
|
|
Messaging.message("commandline_background", "recvExStr", [exstr])
|
|
|
|
}
|
|
|
|
|
2017-09-29 18:29:36 +01:00
|
|
|
/* Process the commandline on enter. */
|
|
|
|
clInput.addEventListener("keydown", function (keyevent) {
|
|
|
|
if (keyevent.key === "Enter") {
|
|
|
|
process()
|
|
|
|
}
|
2017-10-09 12:40:23 -07:00
|
|
|
if (keyevent.key === "Escape") {
|
2017-10-09 23:55:24 +01:00
|
|
|
/** Bug workaround: clInput cannot be cleared during an "Escape"
|
|
|
|
* keydown event, presumably due to Firefox's internal handler for
|
|
|
|
* Escape. So clear clInput just after :)
|
|
|
|
*
|
|
|
|
* TODO: Report this on bugzilla.
|
|
|
|
*/
|
2017-10-13 22:10:33 -07:00
|
|
|
completions.innerHTML = ""
|
2017-10-09 23:55:24 +01:00
|
|
|
setTimeout(()=>{clInput.value = ""}, 0)
|
2017-10-28 05:11:10 +01:00
|
|
|
sendExstr("hidecmdline")
|
2017-10-09 12:40:23 -07:00
|
|
|
}
|
2017-09-29 18:29:36 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
/* Send the commandline to the background script and await response. */
|
|
|
|
function process() {
|
|
|
|
console.log(clInput.value)
|
2017-10-28 05:11:10 +01:00
|
|
|
sendExstr("hidecmdline")
|
|
|
|
sendExstr(clInput.value)
|
2017-10-13 22:10:33 -07:00
|
|
|
completions.innerHTML = ""
|
2017-09-29 18:29:36 +01:00
|
|
|
clInput.value = ""
|
|
|
|
}
|
2017-10-02 00:59:51 +01:00
|
|
|
|
2017-10-12 04:02:01 +01:00
|
|
|
export function fillcmdline(newcommand?: string){
|
2017-10-24 17:38:52 +01:00
|
|
|
if (newcommand != "") {
|
2017-10-19 20:34:16 +01:00
|
|
|
clInput.value = newcommand + " "
|
2017-10-06 04:16:02 +01:00
|
|
|
}
|
|
|
|
// Focus is lost for some reason.
|
2017-10-12 04:02:01 +01:00
|
|
|
focus()
|
2017-10-05 23:11:56 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 04:43:56 +01:00
|
|
|
export function changecompletions(newcompletions: string) {
|
2017-10-09 12:09:23 -07:00
|
|
|
completions.innerHTML = newcompletions
|
|
|
|
}
|
|
|
|
|
2017-10-05 23:11:56 +01:00
|
|
|
function handler(message) {
|
2017-10-12 04:43:56 +01:00
|
|
|
SELF[message.command](...message.args)
|
2017-10-05 23:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Messaging.addListener('commandline_frame', handler)
|
|
|
|
} catch(e) {
|
|
|
|
console.error("WAHWAH", e)
|
|
|
|
}
|