JS Plugin API

This contains a handful of javascript functions, used to create native TinyShell applications.

Shortcuts: run, onkeydown, onkeypress.

Object: Plugin

An application is basically a MooTools javascript class. The application is initiated with the member function run and the application should terminate itself by calling resume() on the TinyShell object. The following methods are special and might be called while the application is being executed.

Properties

  • description – (string) A short help text describing the application.

Example

All application plugins are programmed this way, for simple examples see Clear, Cowsay. For a bit more advanced examples see Cat or Sys.

Plugin Method: run

Application constructor function.

Syntax

  1. run(terminal, args, line);

Arguments

  1. terminal – (object) Reference to the calling TinyShell.shell instance. Use this object to access functions in the Core API.
  2. args – (array) Arguments passed to the command, not including the program name.
  3. line – (string) Complete unparsed command entered to execute the program.

Returns

  • (void) Return value is not expected

Example

If the application is called test, the command

  1. $ test -a "Test argument 1" -b arg2

Would cause the TinyShell object to start the application with similar code:

  1. this.proc = new TinyShell.plugins.test();
  2. proc.run(this, ["-a", "Test argument 1", "-b", "arg2"], "test -a \"Test argument 1\" -b arg2");

Plugin Method: onkeydown

Event is fired when a keyboard button is pressed down, while an instance of the application is running. Use this event to catch special buttons, like tab, enter, arrows, etc.

Syntax

  1. onkeydown(event);

Arguments

  1. event – (event) A native MooTools event object.

Returns

  • (boolean) If native onkeydown events should be fired true, otherwise false.

Example

This function is implemented in the default plugins: MySQL and Tiny.

Plugin Method: onkeypress

Event is fired when a keyboard button is pressed, while an instance of the application is running. Use this event to catch character inputs, like letters, number, etc.

Syntax

  1. onkeypress(event);

Arguments

  1. event – (event) A native MooTools event object.

Returns

  • (boolean) If native onkeypress events should be fired true, otherwise false.

Example

The function is used in the default plugin Tiny to make sure that some keyboards events are not caught by both onkeypress and onkeydown.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>