diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-10-03 16:27:58 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-10-03 16:27:58 +0200 |
commit | c6a089e448a8c270b106eb862419c4a49982e9d4 (patch) | |
tree | 689a8d3312dd582b8239708ce46c171eb4705438 | |
parent | 825356d7ee6887f38f9e9b35a55bbe721c682b40 (diff) | |
download | xmobar-c6a089e448a8c270b106eb862419c4a49982e9d4.tar.gz xmobar-c6a089e448a8c270b106eb862419c4a49982e9d4.tar.bz2 |
README updated to recent API changes (the last hopefully)
darcs-hash:20071003142758-d6583-50b99b7cc0e00e5c2ee1564f3a997f49a50e5993.gz
-rw-r--r-- | README | 40 |
1 files changed, 30 insertions, 10 deletions
@@ -267,27 +267,47 @@ Writing a plugin for Xmobar should be very simple. You need to create a data type with at least one constructor. Next you must declare this data type an instance of the Exec class, by -defining the 1 needed method (alternatively "start" or "run") and one -optional one (alias): +defining the 1 needed method (alternatively "start" or "run") and 2 +optional ones (alias and rate): start :: e -> (String -> IO ()) -> IO () run :: e -> IO String + rate :: e -> Int alias :: e -> String "start" must receive a callback to be used to display the String produced by the plugin. This method can be used for plugins that need -to perform asynchronous actions, or that need to set a refresh rate. -See Plugins/Date.hs or Plugins/PipeReader.hs for examples. - -"run" can be used for simpler plugins, that must be run every second. -See Plugins/HelloWorld.hs for an example. +to perform asynchronous actions. See Plugins/PipeReader.hs for an +example. + +"run" can be used for simpler plugins. If you define only "run" the +plugin will be run every second. To overwrite this default you just +need to implement "rate", which must return the number of tenth of +seconds between every successive runs. See Plugins/HelloWorld.hs for +an example of a plugin that runs just once, and Plugins/Date.hs for +one that implements "rate". + +Notice that Date could be implemented as: +instance Exec Date where + alias (Date _ a _) = a + start (Date f _ r) = date f r + +date :: String -> Int -> (String -> IO ()) -> IO () +date format r callback = do go + where go = do + t <- toCalendarTime =<< getClockTime + callback $ formatCalendarTime defaultTimeLocale format t + tenthSeconds r >> go + +This implementation is equivalent to the one you can read in +Plugins/Date.hs "alias" is the name to be used in the output template. Default alias will be the data type constructor. -That requires importing the plugin API (the Exec class definition), -that is exported by Plugins.hs. So you just need to import it in your -module with: +Implementing a plugin requires importing the plugin API (the Exec +class definition), that is exported by Plugins.hs. So you just need to +import it in your module with: import Plugins |