Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out swarm-doc and swarm-tui sublibraries #1834

Merged
merged 10 commits into from
May 11, 2024
1 change: 0 additions & 1 deletion app/doc/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ cliParser =
, command "keys" (info (pure SpecialKeyNames) $ progDesc "Output list of recognized special key names")
, command "cheatsheet" (info (CheatSheet <$> address <*> cheatsheet <**> helper) $ progDesc "Output nice Wiki tables")
, command "pedagogy" (info (pure TutorialCoverage) $ progDesc "Output tutorial coverage")
, command "endpoints" (info (pure WebAPIEndpoints) $ progDesc "Generate markdown Web API documentation.")
]
where
editor :: Parser (Maybe EditorType)
Expand Down
11 changes: 0 additions & 11 deletions src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ module Swarm.TUI.Controller (

-- ** Info panel
handleInfoPanelEvent,

-- ** Utils
getTutorials,
) where

import Brick hiding (Direction, Location)
Expand Down Expand Up @@ -140,9 +137,6 @@ import Prelude hiding (Applicative (..)) -- See Note [liftA2 re-export from Prel
-- we could get rid of both explicit imports and just get liftA2 and
-- pure implicitly from Prelude.

tutorialsDirname :: FilePath
tutorialsDirname = "Tutorials"

-- | The top-level event handler for the TUI.
handleEvent :: BrickEvent Name AppEvent -> EventM Name AppState ()
handleEvent = \case
Expand Down Expand Up @@ -226,11 +220,6 @@ handleMainMenuEvent menu = \case
uiState . uiMenu .= MainMenu menu'
_ -> continueWithoutRedraw

getTutorials :: ScenarioCollection -> ScenarioCollection
getTutorials sc = case M.lookup tutorialsDirname (scMap sc) of
Just (SICollection _ c) -> c
_ -> error $ "No tutorials exist: " ++ show sc

-- | If we are in a New Game menu, advance the menu to the next item in order.
--
-- NOTE: be careful to maintain the invariant that the currently selected
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions app/doc/Swarm/Doc/Gen.hs → src/swarm-doc/Swarm/Doc/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import Swarm.Game.World.Typecheck (Some (..), TTerm)
import Swarm.Language.Key (specialKeyNames)
import Swarm.Util (both, listEnums)
import Swarm.Util.Effect (simpleErrorHandle)
import Swarm.Web (swarmApiMarkdown)
import Text.Dot (Dot, NodeId, (.->.))
import Text.Dot qualified as Dot

Expand All @@ -68,8 +67,6 @@ data GenerateDocs where
CheatSheet :: PageAddress -> Maybe SheetType -> GenerateDocs
-- | List command introductions by tutorial
TutorialCoverage :: GenerateDocs
-- | Web API endpoints
WebAPIEndpoints :: GenerateDocs
deriving (Eq, Show)

-- | Generate the requested kind of documentation to stdout.
Expand All @@ -90,7 +87,6 @@ generateDocs = \case
SpecialKeyNames -> generateSpecialKeyNames
CheatSheet address s -> makeWikiPage address s
TutorialCoverage -> renderTutorialProgression >>= putStrLn . T.unpack
WebAPIEndpoints -> putStrLn swarmApiMarkdown

-- ----------------------------------------------------------------------------
-- GENERATE KEYWORDS: LIST OF WORDS TO BE HIGHLIGHTED
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Swarm.Game.ScenarioInfo (
ScenarioCollection,
ScenarioInfoPair,
flatten,
getTutorials,
loadScenarios,
scenarioCollectionToList,
scenarioPath,
Expand All @@ -58,7 +59,6 @@ import Swarm.Language.Pipeline (ProcessedTerm (..))
import Swarm.Language.Syntax
import Swarm.Language.Text.Markdown (docToText, findCode)
import Swarm.Language.Types (Polytype)
import Swarm.TUI.Controller (getTutorials)
import Swarm.Util.Effect (ignoreWarnings, simpleErrorHandle)

-- * Constants
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 15 additions & 2 deletions src/swarm-engine/Swarm/Game/ScenarioInfo.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}

-- -Wno-orphans is for the Eq/Ord Time instances

-- |
-- SPDX-License-Identifier: BSD-3-Clause
--
Expand All @@ -27,6 +25,10 @@ module Swarm.Game.ScenarioInfo (
scenarioItemName,
_SISingle,

-- ** Tutorials
tutorialsDirname,
getTutorials,

-- * Loading and saving scenarios
loadScenarios,
loadScenarioInfo,
Expand Down Expand Up @@ -103,6 +105,17 @@ scenarioItemByPath path = ixp ps
SISingle {} -> pure si
SICollection n' col -> SICollection n' <$> ixp xs f col

-- | Subdirectory of the scenarios directory where tutorials are stored.
tutorialsDirname :: FilePath
tutorialsDirname = "Tutorials"

-- | Extract just the collection of tutorial scenarios from the entire
-- scenario collection.
getTutorials :: ScenarioCollection -> ScenarioCollection
getTutorials sc = case M.lookup tutorialsDirname (scMap sc) of
Just (SICollection _ c) -> c
_ -> error $ "No tutorials exist: " ++ show sc

-- | Canonicalize a scenario path, making it usable as a unique key.
normalizeScenarioPath ::
(MonadIO m) =>
Expand Down
Loading
Loading