lighthouse-provider

1.2.1 • Public • Published

lighthouse-provider

Build Status

This module provides a way to easily define providers for menu entries to the lighthouse launcher. It depends on generators, so run node with the --harmony flag (or use io.js).

Quickstart

lighthouse.js:

#!/usr/bin/env node
var Lighthouse = require('lighthouse-provider');
var lighthouse = new Lighthouse();

lighthouse.attach(function *(input) {
	return {
		icon: '/some/path/to/icon.png',
		title: 'Execute [' + input + ']',
		action: input
	};
});

process.stdin.pipe(lighthouse).pipe(process.stdout);

You may now use this file as a cmd file for lighthouse.

API

Once you created a provider instance via

var lighthouse = new Lighthouse();

You can use it as a duplex stream:

process.stdin.pipe(lighthouse).pipe(process.stdout);

lighthouse.attach(identifier, handler)

This function allows you to provide a generator function for asynchronous data retrieval (will be run through co).

Identifier

The identifier parameter is optional and may be used, to filter for specific handlers.

So if your input to lighthouse looks like :someId actual input, only the handlers with the identifier someId will be called. You may use :: as an identifier to filter out only those handlers without an identifier.

Handler Function

The handler function will be called with whatever the user types into lighthouse (minus the identifier). It should return a co yieldable (so you may use a generator function here). As a second argument, it is provided a boolean signifying if the handlers flag was supplied. Your function may then do whatever it likes with it, retrieve data from the web, a file system or simply reformat the input etc.

Once done, simply return an object of the form:

{
	icon: '/some/path/to/icon.png',
	title: 'Execute [' + input + ']',
	action: input
}

The icon property may be omitted, but title and action are required. lighthouse-provider will then take care of escaping and formatting the output for you.

If you return anything but an object, your handler will not be output.

An array may be returned for multiple new entries.

lighthouse-provider-common

You may want to check out the lighthouse-provider-common module, for some useful providers.

Readme

Keywords

none

Package Sidebar

Install

npm i lighthouse-provider

Weekly Downloads

0

Version

1.2.1

License

BSD-3-Clause

Last publish

Collaborators

  • paulavery