From b99a8a6833a1b38882b463fd72784cd6d6f91d9e Mon Sep 17 00:00:00 2001 From: Michal Zielonka Date: Thu, 7 Oct 2021 23:25:09 +0200 Subject: try to reorganize modules per os We should make better split os specify code for FreeBSD and Linux. Idea comes from @liskin. --- src/Xmobar/Plugins/Monitors/Net/Common.hs | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Xmobar/Plugins/Monitors/Net/Common.hs (limited to 'src/Xmobar/Plugins/Monitors/Net/Common.hs') 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 +-- 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 -- cgit v1.2.3