~ph14nix/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3

[PATCH] fix a few warnings

Details
Message ID
<20220531132629.2003-1-ivan.oleynikov95@gmail.com>
DKIM signature
pass
Download raw message
Patch: +14 -27
---
 src/Environment.hs |  6 +++---
 src/Main.hs        |  6 ------
 src/Render.hs      | 27 ++++++++++-----------------
 src/State.hs       |  2 +-
 4 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/src/Environment.hs b/src/Environment.hs
index af08146..1045de5 100644
--- a/src/Environment.hs
+++ b/src/Environment.hs
@@ -13,9 +13,9 @@ import Data.List (sortOn)
import Data.List.Extra (nubOrd)

data Env = Env
  { _today :: Day
  , _records :: [Record]
  , _activities :: [Activity]
  { _envToday :: Day
  , _envRecords :: [Record]
  , _envActivities :: [Activity]
  }
makeLenses ''Env

diff --git a/src/Main.hs b/src/Main.hs
index 8d7a9a8..4e40cae 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -2,22 +2,16 @@
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Data.TimeTracker
import Data.TimeTracker.Parsec (timeLog)
import Text.Parsec.String (parseFromFile)

import qualified Data.Text as T
import qualified Graphics.Vty as V

import Brick.Main
import Brick.AttrMap

import Data.Time.Calendar
import Data.Time.LocalTime

import Control.Lens
import Data.TimeTracker.Lens

import Environment
import State
import Render (ui, runRenderM)
diff --git a/src/Render.hs b/src/Render.hs
index ab76623..93c77e6 100644
--- a/src/Render.hs
+++ b/src/Render.hs
@@ -22,30 +22,25 @@ import Brick.Types
  )
import qualified Brick.Widgets.Border as B
import qualified Brick.Widgets.Border.Style as BS
import Brick.Widgets.Calendar (calendarSimple)
import Brick.Widgets.List hiding (reverse)
import Brick.Widgets.FancyProgressBar
import Text.Wrap (preserveIndentation, WrapSettings, defaultWrapSettings)

import Graphics.Vty hiding ((<|>))

import Data.Vector (fromList)
import Data.Maybe (fromJust)
import Control.Applicative ((<|>))

import Data.Time.Format
import Data.Time.Calendar
import qualified Data.Text as T
import Data.Time.Lens
import Data.Time.Lens (julianDay)

import Control.Lens
import Control.Lens.Combinators (head1)
import Control.Monad.Reader
import Control.Arrow (second)

import Environment
import State
import Extra (notNull)
import Data.List.Extra (notNull)

type RenderM = Reader (Env, St)
type W = Widget Res
@@ -67,7 +62,7 @@ myWrap = defaultWrapSettings {preserveIndentation = True}

relevantEntries :: RenderM [Record]
relevantEntries = do
  rs <- view $ env . records
  rs <- view $ env . envRecords
  cA <- view $ st . activitiesList . listSelectedElementL
  pure $ filter (\(_, e) -> notNull $ e ^. dayEntries)
       $ map (second $ over dayEntries $ filter $ \(a, _) -> a == cA) rs
@@ -81,7 +76,7 @@ countHours = map $ second $ \dd -> sum $ map f (dd ^. dayEntries)
verbalSummary :: RenderM W
verbalSummary = do
  hours <- countHours <$> relevantEntries
  tD <- view $ env . today
  tD <- view $ env . envToday
  let thisMon = thisMonday tD
  let nextMon = thisMon & julianDay %~ (+7)
  let lastMon = thisMon & julianDay %~ subtract 7
@@ -109,10 +104,10 @@ timeline = do
  unit <- view $ st . timeScale
  let
    renderTime :: Int -> T.Text
    renderTime x = let len = roundDoubleInt (int2Double x / int2Double unit) in pad (len - 1) $ T.pack (show $ x `div` 60) <> "h"
    pad :: Int -> T.Text -> T.Text
    pad l x | T.length x > l = T.replicate l " "
            | otherwise = let rem = l - T.length x in T.replicate (rem `div` 2) " " <> x <> T.replicate (rem `div` 2 + rem `mod` 2) " "
    renderTime x = let len = roundDoubleInt (int2Double x / int2Double unit) in padT (len - 1) $ T.pack (show $ x `div` 60) <> "h"
    padT :: Int -> T.Text -> T.Text
    padT l x | T.length x > l = T.replicate l " "
            | otherwise = let r = l - T.length x in T.replicate (r `div` 2) " " <> x <> T.replicate (r `div` 2 + r `mod` 2) " "
    flush :: (Maybe Int, [TL.TimelineItem]) -> [TL.TimelineItem]
    flush (Nothing, l) = l
    flush (Just x, l) = TL.TimelineSegment (renderTime x) : l
@@ -134,16 +129,14 @@ makeGreen = modifyDefAttr (const $ fg green)

canvasDayBars :: RenderM W
canvasDayBars = do
  tD <- view $ env . today
  tD <- view $ env . envToday
  selected <- countHours <$> relevantEntries
  let f (d, h) = [strWrap $ describeDay tD d, str (showTime h ++ " ") <+> (makeGreen $ progressEightsRight (fromRational $ (toInteger h) :% (12 * 60))), str " "]
  let f (d, h) = [strWrap $ describeDay tD d, str (showTime h ++ " ") <+> makeGreen (progressEightsRight (fromRational $ toInteger h :% (12 * 60))), str " "]
  pure $ vBox $ concatMap f selected

canvas :: RenderM W
canvas = do
  a <- view $ st . activitiesList . listSelectedElementL
  B.borderWithLabel (str " Activity Info ") <$> padBottom Max <$> do
    t <- view $ st . canvasSt
    vs <- verbalSummary
    tl <- timeline
    pure $ vs <=> tl
diff --git a/src/State.hs b/src/State.hs
index 2396ccc..2345854 100644
--- a/src/State.hs
+++ b/src/State.hs
@@ -37,4 +37,4 @@ listSelectedElementL f l = case ii of
    ii = listSelected l

newState :: Env -> St
newState e = St (list ResActivityList (fromList $ e ^. activities) 1) CanvasTime 60
newState e = St (list ResActivityList (fromList $ e ^. envActivities) 1) CanvasTime 60
-- 
2.36.1
Details
Message ID
<CKDZCWD2QCRP.2ETEJT5XVHI2M@arch>
In-Reply-To
<20220531132629.2003-1-ivan.oleynikov95@gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Tue May 31, 2022 at 4:26 PM MSK, Ivan Oleynikov wrote:
> ---
>  src/Environment.hs |  6 +++---
>  src/Main.hs        |  6 ------
>  src/Render.hs      | 27 ++++++++++-----------------
>  src/State.hs       |  2 +-
>  4 files changed, 14 insertions(+), 27 deletions(-)
>
> diff --git a/src/Environment.hs b/src/Environment.hs
> index af08146..1045de5 100644
> --- a/src/Environment.hs
> +++ b/src/Environment.hs
> @@ -13,9 +13,9 @@ import Data.List (sortOn)
>  import Data.List.Extra (nubOrd)
>  
>  data Env = Env
> -  { _today :: Day
> -  , _records :: [Record]
> -  , _activities :: [Activity]
> +  { _envToday :: Day
> +  , _envRecords :: [Record]
> +  , _envActivities :: [Activity]
>    }

A comment
Details
Message ID
<CKDZDJY8JWVO.N344B40CXK1G@arch>
In-Reply-To
<20220531132629.2003-1-ivan.oleynikov95@gmail.com> (view parent)
DKIM signature
pass
Download raw message
>  newState :: Env -> St
> -newState e = St (list ResActivityList (fromList $ e ^. activities) 1) CanvasTime 60
> +newState e = St (list ResActivityList (fromList $ e ^. envActivities) 1) CanvasTime 60

Another comment
Details
Message ID
<CKDZE1WGO8XZ.3USLHZWIMW6K0@arch>
In-Reply-To
<20220531132629.2003-1-ivan.oleynikov95@gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Tue May 31, 2022 at 4:26 PM MSK, Ivan Oleynikov wrote:
> ---
>  src/Environment.hs |  6 +++---
>  src/Main.hs        |  6 ------
>  src/Render.hs      | 27 ++++++++++-----------------
>  src/State.hs       |  2 +-
>  4 files changed, 14 insertions(+), 27 deletions(-)
>
> diff --git a/src/Environment.hs b/src/Environment.hs
> index af08146..1045de5 100644
> --- a/src/Environment.hs
> +++ b/src/Environment.hs
> @@ -13,9 +13,9 @@ import Data.List (sortOn)
>  import Data.List.Extra (nubOrd)
>  
>  data Env = Env
> -  { _today :: Day
> -  , _records :: [Record]
> -  , _activities :: [Activity]
> +  { _envToday :: Day
> +  , _envRecords :: [Record]
> +  , _envActivities :: [Activity]
>    }
>  makeLenses ''Env
>  
> diff --git a/src/Main.hs b/src/Main.hs
> index 8d7a9a8..4e40cae 100644
> --- a/src/Main.hs
> +++ b/src/Main.hs
> @@ -2,22 +2,16 @@
>  {-# LANGUAGE OverloadedStrings #-}
>  module Main where
>  
> -import Data.TimeTracker
>  import Data.TimeTracker.Parsec (timeLog)
>  import Text.Parsec.String (parseFromFile)
>  
> -import qualified Data.Text as T

Simultaneous comment1

>  import qualified Graphics.Vty as V
>  
>  import Brick.Main
>  import Brick.AttrMap
>  
> -import Data.Time.Calendar
>  import Data.Time.LocalTime

Simultaneous comment2

>  
> -import Control.Lens
> -import Data.TimeTracker.Lens
> -
>  import Environment
>  import State
>  import Render (ui, runRenderM)
> diff --git a/src/Render.hs b/src/Render.hs
> index ab76623..93c77e6 100644
> --- a/src/Render.hs
> +++ b/src/Render.hs
> @@ -22,30 +22,25 @@ import Brick.Types
>    )
>  import qualified Brick.Widgets.Border as B
>  import qualified Brick.Widgets.Border.Style as BS
> -import Brick.Widgets.Calendar (calendarSimple)
>  import Brick.Widgets.List hiding (reverse)
>  import Brick.Widgets.FancyProgressBar
>  import Text.Wrap (preserveIndentation, WrapSettings, defaultWrapSettings)
>  
>  import Graphics.Vty hiding ((<|>))
>  
> -import Data.Vector (fromList)
> -import Data.Maybe (fromJust)
>  import Control.Applicative ((<|>))
>  
> -import Data.Time.Format
>  import Data.Time.Calendar
>  import qualified Data.Text as T
> -import Data.Time.Lens
> +import Data.Time.Lens (julianDay)
>  
>  import Control.Lens
> -import Control.Lens.Combinators (head1)
>  import Control.Monad.Reader
>  import Control.Arrow (second)
>  
>  import Environment
>  import State
> -import Extra (notNull)
> +import Data.List.Extra (notNull)
>  
>  type RenderM = Reader (Env, St)
>  type W = Widget Res
> @@ -67,7 +62,7 @@ myWrap = defaultWrapSettings {preserveIndentation = True}
>  
>  relevantEntries :: RenderM [Record]
>  relevantEntries = do
> -  rs <- view $ env . records
> +  rs <- view $ env . envRecords
>    cA <- view $ st . activitiesList . listSelectedElementL
>    pure $ filter (\(_, e) -> notNull $ e ^. dayEntries)
>         $ map (second $ over dayEntries $ filter $ \(a, _) -> a == cA) rs
> @@ -81,7 +76,7 @@ countHours = map $ second $ \dd -> sum $ map f (dd ^. dayEntries)
>  verbalSummary :: RenderM W
>  verbalSummary = do
>    hours <- countHours <$> relevantEntries
> -  tD <- view $ env . today
> +  tD <- view $ env . envToday
>    let thisMon = thisMonday tD
>    let nextMon = thisMon & julianDay %~ (+7)
>    let lastMon = thisMon & julianDay %~ subtract 7
> @@ -109,10 +104,10 @@ timeline = do
>    unit <- view $ st . timeScale
>    let
>      renderTime :: Int -> T.Text
> -    renderTime x = let len = roundDoubleInt (int2Double x / int2Double unit) in pad (len - 1) $ T.pack (show $ x `div` 60) <> "h"
> -    pad :: Int -> T.Text -> T.Text
> -    pad l x | T.length x > l = T.replicate l " "
> -            | otherwise = let rem = l - T.length x in T.replicate (rem `div` 2) " " <> x <> T.replicate (rem `div` 2 + rem `mod` 2) " "
> +    renderTime x = let len = roundDoubleInt (int2Double x / int2Double unit) in padT (len - 1) $ T.pack (show $ x `div` 60) <> "h"
> +    padT :: Int -> T.Text -> T.Text
> +    padT l x | T.length x > l = T.replicate l " "
> +            | otherwise = let r = l - T.length x in T.replicate (r `div` 2) " " <> x <> T.replicate (r `div` 2 + r `mod` 2) " "
>      flush :: (Maybe Int, [TL.TimelineItem]) -> [TL.TimelineItem]
>      flush (Nothing, l) = l
>      flush (Just x, l) = TL.TimelineSegment (renderTime x) : l
> @@ -134,16 +129,14 @@ makeGreen = modifyDefAttr (const $ fg green)
>  
>  canvasDayBars :: RenderM W
>  canvasDayBars = do
> -  tD <- view $ env . today
> +  tD <- view $ env . envToday
>    selected <- countHours <$> relevantEntries
> -  let f (d, h) = [strWrap $ describeDay tD d, str (showTime h ++ " ") <+> (makeGreen $ progressEightsRight (fromRational $ (toInteger h) :% (12 * 60))), str " "]
> +  let f (d, h) = [strWrap $ describeDay tD d, str (showTime h ++ " ") <+> makeGreen (progressEightsRight (fromRational $ toInteger h :% (12 * 60))), str " "]
>    pure $ vBox $ concatMap f selected
>  
>  canvas :: RenderM W
>  canvas = do
> -  a <- view $ st . activitiesList . listSelectedElementL
>    B.borderWithLabel (str " Activity Info ") <$> padBottom Max <$> do
> -    t <- view $ st . canvasSt
>      vs <- verbalSummary
>      tl <- timeline
>      pure $ vs <=> tl
> diff --git a/src/State.hs b/src/State.hs
> index 2396ccc..2345854 100644
> --- a/src/State.hs
> +++ b/src/State.hs
> @@ -37,4 +37,4 @@ listSelectedElementL f l = case ii of
>      ii = listSelected l
>  
>  newState :: Env -> St
> -newState e = St (list ResActivityList (fromList $ e ^. activities) 1) CanvasTime 60
> +newState e = St (list ResActivityList (fromList $ e ^. envActivities) 1) CanvasTime 60
> -- 
> 2.36.1
Reply to thread Export thread (mbox)