Re: [dev] [acmebrowse] Mouse driven interface for edbrowse

From: Paul Onyschuk <ptmelville_AT_gmail.com>
Date: Tue, 29 Jul 2014 12:30:57 +0200

I attached a version of acmebrowse that doesn't require tmux. I removed
readme from the script - you can still find it in a previous message.
Only pipes are used. Below is a generalized version that could be
adapted for other programs:

> #!/bin/rc
>
> . 9.rc
> . $PLAN9/lib/acme.rc
>
> fn event {
> switch($1$2){
> case E* # write to body or tag
> case F* # generated by ourselves; ignore
> case K* # type away we do not care
> case Mi # mouse: text inserted in tag
> case MI # mouse: text inserted in body
> case Md # mouse: text deleted from tag
> case MD # mouse: text deleted from body
> winwriteevent $*
> case Mx MX # button 2 in tag or body
> echo $9
> case Ml ML # button 3 in tag or body
> echo /$9/
> }
> }
>
> newwindow
> _AT_{wineventloop} | edbrowse | winwrite body

wineventloop is exucuted in a subshell and the output is piped into
edbrowse (simple echo is used within a loop). This approach has few
advantages. Buffering issues are avoided as in case of fifos or
redirection to a file:

$ tail -f input | edbrowse
$ echo "some command" >> input

Blocking the reads from edbrowse stdout is unnecessary, since it is
piped all the time into acme window. Yet the content of a window can be
erased if need using:

> echo -n , | winwrite addr
> winctl 'dot=addr'
> winwrite data

Blocking in acmebrowse is used now for a different purpose: jumping to
the top of a window. If you don't mind the cursor ending at a bottom of
content, you can get away without "kill $apid/wait" approach.

Window name in acme matches now the filename/URL opened in edbrowse. I
find it more useful than the name of a script.

As if PCRE wasn't a mess enough, edbrowse doesn't use them it in a
straight way. Some behavior was changed to match ed more closly. I
decided that the best way to sanitize them is to turn special characters
into dots:

$ echo $regexp | tr '^$[]+*?\/' '.'

This avoids the escape hell, when you want to repeat a search.

I'm pretty satisfied with the script. Other than that the naming of
functions/commands could be improved I guess.

-- 
Paul Onyschuk

Received on Tue Jul 29 2014 - 12:30:57 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 29 2014 - 12:36:11 CEST