Clean up using hlint and --pedantic
This commit is contained in:
parent
89248a34d1
commit
b524441d9c
7 changed files with 62 additions and 41 deletions
|
|
@ -10,7 +10,7 @@ import TaskMachine.LTask
|
||||||
import TaskMachine.UI
|
import TaskMachine.UI
|
||||||
import TaskMachine.UI.Types
|
import TaskMachine.UI.Types
|
||||||
|
|
||||||
data Options = Options
|
newtype Options = Options
|
||||||
{ oTodofile :: FilePath
|
{ oTodofile :: FilePath
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
|
@ -24,11 +24,9 @@ opts = pure Options
|
||||||
)
|
)
|
||||||
|
|
||||||
optsInfo :: O.ParserInfo Options
|
optsInfo :: O.ParserInfo Options
|
||||||
optsInfo = O.info (opts <**> O.helper)
|
optsInfo = O.info (opts <**> O.helper) O.fullDesc
|
||||||
( O.fullDesc
|
|
||||||
-- <> O.progDesc "program description"
|
-- <> O.progDesc "program description"
|
||||||
-- <> O.header "help header"
|
-- <> O.header "help header"
|
||||||
)
|
|
||||||
|
|
||||||
main :: IO()
|
main :: IO()
|
||||||
main = do
|
main = do
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import Data.List
|
||||||
import Data.Function
|
import Data.Function
|
||||||
|
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import Text.Megaparsec
|
|
||||||
|
|
||||||
import TaskMachine.Todotxt
|
import TaskMachine.Todotxt
|
||||||
|
|
||||||
|
|
@ -30,11 +29,11 @@ loadLTasks :: FilePath -> IO (Either String (V.Vector LTask))
|
||||||
loadLTasks file = do
|
loadLTasks file = do
|
||||||
content <- readFile file
|
content <- readFile file
|
||||||
case parseTasks file content of
|
case parseTasks file content of
|
||||||
Right tasks -> pure $ Right $ V.fromList $ fromTasks tasks
|
Right taskList -> pure $ Right $ V.fromList $ fromTasks taskList
|
||||||
Left parseError -> pure $ Left $ show parseError
|
Left parseError -> pure $ Left $ show parseError
|
||||||
|
|
||||||
saveLTasks :: V.Vector LTask -> FilePath -> IO ()
|
saveLTasks :: V.Vector LTask -> FilePath -> IO ()
|
||||||
saveLTasks ltasks file = do
|
saveLTasks ltasks file = do
|
||||||
let tasks = map ltaskTask $ sortBy (compare `on` ltaskNumber) $ V.toList ltasks
|
let taskList = map ltaskTask $ sortBy (compare `on` ltaskNumber) $ V.toList ltasks
|
||||||
text = unlines $ map formatTask tasks
|
text = unlines $ map formatTask taskList
|
||||||
writeFile file text
|
writeFile file text
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import Data.Set as Set
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
import Text.Megaparsec.Char
|
import Text.Megaparsec.Char
|
||||||
import Text.Megaparsec.Error
|
|
||||||
|
|
||||||
type Parser = Parsec Void String
|
type Parser = Parsec Void String
|
||||||
|
|
||||||
|
|
@ -119,10 +118,10 @@ data Task = Task
|
||||||
-- show = formatTask
|
-- show = formatTask
|
||||||
|
|
||||||
formatTask :: Task -> String
|
formatTask :: Task -> String
|
||||||
formatTask (Task done prio dates desc)
|
formatTask (Task done prio tDates desc)
|
||||||
= (if done then "x " else "")
|
= (if done then "x " else "")
|
||||||
++ maybe "" ((++" ") . formatPriority) prio
|
++ maybe "" ((++" ") . formatPriority) prio
|
||||||
++ maybe "" ((++" ") . formatDates) dates
|
++ maybe "" ((++" ") . formatDates) tDates
|
||||||
++ desc
|
++ desc
|
||||||
|
|
||||||
parseTasks :: FilePath -> String -> Either (ParseError Char Void) [Task]
|
parseTasks :: FilePath -> String -> Either (ParseError Char Void) [Task]
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,8 @@ module TaskMachine.UI where
|
||||||
--
|
--
|
||||||
import qualified Brick as B
|
import qualified Brick as B
|
||||||
import qualified Brick.Themes as B
|
import qualified Brick.Themes as B
|
||||||
import qualified Brick.Widgets.Core as B
|
|
||||||
import qualified Brick.Widgets.List as B
|
import qualified Brick.Widgets.List as B
|
||||||
import qualified Data.Vector as V
|
|
||||||
import qualified Graphics.Vty as VTY
|
|
||||||
|
|
||||||
import TaskMachine.LTask
|
|
||||||
import TaskMachine.Todotxt
|
|
||||||
import TaskMachine.UI.TaskList
|
import TaskMachine.UI.TaskList
|
||||||
import TaskMachine.UI.Types
|
import TaskMachine.UI.Types
|
||||||
--import qualified Database.SQLite.Simple as DB
|
--import qualified Database.SQLite.Simple as DB
|
||||||
|
|
@ -49,7 +44,7 @@ Edit _____________________________
|
||||||
-- [_] display loaded tasks in UI
|
-- [_] display loaded tasks in UI
|
||||||
|
|
||||||
drawUIState :: UIState -> [B.Widget RName]
|
drawUIState :: UIState -> [B.Widget RName]
|
||||||
drawUIState UIState{..} = [B.renderList renderLTask True taskList]
|
drawUIState UIState{..} = [B.renderList (renderLTask taskEdit) True taskList]
|
||||||
|
|
||||||
myApp :: B.Theme -> B.App UIState () RName
|
myApp :: B.Theme -> B.App UIState () RName
|
||||||
myApp theme = B.App
|
myApp theme = B.App
|
||||||
|
|
@ -57,7 +52,7 @@ myApp theme = B.App
|
||||||
, B.appChooseCursor = B.neverShowCursor
|
, B.appChooseCursor = B.neverShowCursor
|
||||||
, B.appHandleEvent = B.resizeOrQuit
|
, B.appHandleEvent = B.resizeOrQuit
|
||||||
, B.appStartEvent = pure
|
, B.appStartEvent = pure
|
||||||
, B.appAttrMap = const $ attrMap
|
, B.appAttrMap = const attrMap
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
attrMap = B.themeToAttrMap theme
|
attrMap = B.themeToAttrMap theme
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,6 @@ import Control.Monad
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
import qualified Brick as B
|
import qualified Brick as B
|
||||||
import qualified Brick.Focus as B
|
|
||||||
import qualified Brick.Themes as B
|
|
||||||
import qualified Brick.Widgets.List as B
|
|
||||||
import qualified Data.Vector as V
|
|
||||||
import qualified Graphics.Vty as VTY
|
import qualified Graphics.Vty as VTY
|
||||||
|
|
||||||
colors :: [(String, VTY.Color)]
|
colors :: [(String, VTY.Color)]
|
||||||
|
|
@ -50,14 +46,14 @@ toName :: String -> String -> String -> B.AttrName
|
||||||
toName a b c = B.attrName a <> B.attrName b <> B.attrName c
|
toName a b c = B.attrName a <> B.attrName b <> B.attrName c
|
||||||
|
|
||||||
useStyles :: [VTY.Style] -> VTY.Attr -> VTY.Attr
|
useStyles :: [VTY.Style] -> VTY.Attr -> VTY.Attr
|
||||||
useStyles styles = foldr (.) id $ map (flip VTY.withStyle) styles
|
useStyles = foldr ((.) . flip VTY.withStyle) id
|
||||||
|
|
||||||
attrMap :: B.AttrMap
|
attrMap :: B.AttrMap
|
||||||
attrMap = B.attrMap VTY.defAttr $ do
|
attrMap = B.attrMap VTY.defAttr $ do
|
||||||
(fgName, fgColor) <- colors
|
(fgName, fgColor) <- colors
|
||||||
(bgName, bgColor) <- colors
|
(bgName, bgColor) <- colors
|
||||||
styleList <- subsequences styles
|
styleList <- subsequences styles
|
||||||
let styleName = concat $ map fst styleList
|
let styleName = concatMap fst styleList
|
||||||
name = toName styleName bgName fgName
|
name = toName styleName bgName fgName
|
||||||
fgAttr = VTY.withForeColor VTY.defAttr fgColor
|
fgAttr = VTY.withForeColor VTY.defAttr fgColor
|
||||||
bgAttr = VTY.withBackColor fgAttr bgColor
|
bgAttr = VTY.withBackColor fgAttr bgColor
|
||||||
|
|
@ -72,7 +68,8 @@ cw style = B.vBox $ B.str (' ':style) : do
|
||||||
let name = toName style bgName fgName
|
let name = toName style bgName fgName
|
||||||
pure $ B.withAttr name $ B.str "Hi"
|
pure $ B.withAttr name $ B.str "Hi"
|
||||||
|
|
||||||
testWidget = B.vBox $
|
testWidget :: B.Widget n
|
||||||
|
testWidget = B.vBox
|
||||||
[ B.hBox [cw "", cw "standout"]
|
[ B.hBox [cw "", cw "standout"]
|
||||||
, B.hBox [cw "", cw "underline"]
|
, B.hBox [cw "", cw "underline"]
|
||||||
-- , B.hBox [cw "", cw "reverseVideo"]
|
-- , B.hBox [cw "", cw "reverseVideo"]
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module TaskMachine.UI.TaskList where
|
module TaskMachine.UI.TaskList where
|
||||||
|
|
||||||
import qualified Brick as B
|
import qualified Brick as B
|
||||||
|
import qualified Brick.Widgets.Edit as B
|
||||||
|
|
||||||
import TaskMachine.LTask
|
import TaskMachine.LTask
|
||||||
import TaskMachine.Todotxt
|
import TaskMachine.Todotxt
|
||||||
import TaskMachine.UI.Types
|
import TaskMachine.UI.Types
|
||||||
|
|
||||||
|
{-
|
||||||
widgetPriority :: B.AttrName -> Maybe Priority -> B.Widget n
|
widgetPriority :: B.AttrName -> Maybe Priority -> B.Widget n
|
||||||
widgetPriority _ Nothing = B.emptyWidget
|
widgetPriority _ Nothing = B.emptyWidget
|
||||||
widgetPriority highlight (Just prio) =
|
widgetPriority highlight (Just prio) =
|
||||||
|
|
@ -28,3 +29,12 @@ renderLTask highlight (LTask _ Task{..}) =
|
||||||
wPriority = widgetPriority attrHighlight taskPriority
|
wPriority = widgetPriority attrHighlight taskPriority
|
||||||
wDescription = widgetDescription attrHighlight taskDescription
|
wDescription = widgetDescription attrHighlight taskDescription
|
||||||
in B.hBox [wCompleted, wPriority, wDescription]
|
in B.hBox [wCompleted, wPriority, wDescription]
|
||||||
|
-}
|
||||||
|
|
||||||
|
renderLTask :: Maybe (B.Editor String RName) -> Bool -> LTask -> B.Widget RName
|
||||||
|
renderLTask _ False (LTask _ t) = B.withAttr normal $ B.str $ formatTask t
|
||||||
|
where normal = "normal" <> "priority"
|
||||||
|
renderLTask Nothing True (LTask _ t) = B.withAttr highlight $ B.str $ formatTask t
|
||||||
|
where highlight = "highlight" <> "priority"
|
||||||
|
renderLTask (Just edit) True _ = B.withAttr highlight $ B.renderEditor (B.str . unlines) True edit
|
||||||
|
where highlight = "highlight" <> "priority"
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ module TaskMachine.UI.Types
|
||||||
import qualified Brick.Focus as B
|
import qualified Brick.Focus as B
|
||||||
import qualified Brick.Themes as B
|
import qualified Brick.Themes as B
|
||||||
import qualified Brick.Widgets.List as B
|
import qualified Brick.Widgets.List as B
|
||||||
|
import qualified Brick.Widgets.Edit as B
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import qualified Graphics.Vty as VTY
|
import qualified Graphics.Vty as VTY
|
||||||
|
|
||||||
|
|
@ -21,35 +22,57 @@ import TaskMachine.LTask
|
||||||
|
|
||||||
-- | Resource names
|
-- | Resource names
|
||||||
data RName
|
data RName
|
||||||
-- These can be tab-cycled through
|
= RSearchEdit
|
||||||
= RTopBar
|
|
||||||
| RTaskList
|
| RTaskList
|
||||||
| REdit
|
| RNewEdit
|
||||||
-- Items in the top bar that are selected with the ← and → arrow keys
|
|
||||||
| RPrune
|
|
||||||
| RReload
|
|
||||||
| RSearch
|
|
||||||
deriving (Eq, Show, Ord)
|
deriving (Eq, Show, Ord)
|
||||||
|
|
||||||
|
data BigRing
|
||||||
|
= BRTopBar
|
||||||
|
| BRTaskList
|
||||||
|
| BRNewTask
|
||||||
|
deriving (Eq)
|
||||||
|
|
||||||
|
data SmallRing
|
||||||
|
= SRPrune
|
||||||
|
| SRReload
|
||||||
|
| SRSearch
|
||||||
|
deriving (Eq)
|
||||||
|
|
||||||
-- | The state of the program and UI
|
-- | The state of the program and UI
|
||||||
data UIState = UIState
|
data UIState = UIState
|
||||||
{ focus :: B.FocusRing RName
|
{ focus :: B.FocusRing BigRing
|
||||||
-- ^ 'B.FocusRing' for tab navigation
|
-- ^ 'B.FocusRing' for tab navigation
|
||||||
, topBarFocus :: B.FocusRing RName
|
, focusTopBar :: B.FocusRing SmallRing
|
||||||
-- ^ 'B.FocusRing' for the top bar, for ← and → arrow key navigation
|
-- ^ 'B.FocusRing' for the top bar, for ← and → arrow key navigation
|
||||||
|
|
||||||
|
-- TOP BAR
|
||||||
|
, searchEdit :: B.Editor String RName
|
||||||
|
-- ^ Content of the search field
|
||||||
|
|
||||||
|
-- TASK LIST
|
||||||
, taskList :: B.List RName LTask
|
, taskList :: B.List RName LTask
|
||||||
-- ^ List to display tasks
|
-- ^ List to display tasks
|
||||||
, invisibleTasks :: V.Vector LTask
|
, invisibleTasks :: V.Vector LTask
|
||||||
-- ^ All tasks that aren't displayed in the taskList due to search filters
|
-- ^ All tasks that aren't displayed in the taskList due to search filters
|
||||||
|
, taskEdit :: Maybe (B.Editor String RName)
|
||||||
|
-- ^ Task currently being edited
|
||||||
|
|
||||||
|
-- NEW TASK
|
||||||
|
, newEdit :: B.Editor String RName
|
||||||
|
-- ^ "New task" text field at the bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Create a starting UI state
|
-- | Create a starting UI state
|
||||||
startUIState :: V.Vector LTask -> UIState
|
startUIState :: V.Vector LTask -> UIState
|
||||||
startUIState ltasks = UIState
|
startUIState ltasks = UIState
|
||||||
{ focus = B.focusRing [RTaskList, REdit, RTopBar]
|
{ focus = B.focusRing [BRTaskList, BRNewTask, BRTopBar]
|
||||||
, topBarFocus = B.focusRing [RPrune, RReload, RSearch]
|
, focusTopBar = B.focusRing [SRPrune, SRReload, SRSearch]
|
||||||
|
, searchEdit = B.editor RSearchEdit (Just 1) ""
|
||||||
, taskList = B.list RTaskList ltasks 1
|
, taskList = B.list RTaskList ltasks 1
|
||||||
, invisibleTasks = V.empty
|
, invisibleTasks = V.empty
|
||||||
|
, taskEdit = Nothing
|
||||||
|
, newEdit = B.editor RNewEdit (Just 1) ""
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultTheme :: B.Theme
|
defaultTheme :: B.Theme
|
||||||
|
|
@ -70,8 +93,8 @@ defaultTheme = B.newTheme VTY.defAttr
|
||||||
where
|
where
|
||||||
fg = flip VTY.withForeColor
|
fg = flip VTY.withForeColor
|
||||||
bg = flip VTY.withBackColor
|
bg = flip VTY.withBackColor
|
||||||
st = flip VTY.withStyle
|
--st = flip VTY.withStyle
|
||||||
fg' = VTY.withForeColor none
|
--fg' = VTY.withForeColor none
|
||||||
bg' = VTY.withBackColor none
|
bg' = VTY.withBackColor none
|
||||||
st' = VTY.withStyle none
|
st' = VTY.withStyle none
|
||||||
none = VTY.defAttr
|
none = VTY.defAttr
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue