Node Zephyros Callback
Like node-zephyros, but simplified, and prefer callbacks then promise.
With Zephros, you are able to get window_ids, screen_ids, app_ids and talk ot listen to them. Mainly it is used to add key bindings for window resizing and moving.
Thie module is a thin wrapper on Zephros's protocol. It has language bindings in several languages, even one called [node-zephyros] wrapped with promise. You may find [more about the bindings in the repo][bindngs].
Usage
We got lots of callbacks:
npm install --save node-zephyros-callback
z = require './bind.coffee' require 'proto-task-wait-done' zconnect port: 1235-> zall_windows # return windowsmap zsend window_id'title' zsend window_id'app' zsend app_id'title' consolelog titleapp_title zsend null'bind''e''cmd''alt'-> consolelog 'cmd alt e' zbind 'l''cmd''alt'-> zfocused_window zmain_screen zsend screen_id'frame_including_dock_and_menu' half_w = Mathround framew / 2 half_h = Mathround frameh / 2 zsend window_id'set_frame' x: 0 y: 0 w: half_w h: frameh -> zbind 'r''cmd''alt'-> zfocused_window # console.log 'window_id', window_id zmain_screen zsend screen_id'frame_including_dock_and_menu' half_w = Mathround framew / 2 half_h = Mathround frameh / 2 zsend window_id'set_frame' x: half_w y: 0 w: half_w h: frameh ->
Guide
Before using this, you should read its protocol and have some basic ideas about using that.
node-zephyros-callback
connects to Zephros with a TCP connection, which means you need to set Zephros to listen to a TCP port in its preference. The default port is 1235
, code it like this:
z = require 'node-zephyros-callback'zconnect port: 1235-> # `z` is the entry # do stuffs after connection is established
Every message was consists of 4 parts like: [msg_id, receiver_id, method, *args]
,
node-zephyros-callback
will take case of msg_id
and make it into a callback,
so you don't have to write msg_id
, but receiver_id
s are required at times.
Basicly, z.send
is for sending messages and attaching each with a callback, followed with a window_id
-- the receiver_id
, a 'title'
-- the method
, some or zero *args
, and an optional callback, like this demo:
zall_windows # return windowsmap zsend window_id'title' zsend window_id'app' zsend app_id'title' consolelog titleapp_title
Top level APIs use null
as receiver_id
, so they are attached to z
directly.
That why there's code like this:
zall_windows # `windows` is an array of `id`s, or exactly an array of numbers by now
Events are attached to z
too, you may write like this:
zwindow_moved consolelog window_id
More
Please read test.coffee
and my.coffee
for what I have now.
This module is not well tested, you may still find some problems.
If you find bugs, please report at issue or folk it, the code is short.
License
BSD