From 4d2d0aa19822d9903ced2403aeaaa04ae63fa606 Mon Sep 17 00:00:00 2001 From: dneaves Date: Sun, 6 Sep 2026 14:21:44 -0400 Subject: [PATCH] Add basic view stuff in --- README.md | 1 + TODO.md | 3 ++ app/Glyph/Elements/Base.hs | 25 +++++++++++++ app/Glyph/Elements/BottomBar.hs | 28 +++++++++++++++ app/Glyph/Event.hs | 38 ++++++++++++++++++++ app/Glyph/Style.hs | 41 ++++++++++++++++++++++ app/Glyph/ViewId.hs | 8 +++++ app/Main.hs | 62 +++++++++++++++++++-------------- glyph.cabal | 11 +++++- lib/Glyph/Data/Mode.hs | 18 ++++++++++ lib/Glyph/Data/State.hs | 14 +++++++- 11 files changed, 220 insertions(+), 29 deletions(-) create mode 100644 README.md create mode 100644 TODO.md create mode 100644 app/Glyph/Elements/Base.hs create mode 100644 app/Glyph/Elements/BottomBar.hs create mode 100644 app/Glyph/Event.hs create mode 100644 app/Glyph/Style.hs create mode 100644 app/Glyph/ViewId.hs create mode 100644 lib/Glyph/Data/Mode.hs diff --git a/README.md b/README.md new file mode 100644 index 0000000..10ddd6d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Hello! diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..aab0a30 --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +- Add view bits +- Transform "raw" Dhall config modal keybinds into a parsable structure (looking at you, `CaptureNumbers`) + - Parse aforementioned keybinds in the view diff --git a/app/Glyph/Elements/Base.hs b/app/Glyph/Elements/Base.hs new file mode 100644 index 0000000..ae33537 --- /dev/null +++ b/app/Glyph/Elements/Base.hs @@ -0,0 +1,25 @@ +module Glyph.Elements.Base where + +---------------------------------------------------------------------------------------------------- + +import qualified Brick +import qualified Brick.Widgets.Border as Border +import qualified Brick.Widgets.Center as Center + +import Glyph.Data.State ( State (..) ) +import qualified Glyph.Elements.BottomBar as BB +import qualified Glyph.Style as Style +import Glyph.ViewId ( ViewId ) + +---------------------------------------------------------------------------------------------------- + +baseView :: State -> [Brick.Widget ViewId] +baseView state = + [ Brick.vBox + [ Brick.withBorderStyle Style.ruledBorderStyle + <. Border.border + <| Center.center + <| Brick.txt "Hello, World!" + , BB.bottomBar state + ] + ] diff --git a/app/Glyph/Elements/BottomBar.hs b/app/Glyph/Elements/BottomBar.hs new file mode 100644 index 0000000..24ab352 --- /dev/null +++ b/app/Glyph/Elements/BottomBar.hs @@ -0,0 +1,28 @@ +module Glyph.Elements.BottomBar where + +---------------------------------------------------------------------------------------------------- + +import qualified Brick + +import qualified Data.List as List +import qualified Data.Text as Text + +import Glyph.Control.Stringable ( Stringable (..) ) +import Glyph.Data.State ( State (..) ) +import Glyph.ViewId ( ViewId ) + +---------------------------------------------------------------------------------------------------- + +bottomBar :: State -> Brick.Widget ViewId +bottomBar state = + Brick.cropToContext + <. Brick.withAttr (Brick.attrName "bottomBar") + <. Brick.padRight Brick.Max + <. Brick.padLeftRight 1 + <| Brick.txt line + where + line :: Text + line = + [toText state.mode, "", state.status] + |> List.filter (Text.null .> not) + |> Text.intercalate " | " diff --git a/app/Glyph/Event.hs b/app/Glyph/Event.hs new file mode 100644 index 0000000..cea6c7b --- /dev/null +++ b/app/Glyph/Event.hs @@ -0,0 +1,38 @@ +module Glyph.Event where + +---------------------------------------------------------------------------------------------------- + +import qualified Brick + +import Glyph.Data.State ( State (..) ) +import Glyph.ViewId ( ViewId ) + +import qualified Graphics.Vty.Input.Events as VtyEvent + +---------------------------------------------------------------------------------------------------- + +data Event = Quit + deriving (Bounded, Enum, Eq, Ord, Show) + +---------------------------------------------------------------------------------------------------- + +update :: Brick.BrickEvent ViewId Event -> Brick.EventM ViewId State () +update = \case + Brick.VtyEvent event -> handleVtyEvent event + Brick.AppEvent event -> handleAppEvent event + Brick.MouseDown{} -> return () + Brick.MouseUp{} -> return () + +handleVtyEvent :: VtyEvent.Event -> Brick.EventM ViewId State () +handleVtyEvent = \case + VtyEvent.EvKey key modifiers -> Brick.halt + VtyEvent.EvResize _width _height -> return () + VtyEvent.EvMouseDown{} -> return () + VtyEvent.EvMouseUp{} -> return () + VtyEvent.EvPaste _bytes -> return () + VtyEvent.EvLostFocus -> return () + VtyEvent.EvGainedFocus -> return () + +handleAppEvent :: Event -> Brick.EventM ViewId State () +handleAppEvent = \case + Quit -> Brick.halt diff --git a/app/Glyph/Style.hs b/app/Glyph/Style.hs new file mode 100644 index 0000000..d15875e --- /dev/null +++ b/app/Glyph/Style.hs @@ -0,0 +1,41 @@ +module Glyph.Style where + +---------------------------------------------------------------------------------------------------- + +import qualified Brick +import Brick.Widgets.Border.Style ( BorderStyle (..) ) + +import Glyph.Data.State ( State ) + +import qualified Graphics.Vty.Attributes as VtyAttr +import qualified Graphics.Vty.Attributes.Color as VtyColor + +---------------------------------------------------------------------------------------------------- + +attrMap :: State -> Brick.AttrMap +attrMap _ = + Brick.attrMap + VtyAttr.defAttr + [ + ( Brick.attrName "bottomBar" + , VtyAttr.withBackColor + (VtyAttr.withForeColor VtyAttr.defAttr VtyColor.black) + (VtyColor.rgbColor (100 :: Word8) 50 200) + ) + ] + +ruledBorderStyle :: BorderStyle +ruledBorderStyle = + BorderStyle + { bsCornerTL = '─' + , bsCornerTR = '─' + , bsCornerBR = '─' + , bsCornerBL = '─' + , bsIntersectFull = '─' + , bsIntersectL = '─' + , bsIntersectR = '─' + , bsIntersectT = '─' + , bsIntersectB = '─' + , bsHorizontal = '─' + , bsVertical = ' ' + } diff --git a/app/Glyph/ViewId.hs b/app/Glyph/ViewId.hs new file mode 100644 index 0000000..7c24498 --- /dev/null +++ b/app/Glyph/ViewId.hs @@ -0,0 +1,8 @@ +module Glyph.ViewId + ( ViewId (..) + ) where + +---------------------------------------------------------------------------------------------------- + +data ViewId = BaseView + deriving (Eq, Ord, Show) diff --git a/app/Main.hs b/app/Main.hs index 5f52065..6660494 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -7,37 +7,45 @@ module Main import qualified Brick import qualified Brick.BChan as BChan +import Control.Monad ( void ) + +import Glyph.Data.State ( State ) +import qualified Glyph.Data.State as State +import qualified Glyph.Elements.Base as Base +import Glyph.Event ( Event ) +import qualified Glyph.Event as Event +import qualified Glyph.Style as Style +import Glyph.ViewId ( ViewId ) + import qualified Graphics.Vty as Vty import qualified Graphics.Vty.CrossPlatform as VtyPlatform -import TestStuff ( doTestStuff ) +-- import TestStuff ( doTestStuff ) ---------------------------------------------------------------------------------------------------- --- | Start the editor. main :: IO () -main = doTestStuff - --- let app :: Brick.App State Event ViewId --- app = --- Brick.App --- { Brick.appDraw = view --- , Brick.appChooseCursor = Brick.showFirstCursor --- , Brick.appHandleEvent = update --- , Brick.appStartEvent = pure () --- , Brick.appAttrMap = attrMap --- } - --- eventQueueDepth = 64 --- buildVty = VtyPlatform.mkVty Vty.defaultConfig --- in do --- startup <- Startup.loadStartup --- channel <- BChan.newBChan eventQueueDepth --- initialVty <- buildVty --- void <| --- Brick.customMain --- initialVty --- buildVty --- (Just channel) --- app --- (State.init startup.registry startup.keymaps startup.notices) +main = + -- doTestStuff + let app :: Brick.App State Event ViewId + app = + Brick.App + { Brick.appDraw = Base.baseView + , Brick.appChooseCursor = Brick.showFirstCursor + , Brick.appHandleEvent = Event.update + , Brick.appStartEvent = return () + , Brick.appAttrMap = Style.attrMap + } + + eventQueueDepth = 64 + buildVty = VtyPlatform.mkVty Vty.defaultConfig + in do + channel <- BChan.newBChan eventQueueDepth + initialVty <- buildVty + void <| + Brick.customMain + initialVty + buildVty + (Just channel) + app + State.initalState diff --git a/glyph.cabal b/glyph.cabal index 41f6460..0f20677 100644 --- a/glyph.cabal +++ b/glyph.cabal @@ -63,6 +63,7 @@ library lib Glyph.Data.Config.Dhall.ModalChars Glyph.Data.Config.Dhall.Modifier Glyph.Data.Config.Dhall.Prelude_ + Glyph.Data.Mode Glyph.Data.State Glyph.Data.String Prelude @@ -81,11 +82,19 @@ executable glyph ghc-options: -threaded hs-source-dirs: app main-is: Main.hs - other-modules: TestStuff + other-modules: + Glyph.Elements.Base + Glyph.Elements.BottomBar + Glyph.Event + Glyph.Style + Glyph.ViewId + TestStuff + build-depends: , brick >=2.12 && <3 , containers >=0.6 && <0.9 , glyph:lib + , text >=2.1 && <2.3 , vty >=6.5 && <7 , vty-crossplatform >=0.5 && <0.6 diff --git a/lib/Glyph/Data/Mode.hs b/lib/Glyph/Data/Mode.hs new file mode 100644 index 0000000..806ea4c --- /dev/null +++ b/lib/Glyph/Data/Mode.hs @@ -0,0 +1,18 @@ +module Glyph.Data.Mode where + +---------------------------------------------------------------------------------------------------- + +import Glyph.Control.Stringable ( Stringable (..) ) + +---------------------------------------------------------------------------------------------------- + +data Mode = Normal | Insert + deriving (Bounded, Enum, Eq, Ord, Show) + +instance Stringable Mode where + toString Normal = "NOR" + toString Insert = "INS" + + fromString "NOR" = Just Normal + fromString "INS" = Just Insert + fromString _ = Nothing diff --git a/lib/Glyph/Data/State.hs b/lib/Glyph/Data/State.hs index dd5088e..eb0c419 100644 --- a/lib/Glyph/Data/State.hs +++ b/lib/Glyph/Data/State.hs @@ -2,9 +2,21 @@ module Glyph.Data.State where ---------------------------------------------------------------------------------------------------- +import Glyph.Data.Mode ( Mode (..) ) + ---------------------------------------------------------------------------------------------------- data State = State - { notices :: List Text + { mode :: Mode + -- One Line of the whole status + , status :: Text + -- More specific notices on status + , notices :: List Text } + deriving (Eq, Show) + +---------------------------------------------------------------------------------------------------- + +initalState :: State +initalState = State Normal "" [] -- 2.54.0