summaryrefslogtreecommitdiffstats
path: root/app/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs100
1 files changed, 100 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
index 0000000..2438203
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,100 @@
1module Main where
2
3import Brick.AttrMap qualified as A
4import Brick.Main qualified as M
5import Brick.Types
6 ( BrickEvent (..),
7 Widget,
8 )
9import Brick.Types qualified as T
10import Brick.Util (bg, on)
11import Brick.Widgets.Center qualified as C
12import Brick.Widgets.Core
13 ( padAll,
14 str,
15 )
16import Brick.Widgets.Dialog qualified as D
17import Graphics.Vty qualified as V
18import Import.Ing.SavingsAccountCsv qualified
19import System.IO (IOMode (ReadMode), withFile)
20import Text.Pretty.Simple (pPrint)
21
22-- data AccountType = Asset | Equity | Liability | Expense | Income
23--
24-- data TxAction = Inc | Dec
25--
26-- txAopp :: TxAction -> TxAction
27-- txaOpp Inc = Dec
28-- txaOpp Dec = Inc
29--
30-- onDebit :: AccountType -> TxAction
31-- onDebit Asset = Inc
32-- onDebit Equity = Dec
33-- onDebit Liability = Dec
34-- onDebit Expense = Inc
35-- onDebit Income = Dec
36--
37-- onCredit :: AccountType -> TxAction
38-- onCredit = txaOpp . onDebit
39--
40-- data Tx = Tx { txDebit :: [(Account, Decimal)], txCredit :: [(Account, Decimal)] } deriving Show
41data Choice = Red | Blue | Green
42 deriving (Show)
43
44data Name
45 = RedButton
46 | BlueButton
47 | GreenButton
48 deriving (Show, Eq, Ord)
49
50drawUI :: D.Dialog Choice Name -> [Widget Name]
51drawUI d = [ui]
52 where
53 ui = D.renderDialog d $ C.hCenter $ padAll 1 $ str "This is the dialog body."
54
55appEvent :: BrickEvent Name e -> T.EventM Name (D.Dialog Choice Name) ()
56appEvent (VtyEvent ev) =
57 case ev of
58 V.EvKey V.KEsc [] -> M.halt
59 V.EvKey V.KEnter [] -> M.halt
60 _ -> D.handleDialogEvent ev
61appEvent _ = return ()
62
63initialState :: D.Dialog Choice Name
64initialState = D.dialog (Just $ str "Title") (Just (RedButton, choices)) 50
65 where
66 choices =
67 [ ("Red", RedButton, Red),
68 ("Blue", BlueButton, Blue),
69 ("Green", GreenButton, Green)
70 ]
71
72theMap :: A.AttrMap
73theMap =
74 A.attrMap
75 V.defAttr
76 [ (D.dialogAttr, V.white `on` V.blue),
77 (D.buttonAttr, V.black `on` V.white),
78 (D.buttonSelectedAttr, bg V.yellow)
79 ]
80
81theApp :: M.App (D.Dialog Choice Name) e Name
82theApp =
83 M.App
84 { M.appDraw = drawUI,
85 M.appChooseCursor = M.showFirstCursor,
86 M.appHandleEvent = appEvent,
87 M.appStartEvent = return (),
88 M.appAttrMap = const theMap
89 }
90
91main :: IO ()
92main = do
93 let filename = "/home/rutgerbrf/Code/P/wayligmative/test.csv"
94 putStrLn $ "Reading " ++ filename
95 withFile filename ReadMode $ \h -> do
96 entries <- Import.Ing.SavingsAccountCsv.readFile h
97 pPrint entries
98
99-- d <- M.defaultMain theApp initialState
100-- putStrLn $ "You chose: " <> show (D.dialogSelection d)