diff --git a/HappsCommand.hs b/HappsCommand.hs new file mode 100644 index 000000000..6a38ca4aa --- /dev/null +++ b/HappsCommand.hs @@ -0,0 +1,39 @@ +{-| + +A happs-based UI for hledger. + +-} + +module HappsCommand +where +import qualified Data.Map as Map +import Data.Map ((!)) +import HAppS.Server +import Ledger +import Options +import BalanceCommand +import RegisterCommand +import PrintCommand + + +-- | The application state when running the ui command. +data AppState = AppState { + aw :: Int -- ^ window width + ,ah :: Int -- ^ window height + ,amsg :: String -- ^ status message + ,aopts :: [Opt] -- ^ command-line opts + ,aargs :: [String] -- ^ command-line args + ,aledger :: Ledger -- ^ parsed ledger + ,abuf :: [String] -- ^ lines of the current buffered view + -- ^ never null, head is current location + } deriving (Show) + +tcpport = 5000 + +happs :: [Opt] -> [String] -> Ledger -> IO () +happs opts args l = do + putStrLn $ printf "hledger server running on port %d" tcpport + simpleHTTP nullConf{port=tcpport} [ + method GET $ ok $ toResponse $ output + ] + where output = showBalanceReport (opts++[SubTotal]) [] l diff --git a/Makefile b/Makefile index 5b34c9cad..4fa2ec468 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # build the normal hledger binary BUILD=ghc --make hledger.hs -o hledger -O -BUILDFLAGS=-DVTY -DANSI +BUILDFLAGS=-DVTY -DANSI -DHAPPS build: setbuildversion tag $(BUILD) $(BUILDFLAGS) diff --git a/README b/README index b50866bea..4b8145337 100644 --- a/README +++ b/README @@ -37,10 +37,11 @@ features. These are:: -f vty - Build vty-based text ui (requires vty, not available on windows) -f ansi - Build ansi-based text ui (requires ansi-terminal) + -f happs - Build happs-based web ui (requires HApps-Server) Eg:: - cabal install -f "vty ansi" hledger (or runhaskell Setup.hs configure -f "vty ansi") + cabal install -f "vty ansi happs" hledger (or runhaskell Setup.hs configure -f "vty ansi happs") To get the latest development code do:: diff --git a/hledger.cabal b/hledger.cabal index 557801fb1..88bcbf45b 100644 --- a/hledger.cabal +++ b/hledger.cabal @@ -24,6 +24,9 @@ Flag vty Flag ansi description: Build ansi-based text ui (requires ansi-terminal) default: False +Flag happs + description: Build happs-based web ui (requires HApps-Server) + default: False Executable hledger Main-Is: hledger.hs @@ -69,6 +72,10 @@ Executable hledger Build-Depends:ansi-terminal Other-Modules:ANSICommand cpp-options: -DANSI + if flag(happs) + Build-Depends:HAppS-Server>=0.9.3.1 + Other-Modules:HappsCommand + cpp-options: -DHAPPS Library Build-Depends: base, containers, haskell98, directory, parsec, regex-compat, diff --git a/hledger.hs b/hledger.hs index 9bfceb2ec..6be3cba0b 100644 --- a/hledger.hs +++ b/hledger.hs @@ -58,6 +58,9 @@ import qualified UICommand #ifdef ANSI import qualified ANSICommand #endif +#ifdef HAPPS +import qualified HappsCommand +#endif import Tests @@ -77,6 +80,9 @@ main = do #endif #ifdef ANSI | cmd `isPrefixOf` "ansi" = parseLedgerAndDo opts args ANSICommand.ansi +#endif +#ifdef HAPPS + | cmd `isPrefixOf` "happs" = parseLedgerAndDo opts args HappsCommand.happs #endif | cmd `isPrefixOf` "test" = runtests opts args >> return () | otherwise = putStr $ usage