Dzen multiplexer

dmplex is useful if you want to combine multiple input sources into a single dzen instance.

Basically we split the dzen window up into numbered sections and let dmplex handle the layout, we just need to supply the number and value of the section we want to alter.

Usage example:

# First we create a named pipe
$ mkfifo dmpipe

# Listen on the pipe and multiplex the input to dzen
$ tail -f dmpipe | dmplex | dzen2

# Now we can asynchronously write to the pipe and have dmplex handle the layout for us
$ echo "2 second section " > dmpipe
$ echo "1 first section ^r(100x5)" > dmpipe
$ echo "29 29th section" > dmpipe
$ echo "1 first section changed" > dmpipe

The syntax is: section number<space>actual dzen input

Haskell multiplexer

This solution takes a different approach. You can either specify ”-” to let it read from stdin or one or more files to read from. The input will then be concantanated and forwarded to dzen in the correct order.

Save the following to a file called dmhplex.hs:

import System
import System.IO
import Control.Concurrent
import Control.Concurrent.STM.TVar
import Control.Monad
import Control.Monad.STM
 
main = do
    vs <- mapM input =<< getArgs
    let writer old = do
        new <- atomically $ do
            new <- fmap concat $ mapM readTVar vs
            guard (new /= old)
            return new
        putStrLn new
        writer new
    writer ""
 
sourceToHandle "-" = return stdin
sourceToHandle f   = openFile f ReadMode
 
input f = do
    h <- sourceToHandle f
    v <- newTVarIO ""
    forkIO . forever $ hGetLine h >>= atomically . writeTVar v
    return v

Compile with: ghc –make dmhplex.hs

 
dzen/multiplexer.txt · Last modified: 2008/07/21 18:17 by rob
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki