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 (NetDev num -> NetDev num -> Bool
forall num. Eq num => NetDev num -> NetDev num -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetDev num -> NetDev num -> Bool
$c/= :: forall num. Eq num => NetDev num -> NetDev num -> Bool
== :: NetDev num -> NetDev num -> Bool
$c== :: forall num. Eq num => NetDev num -> NetDev num -> Bool
Eq,Int -> NetDev num -> ShowS
forall num. Show num => Int -> NetDev num -> ShowS
forall num. Show num => [NetDev num] -> ShowS
forall num. Show num => NetDev num -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetDev num] -> ShowS
$cshowList :: forall num. Show num => [NetDev num] -> ShowS
show :: NetDev num -> String
$cshow :: forall num. Show num => NetDev num -> String
showsPrec :: Int -> NetDev num -> ShowS
$cshowsPrec :: forall num. Show num => Int -> NetDev num -> ShowS
Show,ReadPrec [NetDev num]
ReadPrec (NetDev num)
ReadS [NetDev num]
forall num. Read num => ReadPrec [NetDev num]
forall num. Read num => ReadPrec (NetDev num)
forall num. Read num => Int -> ReadS (NetDev num)
forall num. Read num => ReadS [NetDev num]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NetDev num]
$creadListPrec :: forall num. Read num => ReadPrec [NetDev num]
readPrec :: ReadPrec (NetDev num)
$creadPrec :: forall num. Read num => ReadPrec (NetDev num)
readList :: ReadS [NetDev num]
$creadList :: forall num. Read num => ReadS [NetDev num]
readsPrec :: Int -> ReadS (NetDev num)
$creadsPrec :: forall num. Read num => Int -> ReadS (NetDev num)
Read)
data NetDevInfo num = NI | ND num num deriving (NetDevInfo num -> NetDevInfo num -> Bool
forall num. Eq num => NetDevInfo num -> NetDevInfo num -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetDevInfo num -> NetDevInfo num -> Bool
$c/= :: forall num. Eq num => NetDevInfo num -> NetDevInfo num -> Bool
== :: NetDevInfo num -> NetDevInfo num -> Bool
$c== :: forall num. Eq num => NetDevInfo num -> NetDevInfo num -> Bool
Eq,Int -> NetDevInfo num -> ShowS
forall num. Show num => Int -> NetDevInfo num -> ShowS
forall num. Show num => [NetDevInfo num] -> ShowS
forall num. Show num => NetDevInfo num -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetDevInfo num] -> ShowS
$cshowList :: forall num. Show num => [NetDevInfo num] -> ShowS
show :: NetDevInfo num -> String
$cshow :: forall num. Show num => NetDevInfo num -> String
showsPrec :: Int -> NetDevInfo num -> ShowS
$cshowsPrec :: forall num. Show num => Int -> NetDevInfo num -> ShowS
Show,ReadPrec [NetDevInfo num]
ReadPrec (NetDevInfo num)
ReadS [NetDevInfo num]
forall num. Read num => ReadPrec [NetDevInfo num]
forall num. Read num => ReadPrec (NetDevInfo num)
forall num. Read num => Int -> ReadS (NetDevInfo num)
forall num. Read num => ReadS [NetDevInfo num]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NetDevInfo num]
$creadListPrec :: forall num. Read num => ReadPrec [NetDevInfo num]
readPrec :: ReadPrec (NetDevInfo num)
$creadPrec :: forall num. Read num => ReadPrec (NetDevInfo num)
readList :: ReadS [NetDevInfo num]
$creadList :: forall num. Read num => ReadS [NetDevInfo num]
readsPrec :: Int -> ReadS (NetDevInfo num)
$creadsPrec :: forall num. Read num => Int -> ReadS (NetDevInfo num)
Read)
type NetDevRawTotal = NetDev Word64
type NetDevRate = NetDev Float
type NetDevRef = IORef (NetDevRawTotal, UTCTime)
instance Ord num => Ord (NetDev num) where
compare :: NetDev num -> NetDev num -> Ordering
compare NetDev num
NA NetDev num
NA = Ordering
EQ
compare NetDev num
NA NetDev num
_ = Ordering
LT
compare NetDev num
_ NetDev num
NA = Ordering
GT
compare (N String
_ NetDevInfo num
i1) (N String
_ NetDevInfo num
i2) = NetDevInfo num
i1 forall a. Ord a => a -> a -> Ordering
`compare` NetDevInfo num
i2
instance Ord num => Ord (NetDevInfo num) where
compare :: NetDevInfo num -> NetDevInfo num -> Ordering
compare NetDevInfo num
NI NetDevInfo num
NI = Ordering
EQ
compare NetDevInfo num
NI ND {} = Ordering
LT
compare ND {} NetDevInfo num
NI = Ordering
GT
compare (ND num
x1 num
y1) (ND num
x2 num
y2) = num
x1 forall a. Ord a => a -> a -> Ordering
`compare` num
x2 forall a. Semigroup a => a -> a -> a
<> num
y1 forall a. Ord a => a -> a -> Ordering
`compare` num
y2