Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions waspc/cli/src/Wasp/Cli/Command/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module Wasp.Cli.Command.Start
)
where

import qualified Brick as B
import qualified Brick.Widgets.Border as B
import qualified Brick.Widgets.Border.Style as B
import qualified Brick.Widgets.Center as B
import Control.Concurrent ()
import Control.Concurrent.Async (race)
import Control.Concurrent.MVar (MVar, newMVar, tryTakeMVar)
import Control.Monad.Except (throwError)
import Control.Monad.IO.Class (liftIO)
import qualified Graphics.Vty
import qualified Graphics.Vty as Vty
import StrongPath ((</>))
import Wasp.Cli.Command (Command, CommandError (..))
import Wasp.Cli.Command.Compile (compile, printWarningsAndErrorsIfAny)
Expand All @@ -19,10 +25,73 @@ import qualified Wasp.Message as Msg
import Wasp.Project (CompileError, CompileWarning)
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)

-- TODO:
-- This is just some initial experimentation, but it looks very promising. Very little, simple code, to get what we need.
--
-- Main thing that will be missing is escaping the ansii control characters. Brick and Vty can't work with them,
-- so to show the output from underlying processes, we will need to escape/rewrite them -> replace them with Vty's styling.
-- This shouldn't be so hard, especially with AI's help -> we can handle most common ones and just skip the rest.
-- Handling of \r will also be interesting, sometihng we can consider.
--
-- Then, we can just pipe all the output from the processes into the Brick's BChan, if I am correct,
-- and re-render whenever a new info comes.
--
-- We will want to wrap logs into vertical scroll and then maybe do some optimizing regarding what is drawn (maybe not).
--
-- There is even support for animations, if we want to play with that.
--
-- Btw here is the central piece of Brick docs: https://github.com/jtdaugherty/brick/blob/master/docs/guide.rst .

start :: Command ()
start = liftIO $ do
B.defaultMain app ()

-- | Resource name
data ResName = NoNamesYet
deriving (Ord, Eq)

app :: B.App () e ResName
app =
B.App
{ appDraw = const [ui],
appHandleEvent = \case
B.VtyEvent (Vty.EvKey (Vty.KChar 'q') []) -> B.halt
_otherEvent -> pure (),
appStartEvent = pure (),
appAttrMap =
const $
B.attrMap
Vty.defAttr
[ (B.attrName "waspLogo", B.fg Vty.yellow `Vty.withStyle` Vty.bold),
(B.attrName "selectedTab", Vty.black `B.on` Vty.yellow `Vty.withStyle` Vty.bold)
],
appChooseCursor = B.neverShowCursor
}

ui :: B.Widget ResName
ui =
B.joinBorders $
B.withBorderStyle B.unicode $
B.vBox
[ B.border $
B.vLimit 1 $
B.hBox
[ B.withAttr (B.attrName "waspLogo") $ B.padLeftRight 1 $ B.str "Wasp =}",
B.vBorder,
B.fill ' ',
B.padLeftRight 1 $ B.str "1:Client",
B.withAttr (B.attrName "selectedTab") $ B.padLeftRight 1 $ B.str "2:Server",
B.padLeftRight 1 $ B.str "3:Db",
B.padLeftRight 1 $ B.str "4:All"
],
B.padAll 1 $ B.center $ B.str "Here come the logs!",
B.border $ B.vLimit 1 $ B.hBox [B.padLeftRight 1 $ B.str "footer", B.fill ' ']
]

-- | Does initial compile of wasp code and then runs the generated project.
-- It also listens for any file changes and recompiles and restarts generated project accordingly.
start :: Command ()
start = do
start' :: Command ()
start' = do
InWaspProject waspProjectDir <- require
let outDir = waspProjectDir </> dotWaspDirInWaspProjectDir </> generatedCodeDirInDotWaspDir

Expand Down
2 changes: 2 additions & 0 deletions waspc/waspc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ library cli-lib
, time
, aeson
, aeson-pretty
, brick ^>=2.8.0
, mtl
, async
, exceptions
Expand All @@ -553,6 +554,7 @@ library cli-lib
, unordered-containers ^>= 0.2.16
, bytestring ^>= 0.11
, tar ^>=0.5.1.1
, vty
, zlib ^>=0.6.3.0
, temporary ^>=1.3
other-modules:
Expand Down
Loading