diff --git a/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs b/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs index febde50eb..dc5b62b1a 100644 --- a/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs +++ b/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs @@ -9,8 +9,9 @@ module Swarm.TUI.Controller.UpdateUI ( updateAndRedrawUI, ) where -import Brick hiding (Direction, Location) +import Brick hiding (Direction, Location, on) import Brick.Focus +import Data.Function (on) -- See Note [liftA2 re-export from Prelude] import Brick.Widgets.List qualified as BL @@ -44,7 +45,7 @@ import Swarm.TUI.Model.Repl import Swarm.TUI.Model.UI import Swarm.TUI.View.Objective qualified as GR import Swarm.TUI.View.Robot -import Swarm.TUI.View.Robot.Type (libList, robID, robotListContent) +import Swarm.TUI.View.Robot.Type (libList, rob, robotListContent) import Witch (into) import Prelude hiding (Applicative (..)) @@ -192,11 +193,11 @@ doRobotListUpdate g = do , _uiDbg = dOps } oldList = getList $ gp ^. uiDialogs . uiRobot . robotListContent . libList - maybeOldSelectedRID = robID . snd <$> BL.listSelectedElement oldList + maybeOldSelected = snd <$> BL.listSelectedElement oldList - modificationFunc = case maybeOldSelectedRID of + modificationFunc = case maybeOldSelected of Nothing -> id - Just oldSelectedRID -> updateList (BL.listFindBy ((== oldSelectedRID) . robID)) + Just oldSelected -> updateList (BL.listFindBy (((==) `on` (view robotID . rob)) oldSelected)) uiState . uiGameplay . uiDialogs . uiRobot . robotListContent . libList .= modificationFunc rd diff --git a/src/swarm-tui/Swarm/TUI/View.hs b/src/swarm-tui/Swarm/TUI/View.hs index 7a1aff2fb..57296be3d 100644 --- a/src/swarm-tui/Swarm/TUI/View.hs +++ b/src/swarm-tui/Swarm/TUI/View.hs @@ -619,12 +619,12 @@ drawModal s = \case HelpModal -> helpWidget (s ^. gameState . randomness . seed) (s ^. runtimeState . webPort) (s ^. keyEventHandling) RobotsModal -> case s ^. uiState . uiGameplay . uiDialogs . uiRobot . robotsDisplayMode of RobotList -> renderRobotsList $ s ^. uiState . uiGameplay . uiDialogs . uiRobot . robotListContent - SingleRobotDetails -> case maybeSelectedRID of + SingleRobotDetails -> case maybeSelectedRobot of Nothing -> str "No selection" - Just selectedRID -> renderRobotDetails selectedRID + Just r -> renderRobotDetails r where oldList = getList $ s ^. uiState . uiGameplay . uiDialogs . uiRobot . robotListContent . libList - maybeSelectedRID = robID . snd <$> BL.listSelectedElement oldList + maybeSelectedRobot = rob . snd <$> BL.listSelectedElement oldList RecipesModal -> availableListWidget (s ^. gameState) RecipeList CommandsModal -> commandsListWidget (s ^. gameState) MessagesModal -> availableListWidget (s ^. gameState) MessageList diff --git a/src/swarm-tui/Swarm/TUI/View/Robot.hs b/src/swarm-tui/Swarm/TUI/View/Robot.hs index 57a017fef..385f58921 100644 --- a/src/swarm-tui/Swarm/TUI/View/Robot.hs +++ b/src/swarm-tui/Swarm/TUI/View/Robot.hs @@ -270,7 +270,7 @@ mkLibraryEntries c = mkRobotRow <$> S.fromList robots where mkRobotRow robot = - RobotRowPayload (robot ^. robotID) $ + RobotRowPayload robot $ LibRobotRow { _fID = strWidget $ show $ robot ^. robotID , _fName = nameWidget diff --git a/src/swarm-tui/Swarm/TUI/View/Robot/Details.hs b/src/swarm-tui/Swarm/TUI/View/Robot/Details.hs index 8f9e4a526..1a088a9fd 100644 --- a/src/swarm-tui/Swarm/TUI/View/Robot/Details.hs +++ b/src/swarm-tui/Swarm/TUI/View/Robot/Details.hs @@ -3,45 +3,75 @@ module Swarm.TUI.View.Robot.Details (renderRobotDetails) where import Brick -import Brick.Widgets.Border -import Brick.Widgets.List qualified as BL -import Brick.Widgets.TabularList.Mixed +import Brick.Widgets.Center (hCenter) +import Brick.Widgets.Table qualified as BT import Control.Lens hiding (from, (<.>)) -import Control.Lens as Lens hiding (Const, from) -import Data.IntMap qualified as IM -import Data.List (transpose) +import Data.Foldable (Foldable (toList)) import Data.Map qualified as M -import Data.Maybe (fromMaybe) -import Data.Sequence (Seq) -import Data.Sequence qualified as S -import Data.Set (Set) -import Data.Text qualified as T -import Data.Vector (Vector) -import Data.Vector qualified as V -import Linear (V2 (..), distance) -import Numeric (showFFloat) -import Swarm.Game.CESK (CESK (..)) -import Swarm.Game.Entity as E -import Swarm.Game.Location +import Prettyprinter (pretty) import Swarm.Game.Robot import Swarm.Game.Robot.Activity import Swarm.Game.Robot.Concrete -import Swarm.Game.State -import Swarm.Game.State.Robot -import Swarm.Game.State.Substate -import Swarm.Game.Tick (addTicks) -import Swarm.Game.Universe -import Swarm.Game.World.Coords -import Swarm.TUI.Model.DebugOption +import Swarm.Language.Pretty (prettyText) +import Swarm.Log import Swarm.TUI.Model.Name -import Swarm.TUI.Model.UI.Gameplay -import Swarm.TUI.View.Attribute.Attr -import Swarm.TUI.View.CellDisplay -import Swarm.TUI.View.Robot.Type -import Swarm.Util (applyWhen, maximum0) -import Swarm.Util.UnitInterval -import Swarm.Util.WindowedCounter qualified as WC -import System.Clock (TimeSpec (..)) +import Swarm.TUI.View.Attribute.Attr (boldAttr) -renderRobotDetails selectedRID = - str $ unwords ["Selected robot", show selectedRID] +renderRobotDetails :: Robot -> Widget Name +renderRobotDetails robot = + vBox + [ hCenter $ + str $ + unwords + [ "Selected robot" + , show $ view robotID robot + ] + , str "-------------------" + , logsTable + , str " " + , hBox [commandsTable, padLeft (Pad 2) inventorySummary] + ] + where + inventorySummary = + vBox $ + map + str + [ "6 things" + , "7 things" + ] + + logsTable = + BT.renderTable + . BT.columnBorders True + . BT.rowBorders False + . BT.surroundingBorder False + . BT.setDefaultColAlignment BT.AlignLeft + . BT.setColAlignment BT.AlignRight 0 + . BT.table + $ (map (withAttr boldAttr . str) ["Time", "Entry"] : logsTableEntries) + + mkLogTableEntry x = + [ str . show . pretty . view leTime $ x + , txt . view leText $ x + ] + logsTableEntries = map mkLogTableEntry . toList . view robotLog $ robot + + commandsTable = + BT.renderTable + . BT.columnBorders True + . BT.rowBorders False + . BT.surroundingBorder False + . BT.setDefaultColAlignment BT.AlignLeft + . BT.setColAlignment BT.AlignRight 0 + . BT.table + $ map (withAttr boldAttr . str) ["Command", "Count"] : commandHistogramEntries + + mkHistogramEntry (k, v) = + [ txt $ prettyText k + , str $ show v + ] + + commandHistogramEntries = + map mkHistogramEntry $ + M.toList $ + robot ^. activityCounts . commandsHistogram diff --git a/src/swarm-tui/Swarm/TUI/View/Robot/Type.hs b/src/swarm-tui/Swarm/TUI/View/Robot/Type.hs index 0f1b43d53..7d08ef419 100644 --- a/src/swarm-tui/Swarm/TUI/View/Robot/Type.hs +++ b/src/swarm-tui/Swarm/TUI/View/Robot/Type.hs @@ -36,7 +36,7 @@ newtype Widths = Widths deriving (Generic) data RobotRowPayload a = RobotRowPayload - { robID :: RID + { rob :: Robot , rPayload :: LibRobotRow a } deriving (Functor) diff --git a/swarm.cabal b/swarm.cabal index 18b0da043..fab381f95 100644 --- a/swarm.cabal +++ b/swarm.cabal @@ -965,6 +965,7 @@ library swarm-tui brick-tabular-list, bytestring, clock, + prettyprinter, colour, containers, extra,