Skip to content

Commit

Permalink
Ormolu formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Garner committed Oct 19, 2020
1 parent b287dfc commit 819a8a5
Show file tree
Hide file tree
Showing 21 changed files with 926 additions and 864 deletions.
2 changes: 1 addition & 1 deletion .envrc
@@ -1 +1 @@
eval "$(lorri direnv)"
use nix
11 changes: 8 additions & 3 deletions shell.nix
Expand Up @@ -2,22 +2,27 @@ let
pkgs = import <nixpkgs> {};
dhall = import (fetchTarball {
url = https://hydra.dhall-lang.org/jobset/dhall-haskell/master/channel/latest/nixexprs.tar.bz2;
sha256 = "127r3nabcc4snqy1jap0yyas2cfjyiz5qxhz5dyjd56nznkfda5a";
sha256 = "0636c1lz1ndsdskgvqcbrfx2bav6hycdwlbsbyv0lvl9ykca1mk4";
}) {};
nix-tools = import (fetchTarball {
url = https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz;
sha256 = "08sf4k9w6gn2scp86bcq0j27akjrxykf8dziy12dm61aqhwy948q";
}) {};
hls = (import (builtins.fetchTarball "https://github.com/shajra/nix-hls/tarball/master") {ghcVersion = "ghc884";});
# hls = (import (builtins.fetchTarball "https://github.com/shajra/nix-hls/tarball/master") {ghcVersion = "ghc884";});
in
pkgs.mkShell {
buildInputs = [
pkgs.termite
pkgs.stack
pkgs.dhall
pkgs.glibc
hls.hls
# hls.hls
pkgs.haskellPackages.ghcide
dhall.linux-dhall-lsp-server
pkgs.haskellPackages.ormolu
];
shellHook = ''
export TEST="IN HERE!"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${pkgs.glibc}/lib
'';
}
19 changes: 10 additions & 9 deletions src/Actions/ActionTypes.hs
@@ -1,10 +1,10 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveAnyClass #-}

module Actions.ActionTypes where

import Standard
import Dhall (Interpret)
import FocusList
import Dhall (Interpret)
import FocusList
import Standard

-- | Actions/events to be performed
data Action
Expand Down Expand Up @@ -38,11 +38,12 @@ data Action
deriving (Show, Generic, Interpret)

-- | Modes similar to modes in vim
data Mode = NewMode { modeName :: Text
, hasButtons :: Bool
, hasBorders :: Bool
}
data Mode = NewMode
{ modeName :: Text,
hasButtons :: Bool,
hasBorders :: Bool
}
deriving (Show, Generic, Interpret)

instance Eq Mode where
n1 == n2 = modeName n1 == modeName n2

232 changes: 118 additions & 114 deletions src/Base/DoAll.hs
@@ -1,112 +1,117 @@
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- |There's a lot going on in this module and it can be really confusing if you
-- aren't familiar with some fairly new Haskell extensions. Xest's effect
-- system is provided by the Capability library. Capability provides what is
-- essentially the ReaderT pattern with some code for reducing
-- boilerplate. The boilerplate reducing code depends on deriving via, a GHC
-- extension, and a bunch of newtypes exported by the library. To further
-- reduce the boilerplate, I've used a Template Haskell function for some of
-- the derivations.
-- | There's a lot going on in this module and it can be really confusing if you
-- aren't familiar with some fairly new Haskell extensions. Xest's effect
-- system is provided by the Capability library. Capability provides what is
-- essentially the ReaderT pattern with some code for reducing
-- boilerplate. The boilerplate reducing code depends on deriving via, a GHC
-- extension, and a bunch of newtypes exported by the library. To further
-- reduce the boilerplate, I've used a Template Haskell function for some of
-- the derivations.
module Base.DoAll
( module Base.Helpers
, module Base.Other
, module Base.Mover
, module Base.Property
, module Base.Minimizer
, module Base.Executor
, module Base.Global
, module Base.EventFlags
, module Base.Colorer
, module Base.Unmanaged
, module Base.DoAll
( module Base.Helpers,
module Base.Other,
module Base.Mover,
module Base.Property,
module Base.Minimizer,
module Base.Executor,
module Base.Global,
module Base.EventFlags,
module Base.Colorer,
module Base.Unmanaged,
module Base.DoAll,
)
where

import Standard
import Graphics.X11.Xlib.Types
import Graphics.X11.Xlib.Extras
import Graphics.X11.Types
import qualified Data.Map as M
import qualified SDL
import Base.Helpers
import Base.Other
import Base.Mover
import Base.Property
import Base.Minimizer
import Base.Executor
import Base.Global
import Base.Colorer
import Base.EventFlags
import Base.Unmanaged
import Tiler.TilerTypes
import Tiler.ParentChild
import TH
import Config
import Actions.ActionTypes
import qualified SDL.Font as Font
import qualified Control.Monad.Reader as R
import Graphics.X11.Xinerama (XineramaScreenInfo)
import Actions.ActionTypes
import Base.Colorer
import Base.EventFlags
import Base.Executor
import Base.Global
import Base.Helpers
import Base.Minimizer
import Base.Mover
import Base.Other
import Base.Property
import Base.Unmanaged
import Capability.Reader ()
import Capability.State ()
import Config
import qualified Control.Monad.Reader as R
import qualified Data.Map as M
import Graphics.X11.Types
import Graphics.X11.Xinerama (XineramaScreenInfo)
import Graphics.X11.Xlib.Extras
import Graphics.X11.Xlib.Types
import qualified SDL
import qualified SDL.Font as Font
import Standard
import TH
import Tiler.ParentChild
import Tiler.TilerTypes

-- |Defines what kind of action triggered the KeyStatus Temp mode.
-- | Defines what kind of action triggered the KeyStatus Temp mode.
data TempType = FromMod | NotMod
deriving Show
deriving (Show)

-- |Defines the states for the keybinding state machine. For more info about
-- how this is used, look in XEvents.
-- | Defines the states for the keybinding state machine. For more info about
-- how this is used, look in XEvents.
data KeyStatus = New KeyStatus Mode KeyCode [Action] | Temp TempType KeyStatus Mode KeyCode [Action] | Default
deriving Show
makeBaseFunctor ''KeyStatus
deriving (Show)

makeBaseFunctor ''KeyStatus

-- |The large record Xest uses in the ReaderT type.
-- | The large record Xest uses in the ReaderT type.
data Ctx = Ctx
{ shouldLog :: IORef (Bool)
, logHistory :: IORef [Text]
, activeMode :: IORef Mode
, screenList :: IORef Screens
, keyStatus :: IORef KeyStatus
, yankBuffer :: IORef [SubTiler]
, oldMouseButtons :: IORef OldMouseButtons
, atomNameCache :: IORef (M.Map Text Atom)
, atomValueCache :: IORef (M.Map Atom [Int])
, focusedWindow :: IORef FocusedCache
, borderLocations :: IORef (M.Map SDL.Window XRect)
, windowLocations :: IORef (M.Map Window XRect)
, windowChildren :: IORef (M.Map Window [ParentChild])
, stackCache :: IORef [Window]
, shouldRedraw :: IORef (Maybe ())
, configuration :: IORef Conf
, activeScreen :: IORef ActiveScreen
, lastTime :: IORef OldTime
, knownDocks :: IORef Docks
, dockState :: IORef DockState
, rootWindow :: Window
, display :: Display
, fontChoice :: Font.Font
, cursor :: XCursor
} deriving (Generic)
{ shouldLog :: IORef (Bool),
logHistory :: IORef [Text],
activeMode :: IORef Mode,
screenList :: IORef Screens,
keyStatus :: IORef KeyStatus,
yankBuffer :: IORef [SubTiler],
oldMouseButtons :: IORef OldMouseButtons,
atomNameCache :: IORef (M.Map Text Atom),
atomValueCache :: IORef (M.Map Atom [Int]),
focusedWindow :: IORef FocusedCache,
borderLocations :: IORef (M.Map SDL.Window XRect),
windowLocations :: IORef (M.Map Window XRect),
windowChildren :: IORef (M.Map Window [ParentChild]),
stackCache :: IORef [Window],
shouldRedraw :: IORef (Maybe ()),
configuration :: IORef Conf,
activeScreen :: IORef ActiveScreen,
lastTime :: IORef OldTime,
knownDocks :: IORef Docks,
dockState :: IORef DockState,
rootWindow :: Window,
display :: Display,
fontChoice :: Font.Font,
cursor :: XCursor
}
deriving (Generic)

-- Some helper type synonyms for creating Input/Output/State instances for
-- items in Ctx.
type FromInput name = Rename name (Field name () (MonadReader M))

type From name = ReaderIORef (FromInput name)

type Logged name s = LoggedSink name s (From name) M

-- Type aliases that should be used elsewhere but for now are just used to get
-- easy to access names when deriving Input/Output/State over these types.
type ShouldRedraw = Maybe ()

type Yanked = [SubTiler]

type LostWindow = Map Window [ParentChild]

-- The Main Monad for Xest.
newtype M a = M { runM :: R.ReaderT Ctx IO a }
newtype M a = M {runM :: R.ReaderT Ctx IO a}
deriving (Functor, Applicative, Monad, MonadIO, R.MonadReader Ctx)
deriving (Input NewBorders) via FakeBorders M
deriving (Input MouseButtons) via FakeMouseButtons M
Expand All @@ -122,49 +127,48 @@ newtype M a = M { runM :: R.ReaderT Ctx IO a }
-- much about the syntax/meta programming that's going on here. The template
-- haskell code expands to roughly the deriving lines up above but with Output
-- and State added to the deriving list.
generateIOS ''M ''LogLines [t| (From "logHistory") |]
generateIOS ''M ''Bool [t| (From "shouldLog") |]
generateIOS ''M ''Mode [t| (Logged "activeMode" Mode) |]
generateIOS ''M ''Screens [t| (Logged "screenList" Screens) |]
generateIOS ''M ''Yanked [t| (Logged "yankBuffer" [SubTiler]) |]
generateIOS ''M ''OldMouseButtons [t| (Logged "oldMouseButtons" OldMouseButtons) |]
generateIOS ''M ''AtomCache [t| (Logged "atomNameCache" (M.Map Text Atom)) |]
generateIOS ''M ''RootPropCache [t| (Logged "atomValueCache" (M.Map Atom [Int])) |]
generateIOS ''M ''WindowStack [t| (Logged "stackCache" [Window]) |]
generateIOS ''M ''FocusedCache [t| (Logged "focusedWindow" FocusedCache) |]
generateIOS ''M ''SDLLocCache [t| (Logged "borderLocations" SDLLocCache) |]
generateIOS ''M ''LocCache [t| (Logged "windowLocations" LocCache) |]
generateIOS ''M ''LostWindow [t| (Logged "windowChildren" LostWindow) |]
generateIOS ''M ''ShouldRedraw [t| (Logged "shouldRedraw" ShouldRedraw) |]
generateIOS ''M ''Conf [t| (Logged "configuration" Conf) |]
generateIOS ''M ''ActiveScreen [t| (Logged "activeScreen" ActiveScreen) |]
generateIOS ''M ''OldTime [t| (Logged "lastTime" OldTime) |]
generateIOS ''M ''Docks [t| (Logged "knownDocks" Docks) |]
generateIOS ''M ''DockState [t| (Logged "dockState" DockState) |]
generateIOS ''M ''KeyStatus [t| (Logged "keyStatus" KeyStatus) |]
generateIOS ''M ''Tiler [t| FakeTiler M |]
generateIOS ''M ''SubTiler [t| Coerce SubTiler M |]
generateIOS ''M ''LogLines [t|(From "logHistory")|]
generateIOS ''M ''Bool [t|(From "shouldLog")|]
generateIOS ''M ''Mode [t|(Logged "activeMode" Mode)|]
generateIOS ''M ''Screens [t|(Logged "screenList" Screens)|]
generateIOS ''M ''Yanked [t|(Logged "yankBuffer" [SubTiler])|]
generateIOS ''M ''OldMouseButtons [t|(Logged "oldMouseButtons" OldMouseButtons)|]
generateIOS ''M ''AtomCache [t|(Logged "atomNameCache" (M.Map Text Atom))|]
generateIOS ''M ''RootPropCache [t|(Logged "atomValueCache" (M.Map Atom [Int]))|]
generateIOS ''M ''WindowStack [t|(Logged "stackCache" [Window])|]
generateIOS ''M ''FocusedCache [t|(Logged "focusedWindow" FocusedCache)|]
generateIOS ''M ''SDLLocCache [t|(Logged "borderLocations" SDLLocCache)|]
generateIOS ''M ''LocCache [t|(Logged "windowLocations" LocCache)|]
generateIOS ''M ''LostWindow [t|(Logged "windowChildren" LostWindow)|]
generateIOS ''M ''ShouldRedraw [t|(Logged "shouldRedraw" ShouldRedraw)|]
generateIOS ''M ''Conf [t|(Logged "configuration" Conf)|]
generateIOS ''M ''ActiveScreen [t|(Logged "activeScreen" ActiveScreen)|]
generateIOS ''M ''OldTime [t|(Logged "lastTime" OldTime)|]
generateIOS ''M ''Docks [t|(Logged "knownDocks" Docks)|]
generateIOS ''M ''DockState [t|(Logged "dockState" DockState)|]
generateIOS ''M ''KeyStatus [t|(Logged "keyStatus" KeyStatus)|]
generateIOS ''M ''Tiler [t|FakeTiler M|]
generateIOS ''M ''SubTiler [t|Coerce SubTiler M|]

deriving via Logger M instance HasSink LogData LogData M


-- Want to do everything in IO? Use this!
doAll
:: IORef [Text]
-> Screens
-> Conf
-> Mode
-> Display
-> Window
-> Font.Font
-> Cursor
-> M a -- The super long Monad which GHC can figure out on its own
-> IO a
doAll ::
IORef [Text] ->
Screens ->
Conf ->
Mode ->
Display ->
Window ->
Font.Font ->
Cursor ->
M a -> -- The super long Monad which GHC can figure out on its own
IO a
doAll ioref t c m d w f cur mon = do
shouldLog <- newIORef False
logHistory <- pure ioref
activeMode <- newIORef m
yankBuffer <- newIORef []
yankBuffer <- newIORef []
oldMouseButtons <- newIORef $ OMB None
atomNameCache <- newIORef M.empty
atomValueCache <- newIORef M.empty
Expand All @@ -185,4 +189,4 @@ doAll ioref t c m d w f cur mon = do
display <- pure d
fontChoice <- pure f
cursor <- pure $ XCursor cur
R.runReaderT (runM mon) $ Ctx {..}
R.runReaderT (runM mon) $ Ctx {..}
22 changes: 10 additions & 12 deletions src/Base/Helpers.hs
@@ -1,28 +1,26 @@
module Base.Helpers where

import Standard
import Data.Kind
import Graphics.X11.Types

import Data.Kind
import Graphics.X11.Types
import Standard

type family TypeMap (f :: a -> a -> b) (xs :: [a]) where
TypeMap _ '[] = '[]
TypeMap f (x ': xs) = f x x ': TypeMap f xs
TypeMap _ '[] = '[]
TypeMap f (x ': xs) = f x x ': TypeMap f xs

type family (++) (a :: [t]) (b :: [t]) where
(++) '[] b = b
(++) (a ': as) b = a ': (as ++ b)


-- |A type level function which takes a list of Types and turns them into
-- inputs.
-- | A type level function which takes a list of Types and turns them into
-- inputs.
type Inputs (a :: [Type]) = TypeMap HasSource a


-- |Same as above but for State.
-- | Same as above but for State.
type States (a :: [Type]) = TypeMap HasState a

newtype OldTime = OldTime Time
deriving (Show)

-- |Just makes it more clear when you say Input RootWindow.
-- | Just makes it more clear when you say Input RootWindow.
type RootWindow = Window

0 comments on commit 819a8a5

Please sign in to comment.