diff options
author | Michal Zielonka <michal.zielonka.8001@gmail.com> | 2021-10-07 23:25:09 +0200 |
---|---|---|
committer | Michal Zielonka <michal.zielonka.8001@gmail.com> | 2021-10-08 11:11:11 +0200 |
commit | b99a8a6833a1b38882b463fd72784cd6d6f91d9e (patch) | |
tree | 9537dcfe5eff2108937bf9a2160a5f15a7a266e5 /src/Xmobar/Plugins/Monitors/Net/Common.hs | |
parent | a845465fec735d9818a61d078337653b5293da5c (diff) | |
download | xmobar-b99a8a6833a1b38882b463fd72784cd6d6f91d9e.tar.gz xmobar-b99a8a6833a1b38882b463fd72784cd6d6f91d9e.tar.bz2 |
try to reorganize modules per os
We should make better split os specify code for FreeBSD and Linux.
Idea comes from @liskin.
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Net/Common.hs')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Net/Common.hs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Net/Common.hs b/src/Xmobar/Plugins/Monitors/Net/Common.hs new file mode 100644 index 0000000..16ed865 --- /dev/null +++ b/src/Xmobar/Plugins/Monitors/Net/Common.hs @@ -0,0 +1,50 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.Monitors.Net.Common +-- Copyright : (c) 2011, 2012, 2013, 2014, 2017, 2020 Jose Antonio Ortega Ruiz +-- (c) 2007-2010 Andrea Rossato +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org> +-- Stability : unstable +-- Portability : unportable +-- +-- A net device monitor for Xmobar +-- + +----------------------------------------------------------------------------- + +module Xmobar.Plugins.Monitors.Net.Common ( + NetDev(..) + , NetDevInfo(..) + , NetDevRawTotal + , NetDevRate + , NetDevRef + ) where + +import Data.IORef (IORef) +import Data.Time.Clock (UTCTime) +import Data.Word (Word64) + +data NetDev num = N String (NetDevInfo num) | NA deriving (Eq,Show,Read) +data NetDevInfo num = NI | ND num num deriving (Eq,Show,Read) + +type NetDevRawTotal = NetDev Word64 +type NetDevRate = NetDev Float + +type NetDevRef = IORef (NetDevRawTotal, UTCTime) + +-- The more information available, the better. +-- Note that names don't matter. Therefore, if only the names differ, +-- a compare evaluates to EQ while (==) evaluates to False. +instance Ord num => Ord (NetDev num) where + compare NA NA = EQ + compare NA _ = LT + compare _ NA = GT + compare (N _ i1) (N _ i2) = i1 `compare` i2 + +instance Ord num => Ord (NetDevInfo num) where + compare NI NI = EQ + compare NI ND {} = LT + compare ND {} NI = GT + compare (ND x1 y1) (ND x2 y2) = x1 `compare` x2 <> y1 `compare` y2 |