From 86c8896ee69b068368b4ef9a4c3923285907c328 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Tue, 18 Mar 2025 15:29:27 +0100 Subject: Parsing ING statements (POC) --- app/Main.hs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 app/Main.hs (limited to 'app/Main.hs') 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 @@ +module Main where + +import Brick.AttrMap qualified as A +import Brick.Main qualified as M +import Brick.Types + ( BrickEvent (..), + Widget, + ) +import Brick.Types qualified as T +import Brick.Util (bg, on) +import Brick.Widgets.Center qualified as C +import Brick.Widgets.Core + ( padAll, + str, + ) +import Brick.Widgets.Dialog qualified as D +import Graphics.Vty qualified as V +import Import.Ing.SavingsAccountCsv qualified +import System.IO (IOMode (ReadMode), withFile) +import Text.Pretty.Simple (pPrint) + +-- data AccountType = Asset | Equity | Liability | Expense | Income +-- +-- data TxAction = Inc | Dec +-- +-- txAopp :: TxAction -> TxAction +-- txaOpp Inc = Dec +-- txaOpp Dec = Inc +-- +-- onDebit :: AccountType -> TxAction +-- onDebit Asset = Inc +-- onDebit Equity = Dec +-- onDebit Liability = Dec +-- onDebit Expense = Inc +-- onDebit Income = Dec +-- +-- onCredit :: AccountType -> TxAction +-- onCredit = txaOpp . onDebit +-- +-- data Tx = Tx { txDebit :: [(Account, Decimal)], txCredit :: [(Account, Decimal)] } deriving Show +data Choice = Red | Blue | Green + deriving (Show) + +data Name + = RedButton + | BlueButton + | GreenButton + deriving (Show, Eq, Ord) + +drawUI :: D.Dialog Choice Name -> [Widget Name] +drawUI d = [ui] + where + ui = D.renderDialog d $ C.hCenter $ padAll 1 $ str "This is the dialog body." + +appEvent :: BrickEvent Name e -> T.EventM Name (D.Dialog Choice Name) () +appEvent (VtyEvent ev) = + case ev of + V.EvKey V.KEsc [] -> M.halt + V.EvKey V.KEnter [] -> M.halt + _ -> D.handleDialogEvent ev +appEvent _ = return () + +initialState :: D.Dialog Choice Name +initialState = D.dialog (Just $ str "Title") (Just (RedButton, choices)) 50 + where + choices = + [ ("Red", RedButton, Red), + ("Blue", BlueButton, Blue), + ("Green", GreenButton, Green) + ] + +theMap :: A.AttrMap +theMap = + A.attrMap + V.defAttr + [ (D.dialogAttr, V.white `on` V.blue), + (D.buttonAttr, V.black `on` V.white), + (D.buttonSelectedAttr, bg V.yellow) + ] + +theApp :: M.App (D.Dialog Choice Name) e Name +theApp = + M.App + { M.appDraw = drawUI, + M.appChooseCursor = M.showFirstCursor, + M.appHandleEvent = appEvent, + M.appStartEvent = return (), + M.appAttrMap = const theMap + } + +main :: IO () +main = do + let filename = "/home/rutgerbrf/Code/P/wayligmative/test.csv" + putStrLn $ "Reading " ++ filename + withFile filename ReadMode $ \h -> do + entries <- Import.Ing.SavingsAccountCsv.readFile h + pPrint entries + +-- d <- M.defaultMain theApp initialState +-- putStrLn $ "You chose: " <> show (D.dialogSelection d) -- cgit v1.2.3