Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Page commands (@cmd) #3

Open
pfrazee opened this issue Nov 18, 2019 · 0 comments
Open

Page commands (@cmd) #3

pfrazee opened this issue Nov 18, 2019 · 0 comments

Comments

@pfrazee
Copy link
Member

pfrazee commented Nov 18, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant