Showing posts with label ql. Show all posts
Showing posts with label ql. Show all posts

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)
^([a-zA-Z.]+)\(([0-9]+)\)$
doc \2 \1|rf
^http://.*$
open \0
^https://.*$
open \0


Friday, May 22, 2015

When "cd" has no arguments

In a previous post I wrote about commands and channels in Clive. Since then, things have evolved a bit I think it's worth a post.

The cd command, to change the current directory, no longer has a file name argument. Instead, it receives the directory entry to bet set as the new dot from the standard input, like everybody else does to operate on files!. That is:

        /tmp | cd

changes dot to /tmp.

As it can be seen, the first component of the pipe is not a command, but a file name. The Clive shell, Ql, is departing even more from the venerable UNIX sh. Ql commands correspond to streams as explained in the previous post. Since I wrote that post, Ql evolved as well.

Pipe-lines in Ql can be as simple as a set of file names (that is, pairs of a UNIX-like file name and predicate to find files of interest).  One example, list go source files:
       % ,~*.go
        Q/Q.go
        bltin.go
        lex.go
        nd.go
        ql/ql.go
        ql.go
        ql_test.go
        ...

(empty name, which defaults to ".", and ~*.go as predicate to locate Go files).

Further commands may be added to pipe-lines to process the directory entries found, like in the first example, or in this one:
        % ,~*.go | pf -l
        --rw-r--r--   2.1k  /zx/sys/src/clive/app/ql/Q/Q.go
        --rw-r--r--   6.3k  /zx/sys/src/clive/app/ql/bltin.go
        ...

For those cases when we really want to execute a command that takes no files as input we can just pipe nothing, so Ql does not assumes that the first series of names select files:

        % |date
        Fri May 22 19:31:06 CEST 2015

Doing a recursive grep is now delightful:
        % ,~*go |> gr '"Q"'
        Q/Q.go:27: os.Args[0] = "Q"

This used "|>" instead of "|" to ask Ql to retrieve file data and not just directory entries.

More on Ql soon.