minimal happs-based web ui, enabled with -f happs
This commit is contained in:
parent
e361b789a0
commit
ea0c32641d
39
HappsCommand.hs
Normal file
39
HappsCommand.hs
Normal file
@ -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
|
||||||
2
Makefile
2
Makefile
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# build the normal hledger binary
|
# build the normal hledger binary
|
||||||
BUILD=ghc --make hledger.hs -o hledger -O
|
BUILD=ghc --make hledger.hs -o hledger -O
|
||||||
BUILDFLAGS=-DVTY -DANSI
|
BUILDFLAGS=-DVTY -DANSI -DHAPPS
|
||||||
build: setbuildversion tag
|
build: setbuildversion tag
|
||||||
$(BUILD) $(BUILDFLAGS)
|
$(BUILD) $(BUILDFLAGS)
|
||||||
|
|
||||||
|
|||||||
3
README
3
README
@ -37,10 +37,11 @@ features. These are::
|
|||||||
|
|
||||||
-f vty - Build vty-based text ui (requires vty, not available on windows)
|
-f vty - Build vty-based text ui (requires vty, not available on windows)
|
||||||
-f ansi - Build ansi-based text ui (requires ansi-terminal)
|
-f ansi - Build ansi-based text ui (requires ansi-terminal)
|
||||||
|
-f happs - Build happs-based web ui (requires HApps-Server)
|
||||||
|
|
||||||
Eg::
|
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::
|
To get the latest development code do::
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,9 @@ Flag vty
|
|||||||
Flag ansi
|
Flag ansi
|
||||||
description: Build ansi-based text ui (requires ansi-terminal)
|
description: Build ansi-based text ui (requires ansi-terminal)
|
||||||
default: False
|
default: False
|
||||||
|
Flag happs
|
||||||
|
description: Build happs-based web ui (requires HApps-Server)
|
||||||
|
default: False
|
||||||
|
|
||||||
Executable hledger
|
Executable hledger
|
||||||
Main-Is: hledger.hs
|
Main-Is: hledger.hs
|
||||||
@ -69,6 +72,10 @@ Executable hledger
|
|||||||
Build-Depends:ansi-terminal
|
Build-Depends:ansi-terminal
|
||||||
Other-Modules:ANSICommand
|
Other-Modules:ANSICommand
|
||||||
cpp-options: -DANSI
|
cpp-options: -DANSI
|
||||||
|
if flag(happs)
|
||||||
|
Build-Depends:HAppS-Server>=0.9.3.1
|
||||||
|
Other-Modules:HappsCommand
|
||||||
|
cpp-options: -DHAPPS
|
||||||
|
|
||||||
Library
|
Library
|
||||||
Build-Depends: base, containers, haskell98, directory, parsec, regex-compat,
|
Build-Depends: base, containers, haskell98, directory, parsec, regex-compat,
|
||||||
|
|||||||
@ -58,6 +58,9 @@ import qualified UICommand
|
|||||||
#ifdef ANSI
|
#ifdef ANSI
|
||||||
import qualified ANSICommand
|
import qualified ANSICommand
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAPPS
|
||||||
|
import qualified HappsCommand
|
||||||
|
#endif
|
||||||
import Tests
|
import Tests
|
||||||
|
|
||||||
|
|
||||||
@ -77,6 +80,9 @@ main = do
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ANSI
|
#ifdef ANSI
|
||||||
| cmd `isPrefixOf` "ansi" = parseLedgerAndDo opts args ANSICommand.ansi
|
| cmd `isPrefixOf` "ansi" = parseLedgerAndDo opts args ANSICommand.ansi
|
||||||
|
#endif
|
||||||
|
#ifdef HAPPS
|
||||||
|
| cmd `isPrefixOf` "happs" = parseLedgerAndDo opts args HappsCommand.happs
|
||||||
#endif
|
#endif
|
||||||
| cmd `isPrefixOf` "test" = runtests opts args >> return ()
|
| cmd `isPrefixOf` "test" = runtests opts args >> return ()
|
||||||
| otherwise = putStr $ usage
|
| otherwise = putStr $ usage
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user