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

Fix REPL type display #1610

Merged
merged 3 commits into from
Nov 11, 2023
Merged
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
5 changes: 2 additions & 3 deletions src/Swarm/TUI/Panel.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
{-# LANGUAGE TemplateHaskell #-}

-- |
Expand All @@ -9,7 +7,8 @@
-- a border around some content, with the color of the border
-- depending on whether the panel is currently focused. Panels exist
-- within a 'FocusRing' such that the user can cycle between the
-- panels (using /e.g./ the @Tab@ key).
-- panels (using /e.g./ the @Tab@ key). Panels can also have labels
-- at up to 6 locations (top\/bottom, left\/center\/right).
module Swarm.TUI.Panel (
panel,
) where
Expand Down
11 changes: 9 additions & 2 deletions src/Swarm/TUI/View/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Swarm.Game.Scenario (scenarioName)
import Swarm.Game.ScenarioInfo (scenarioItemName)
import Swarm.Game.State
import Swarm.Game.Terrain
import Swarm.Language.Pretty (prettyText)
import Swarm.Language.Pretty (prettyTextLine)
import Swarm.Language.Syntax (Syntax)
import Swarm.Language.Text.Markdown qualified as Markdown
import Swarm.Language.Types (Polytype)
Expand Down Expand Up @@ -115,7 +115,14 @@ generateModal s mt = Modal mt (dialog (Just $ str title) buttons (maxModalWindow

-- | Render the type of the current REPL input to be shown to the user.
drawType :: Polytype -> Widget Name
drawType = withAttr infoAttr . padLeftRight 1 . txt . prettyText
drawType ty = Widget Fixed Fixed $ do
ctx <- getContext
let w = ctx ^. availWidthL
renderedTy = prettyTextLine ty
displayedTy
| T.length renderedTy <= w `div` 2 - 2 = renderedTy
| otherwise = T.take (w `div` 2 - 2 - 3) renderedTy <> "..."
render . withAttr infoAttr . padLeftRight 1 . txt $ displayedTy

-- | Draw markdown document with simple code/bold/italic attributes.
--
Expand Down