diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-22 00:49:16 +0000 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-22 00:49:16 +0000 |
| commit | 7ca94fb84f967fcfc741b7aa3662356e4fc0241f (patch) | |
| tree | ca2c417b1dac7a8e6b19af73c47223008c48685e /webgui/src | |
| parent | 9e45c04c45aef1fa71815c61512c354d0d5ee3e3 (diff) | |
| download | thermoprint-7ca94fb84f967fcfc741b7aa3662356e4fc0241f.tar thermoprint-7ca94fb84f967fcfc741b7aa3662356e4fc0241f.tar.gz thermoprint-7ca94fb84f967fcfc741b7aa3662356e4fc0241f.tar.bz2 thermoprint-7ca94fb84f967fcfc741b7aa3662356e4fc0241f.tar.xz thermoprint-7ca94fb84f967fcfc741b7aa3662356e4fc0241f.zip | |
First stab at threepenny gui
Diffstat (limited to 'webgui/src')
| -rw-r--r-- | webgui/src/Main.hs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/webgui/src/Main.hs b/webgui/src/Main.hs new file mode 100644 index 0000000..d96083e --- /dev/null +++ b/webgui/src/Main.hs | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | module Main (main) where | ||
| 2 | |||
| 3 | import qualified Graphics.UI.Threepenny as UI | ||
| 4 | import Graphics.UI.Threepenny.Core | ||
| 5 | |||
| 6 | import Thermoprint.Client | ||
| 7 | |||
| 8 | import qualified Options.Applicative as Opt | ||
| 9 | import System.Environment | ||
| 10 | |||
| 11 | import Data.ByteString (ByteString) | ||
| 12 | import qualified Data.ByteString as BS | ||
| 13 | import qualified Data.ByteString.Char8 as CBS | ||
| 14 | |||
| 15 | import Control.Applicative | ||
| 16 | import Control.Monad | ||
| 17 | import Data.Maybe | ||
| 18 | import Data.Monoid | ||
| 19 | import Text.Read | ||
| 20 | |||
| 21 | main :: IO () | ||
| 22 | main = config >>= Opt.execParser . opts >>= flip startGUI setup | ||
| 23 | where | ||
| 24 | opts config = Opt.info (Opt.helper <*> config) | ||
| 25 | ( Opt.fullDesc | ||
| 26 | <> Opt.progDesc "Run a webgui to Thermoprint.Client" | ||
| 27 | ) | ||
| 28 | |||
| 29 | config :: IO (Opt.Parser Config) | ||
| 30 | config = do | ||
| 31 | p <- fromMaybe 8023 . (readMaybe =<<) <$> lookupEnv portEnv | ||
| 32 | a <- fromMaybe "localhost" <$> lookupEnv hostEnv | ||
| 33 | return $ (\port addr -> defaultConfig { jsPort = port, jsAddr = addr }) | ||
| 34 | <$> optional (Opt.option Opt.auto $ port p) | ||
| 35 | <*> optional (fmap CBS.pack $ Opt.strOption $ addr a) | ||
| 36 | where | ||
| 37 | port def = Opt.long "port" | ||
| 38 | <> Opt.short 'p' | ||
| 39 | <> Opt.metavar "PORT" | ||
| 40 | <> Opt.help ("Port to bind to; default read from $" <> portEnv) | ||
| 41 | <> Opt.value def | ||
| 42 | <> Opt.showDefault | ||
| 43 | addr def = Opt.long "addr" | ||
| 44 | <> Opt.short 'a' | ||
| 45 | <> Opt.metavar "HOST" | ||
| 46 | <> Opt.help ("Host to listen on; default read from $" <> hostEnv) | ||
| 47 | <> Opt.value def | ||
| 48 | <> Opt.showDefault | ||
| 49 | hostEnv = "ADDR" | ||
| 50 | portEnv = "PORT" | ||
| 51 | |||
| 52 | setup :: Window -> UI () | ||
| 53 | setup window = void $ do | ||
| 54 | return window # set UI.title "Thermoprint" | ||
| 55 | |||
| 56 | title <- UI.input | ||
| 57 | # set UI.id_ "title" | ||
| 58 | content <- UI.textarea | ||
| 59 | # set UI.id_ "content" | ||
| 60 | draftTable <- UI.table | ||
| 61 | |||
| 62 | saveBtn <- UI.button #+ [string "Save"] | ||
| 63 | discBtn <- UI.button #+ [string "Discard"] | ||
| 64 | prntBtn <- UI.button #+ [string "Print"] | ||
| 65 | |||
| 66 | getBody window #+ [ row [ column [ UI.h1 #+ [string "Current draft"] | ||
| 67 | , row [UI.label # set text "Title" # set UI.for "title", element title] | ||
| 68 | , element content | ||
| 69 | , row [ element saveBtn | ||
| 70 | , element prntBtn | ||
| 71 | , element discBtn | ||
| 72 | ] | ||
| 73 | ] | ||
| 74 | , column [ UI.h1 #+ [string "Saved drafts"] | ||
| 75 | , element draftTable | ||
| 76 | ] | ||
| 77 | ] | ||
| 78 | ] | ||
