Skip to content

Commit

Permalink
Update support of brick 1.10 and ghc 9.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
andys8 committed Sep 10, 2023
1 parent 2e75686 commit 9fdf0fc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
${{ runner.os }}-stack-
- uses: haskell/actions/setup@v2
with:
ghc-version: "9.2.8"
ghc-version: "9.4.6"
enable-stack: true
stack-version: "latest"
- name: Build
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
restore-keys: ${{ runner.os }}-cabal-
- uses: haskell/actions/setup@v2
with:
ghc-version: "9.2.8"
ghc-version: "9.4.6"
enable-stack: false
cabal-version: "latest"
- run: cabal update
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
${{ runner.os }}-stack-
- uses: haskell/actions/setup@v2
with:
ghc-version: "9.2.8"
ghc-version: "9.4.6"
enable-stack: true
stack-version: "latest"
- if: matrix.os == 'ubuntu-latest'
Expand Down
50 changes: 29 additions & 21 deletions app/GitBrunch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ data Name
= Local
| Remote
| Filter
| DialogConfirm
| DialogCancel
deriving (Ord, Eq, Show)

data RemoteName
Expand All @@ -58,7 +60,7 @@ data State = State
, _branches :: [Branch]
, _localBranches :: L.List Name Branch
, _remoteBranches :: L.List Name Branch
, _dialog :: Maybe (D.Dialog DialogOption)
, _dialog :: Maybe (D.Dialog DialogOption Name)
, _filter :: E.Editor Text Name
, _isEditingFilter :: Bool
}
Expand All @@ -75,8 +77,8 @@ main = do
state <- M.defaultMain app $ syncBranchLists emptyState{_branches = branches}
let execGit = gitFunction (_gitCommand state)
exitCode <- maybe noBranchErr execGit (selectedBranch state)
when (exitCode /= ExitSuccess) $
die ("Failed to " ++ show (_gitCommand state) ++ ".")
when (exitCode /= ExitSuccess)
$ die ("Failed to " ++ show (_gitCommand state) ++ ".")
where
gitFailed :: SomeException -> IO a
gitFailed _ = exitFailure
Expand Down Expand Up @@ -133,8 +135,8 @@ drawApp state =
, C.hCenter $ toBranchList RRemote remoteBranchesL
]
instructions =
maxWidth 100 $
hBox
maxWidth 100
$ hBox
[ drawInstruction "Enter" "checkout"
, drawInstruction "/" "filter"
, drawInstruction "F" "fetch"
Expand All @@ -150,7 +152,7 @@ drawFilter state =
editor = E.renderEditor (txt . T.unlines) True (state ^. filterL)
label = str " Filter: "

drawDialog :: State -> Widget n
drawDialog :: State -> Widget Name
drawDialog state = case _dialog state of
Nothing -> emptyWidget
Just dialog -> D.renderDialog dialog $ C.hCenter $ padAll 1 content
Expand All @@ -166,9 +168,9 @@ drawDialog state = case _dialog state of

drawBranchList :: Bool -> L.List Name Branch -> Widget Name
drawBranchList hasFocus list =
withBorderStyle BS.unicodeBold $
B.borderWithLabel (drawTitle list) $
L.renderList drawListElement hasFocus list
withBorderStyle BS.unicodeBold
$ B.borderWithLabel (drawTitle list)
$ L.renderList drawListElement hasFocus list
where
attr = withAttr $ if hasFocus then attrTitleFocus else attrTitle
drawTitle = attr . str . map toUpper . show . L.listName
Expand Down Expand Up @@ -277,9 +279,9 @@ appHandleEventDialog e =
EvKey KEnter [] -> do
dialog <- gets _dialog
case D.dialogSelection =<< dialog of
Just (Confirm cmd) -> confirmDialog cmd
Just Cancel -> cancelDialog
Nothing -> pure ()
Just (DialogConfirm, Confirm cmd) -> confirmDialog cmd
Just (DialogCancel, Cancel) -> cancelDialog
_ -> pure ()
EvKey KEsc [] -> cancelDialog
EvKey (KChar 'q') [] -> cancelDialog
ev -> zoom (dialogL . _Just) $ D.handleDialogEvent ev
Expand All @@ -305,8 +307,8 @@ listOffsetDiff :: RemoteName -> EventM Name State Int
listOffsetDiff target = do
offLocal <- getOffset Local
offRemote <- getOffset Remote
pure $
if target == RLocal
pure
$ if target == RLocal
then offRemote - offLocal
else offLocal - offRemote
where
Expand All @@ -328,9 +330,12 @@ updateBranches branches =
syncBranchLists :: State -> State
syncBranchLists state =
state
& localBranchesL .~ mkList Local local
& remoteBranchesL .~ mkList Remote remote
& focusL %~ toggleFocus (local, remote)
& localBranchesL
.~ mkList Local local
& remoteBranchesL
.~ mkList Remote remote
& focusL
%~ toggleFocus (local, remote)
where
mkList name xs = L.list name (Vec.fromList xs) rowHeight
filterText = T.toLower $ T.unwords $ E.getEditContents $ _filter state
Expand All @@ -347,13 +352,16 @@ selectedBranch :: State -> Maybe Branch
selectedBranch state =
snd <$> L.listSelectedElement (state ^. focussedBranchesL)

createDialog :: GitCommand -> D.Dialog DialogOption
createDialog cmd = D.dialog (Just title) (Just (0, choices)) 80
createDialog :: GitCommand -> D.Dialog DialogOption Name
createDialog cmd = D.dialog (Just $ str title) (Just (DialogConfirm, choices)) 80
where
choices = [(btnText $ show cmd, Confirm cmd), ("Cancel", Cancel)]
title = map toUpper $ show cmd
btnText (x : xs) = toUpper x : xs
btnText x = x
choices =
[ (btnText $ show cmd, DialogConfirm, Confirm cmd)
, ("Cancel", DialogCancel, Cancel)
]

mapKey :: (Char -> Key) -> Event -> Event
mapKey f (EvKey (KChar k) []) = EvKey (f k) []
Expand Down Expand Up @@ -402,7 +410,7 @@ branchesL = lens _branches (\s f -> s{_branches = f})
isEditingFilterL :: Lens' State Bool
isEditingFilterL = lens _isEditingFilter (\s f -> s{_isEditingFilter = f})

dialogL :: Lens' State (Maybe (D.Dialog DialogOption))
dialogL :: Lens' State (Maybe (D.Dialog DialogOption Name))
dialogL = lens _dialog (\s v -> s{_dialog = v})

gitCommandL :: Lens' State GitCommand
Expand Down
4 changes: 2 additions & 2 deletions git-brunch.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ executable git-brunch
StrictData
build-depends:
base >=4.7 && <5
, brick <1.11
, brick
, extra
, hspec
, microlens
Expand Down Expand Up @@ -79,7 +79,7 @@ test-suite git-brunch-test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, brick <1.11
, brick
, extra
, hspec
, microlens
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: Please see the README on GitHub at <https://github.com/andys8/git-b

dependencies:
- base >= 4.7 && < 5
- brick < 1.11
- brick
- extra
- microlens
- microlens-mtl
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resolver: lts-20.26
resolver: lts-21.11
packages:
- .
8 changes: 4 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
packages: []
snapshots:
- completed:
sha256: 5a59b2a405b3aba3c00188453be172b85893cab8ebc352b1ef58b0eae5d248a2
size: 650475
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/26.yaml
original: lts-20.26
sha256: 64d66303f927e87ffe6b8ccf736229bf608731e80d7afdf62bdd63c59f857740
size: 640037
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/11.yaml
original: lts-21.11

0 comments on commit 9fdf0fc

Please sign in to comment.