ghcup-hs/lib-tui/GHCup/BrickMain.hs

79 lines
2.9 KiB
Haskell
Raw Normal View History

2024-01-10 06:14:59 +00:00
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -Wno-unused-record-wildcards #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-
This module contains the entrypoint for the brick application and nothing else.
-}
module GHCup.BrickMain where
import GHCup.Types
( Settings(noColor),
2024-02-28 09:29:39 +00:00
AppState(ghcupInfo, settings, keyBindings, loggerConfig), KeyBindings (..) )
2024-01-10 06:14:59 +00:00
import GHCup.Prelude.Logger ( logError )
import qualified GHCup.Brick.Actions as Actions
import qualified GHCup.Brick.Common as Common
import qualified GHCup.Brick.App as BrickApp
import qualified GHCup.Brick.Attributes as Attributes
import qualified GHCup.Brick.BrickState as AppState
2024-02-28 08:37:17 +00:00
import qualified GHCup.Brick.Widgets.Menus.Context as ContextMenu
import qualified GHCup.Brick.Widgets.SectionList as Navigation
2024-02-28 09:29:39 +00:00
import qualified GHCup.Brick.Widgets.Menus.AdvanceInstall as AdvanceInstall
2024-02-28 16:01:54 +00:00
import qualified GHCup.Brick.Widgets.Menus.CompileGHC as CompileGHC
2024-01-10 06:14:59 +00:00
import qualified Brick
import Control.Monad.Reader ( ReaderT(runReaderT) )
import Data.Functor ( ($>) )
import Data.IORef (writeIORef)
import Prelude hiding ( appendFile )
import System.Exit ( ExitCode(ExitFailure), exitWith )
import qualified Data.Text as T
2024-03-04 16:32:22 +00:00
import qualified GHCup.Brick.Widgets.Menus.CompileHLS as CompileHLS
2024-01-10 06:14:59 +00:00
brickMain :: AppState
-> IO ()
brickMain s = do
writeIORef Actions.settings' s
eAppData <- Actions.getAppData (Just $ ghcupInfo s)
case eAppData of
2024-02-28 08:37:17 +00:00
Right ad -> do
let initial_list = Actions.constructList ad Common.defaultAppSettings Nothing
current_element = Navigation.sectionListSelectedElement initial_list
exit_key = bQuit . keyBindings $ s
case current_element of
Nothing -> do
flip runReaderT s $ logError "Error building app state: empty ResultList"
exitWith $ ExitFailure 2
Just (_, e) ->
let initapp =
BrickApp.app
(Attributes.defaultAttributes $ noColor $ settings s)
(Attributes.dimAttributes $ noColor $ settings s)
initstate =
AppState.BrickState ad
Common.defaultAppSettings
initial_list
(ContextMenu.create e exit_key)
2024-02-28 09:29:39 +00:00
(AdvanceInstall.create (bQuit . keyBindings $ s ))
2024-02-28 16:01:54 +00:00
(CompileGHC.create exit_key)
2024-03-04 16:32:22 +00:00
(CompileHLS.create exit_key)
2024-02-28 08:37:17 +00:00
(keyBindings s)
Common.Navigation
in Brick.defaultMain initapp initstate
$> ()
2024-01-10 06:14:59 +00:00
Left e -> do
flip runReaderT s $ logError $ "Error building app state: " <> T.pack (show e)
exitWith $ ExitFailure 2