Page commands (`@cmd`)
pfrazee opened this issue · comments
Webterm is designed to run in "companion mode" with a browsing context. (That is, as a sidebar in an active browser window.) When in companion mode, webterm has an "active page."
"Page commands" would provide a way for the active page to export commands which are callable by webterm. This would be via some API such as:
navigator.registerCommand({
name: 'hello',
help: 'Say hello on the page',
usage: 'hello [-u/--uppercase]',
options: [
{
name: 'uppercase',
abbr: 'u',
help: 'Output hello in all caps',
boolean: true,
default: false
}
],
async command (opts) {
var div = document.createElement('div')
div.textContent = (opts.uppercase) ? 'HELLO' : 'hello'
document.body.append(div)
}
})
Page commands automatically have an @
prefix, which helps avoid collisions with the environment's installed commands. The above command would be invoked like this:
@hello -u
Page commands would be executed in the active page's context. The invocation and response would be serialized as a message and sent between the webterm context and the page context.