Tuesday, February 23, 2016

Clive channels and plumbing

In Clive, we can run
eco http://lsub.org >[out:ink]
to display a web page. Here, eco is Clive's echo, and the redirection at the end is the standard ql(1) syntax to make the standard output channel be the channel named ink. Ql is the Clive's shell.

In the same way,
eco look:ix.go:4 >[out:ink]
opens ix.go in the ix shell and selects line 4; also
eco exec:cmd >[out:ink]
opens a new window in ix with  the cmd output.

I/O in Clive relies on named channels. Instead of 0, 1, and 2 file descriptors in UNIX, Clive has in, out, and err channels. A command may use cmd.In("in") to get the input channel in, or cmd.Out("err") to get the output channel err. The command gets a nil channel if there's no such channel.

This is used by ix(1) to provide an extra output channel named ink. This channel is used by commands to output graphical user interfaces through it. If a command creates a web control, writes it to a buffer, and sends the buffer through this channel, the user interface will show the control and get in touch with the command.

The convention is that through the ink channel we get URLs, or HTML, or strings starting with "look:" or "exec:".

A look package used by ix inspects the look strings read from the ink channel and executes the commands configured by the user. Thus, the ink channel is enough to provide the plumbing facilities provided in Plan 9 by its plumber command.

As another example, with this configuration file, a click with the button-3 at ix(1) opens a window with the manual.
# $home/lib/look: rules for look(2), used by ix(1)
doc \2 \1|rf
open \0
open \0