Namek edited this page Jun 5, 2016 · 9 revisions

Wiki: The Console

To see a full feature list of The Console itself go to main repo page.

Commands

The Console looks like a shell which is a little more special because commands can be scripted using JavaScript. There are 2 ways to provide custom commands:

  • single-file scripts
  • modules

List of built-in commands

  • alias - for command aliasing, e.g. alias map google_maps Warsaw
  • clear - clears output
  • exec - executes file of given path
  • repl - enables to switch Read-Eval-Print Loop

Single-file Scripts vs Modules

The main difference is this:

  1. single-file script is evaluated as a whole thing every time a command is invoked

  2. module is evaluated once (when loaded) and lives inside JavaScript all the time and can provide multiple commands or other things

Example of Single-file Scripts

currency.js which stands for currency command

assertInfo(args.length != 0,
	"Usages:\n" +
	" - currency 12 gbp eur\n" +
	" - currency gbp eur"
)

var amount = args.length == 3 ? args[0] : 1.0
var from = args[args.length == 3 ? 1 : 0]
var to = args[args.length == 3 ? 2 : 1]

var url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=' + from.toUpperCase() + to.toUpperCase() + '=X'
var data = Utils.requestUrl(url)
console.log(data.split(',')[1] * amount)

> Read a blogpost about implementation of currency command

Module

Same currency command would be implemented this way:

exports.commands = {
  currency: function(args) {
    // put here some code as for single-file script
  }
}

> Read more about Modules on Wiki

> Read this blogpost about filesystem module to see a more sophisticated example of module

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.