summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Config.hs3
-rw-r--r--NEWS7
-rw-r--r--Plugins/Date.hs2
-rw-r--r--Plugins/Uptime.hs51
-rw-r--r--README12
5 files changed, 66 insertions, 9 deletions
diff --git a/Config.hs b/Config.hs
index 6eb55a0..23bf997 100644
--- a/Config.hs
+++ b/Config.hs
@@ -32,6 +32,7 @@ import Plugins.CommandReader
import Plugins.StdinReader
import Plugins.XMonadLog
import Plugins.EWMH
+import Plugins.Uptime
#ifdef INOTIFY
import Plugins.Mail
@@ -108,7 +109,7 @@ infixr :*:
-- the 'Runnable.Runnable' Read instance. To install a plugin just add
-- the plugin's type to the list of types (separated by ':*:') appearing in
-- this function's type signature.
-runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: CommandReader :*: StdinReader :*: XMonadLog :*: EWMH :*:
+runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: CommandReader :*: StdinReader :*: XMonadLog :*: EWMH :*: Uptime :*:
#ifdef INOTIFY
Mail :*: MBox :*:
#endif
diff --git a/NEWS b/NEWS
index 1b70e37..936dd8a 100644
--- a/NEWS
+++ b/NEWS
@@ -20,13 +20,14 @@ _New features_
- Window borders: configuration options `border` and `borderColor`
allow drawing borders around xmobar's window.
- - MPD: updated to libmpd 1.5. New fields `ppos` (playlist position)
- and `remaining` (remaining time). New configuration options to
- specify MPD's host, user name and password.
+ - New plugin, `Uptime`, showing the system uptime.
- New Monitor option (`-P`) to enable displaying the `%` sign in
percentages; the sign is now never included by default.
- New 'run once' commands, by specifying a 0 refresh rate in `Run
Com` ([issue 26]).
+ - MPD monitor: updated to libmpd 1.5. New fields `ppos` (playlist
+ position) and `remaining` (remaining time). New configuration
+ options to specify MPD's host, user name and password.
- Battery monitor: new `watts` and `timeleft` fields (Petr Rockai),
and specific arguments to control coloring and thresholds of the
former.
diff --git a/Plugins/Date.hs b/Plugins/Date.hs
index a4ed80f..bfcb132 100644
--- a/Plugins/Date.hs
+++ b/Plugins/Date.hs
@@ -16,7 +16,7 @@
--
-----------------------------------------------------------------------------
-module Plugins.Date where
+module Plugins.Date (Date(..)) where
import Plugins
diff --git a/Plugins/Uptime.hs b/Plugins/Uptime.hs
new file mode 100644
index 0000000..6d81acd
--- /dev/null
+++ b/Plugins/Uptime.hs
@@ -0,0 +1,51 @@
+------------------------------------------------------------------------------
+-- |
+-- Module : Plugins.Uptime
+-- Copyright : (c) 2010 Jose Antonio Ortega Ruiz
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : jao@gnu.org
+-- Stability : unstable
+-- Portability : unportable
+-- Created: Sun Dec 12, 2010 20:26
+--
+--
+-- Uptime
+--
+------------------------------------------------------------------------------
+
+
+module Plugins.Uptime (Uptime(..)) where
+
+import Plugins
+
+import qualified Data.ByteString.Lazy.Char8 as B
+
+data Uptime = Uptime String Int
+ deriving (Read, Show)
+
+instance Exec Uptime where
+ alias (Uptime a _) = a
+ run (Uptime _ _) = uptime
+ rate (Uptime _ r) = r
+
+readUptime :: IO Float
+readUptime =
+ fmap (read . B.unpack . head . B.words) (B.readFile "/proc/uptime")
+
+secsPerDay :: Integer
+secsPerDay = 24 * 3600
+
+uptime :: IO String
+uptime = do
+ t <- readUptime
+ let tsecs = floor t
+ secs = tsecs `mod` secsPerDay
+ days = tsecs `quot` secsPerDay
+ hrs = secs `quot` 3600
+ mins = (secs `mod` 3600) `div` 60
+ dstr | days == 0 = ""
+ | otherwise = show days ++ "d "
+ str x | x < 10 = '0':show x
+ | otherwise = show x
+ return $ dstr ++ str hrs ++ ":" ++ str mins
diff --git a/README b/README
index 4e2b453..8de3050 100644
--- a/README
+++ b/README
@@ -298,8 +298,8 @@ date plugin. These plugins install the following internal commands:
`Weather`, `Network`, `Wireless` (optional), `Memory`, `Swap`, `Cpu`,
`MultiCpu`, `Battery`, `TopProc`, `TopMem`, `DiskU`, `DiskIO`,
`Thermal`, `CpuFreq`, `CoreTemp`, `MPD` (optional), `Mail` (optional),
-`MBox` (optional), `Date`, `StdinReader`, `CommandReader`, and
-`PipeReader`.
+`MBox` (optional), `Date`, `Uptime`, `StdinReader`, `CommandReader`,
+and `PipeReader`.
To remove them see below Installing/Removing a Plugin
@@ -657,8 +657,12 @@ can be used in the output template as `%mydate%`
`Date Format Alias RefreshRate`
-- Format is a time format string, as accepted by the standard UNIX
- utility `date`.
+- Format is a time format string, as accepted by the standard ISO C
+ `strftime` function (or Haskell's `formatCalendarTime`).
+
+`Uptime Alias RefreshRate`
+
+- Shows system uptime.
`CommandReader "/path/to/program" Alias`