From 9fdf0fc355f271e7959c148276ce4fb8d721f6c4 Mon Sep 17 00:00:00 2001 From: andys8 Date: Sun, 10 Sep 2023 13:26:15 +0200 Subject: [PATCH] Update support of brick 1.10 and ghc 9.4.6 --- .github/workflows/ci.yml | 4 +-- .github/workflows/release.yml | 2 +- app/GitBrunch.hs | 50 ++++++++++++++++++++--------------- git-brunch.cabal | 4 +-- package.yaml | 2 +- stack.yaml | 2 +- stack.yaml.lock | 8 +++--- 7 files changed, 40 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b108a5f..c45fd08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c005b47..aa2b2dc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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' diff --git a/app/GitBrunch.hs b/app/GitBrunch.hs index a36bcfa..3c11a0d 100644 --- a/app/GitBrunch.hs +++ b/app/GitBrunch.hs @@ -34,6 +34,8 @@ data Name = Local | Remote | Filter + | DialogConfirm + | DialogCancel deriving (Ord, Eq, Show) data RemoteName @@ -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 } @@ -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 @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) [] @@ -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 diff --git a/git-brunch.cabal b/git-brunch.cabal index d35f95c..d904f9d 100644 --- a/git-brunch.cabal +++ b/git-brunch.cabal @@ -44,7 +44,7 @@ executable git-brunch StrictData build-depends: base >=4.7 && <5 - , brick <1.11 + , brick , extra , hspec , microlens @@ -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 diff --git a/package.yaml b/package.yaml index 7b392ee..0dd088a 100644 --- a/package.yaml +++ b/package.yaml @@ -16,7 +16,7 @@ description: Please see the README on GitHub at = 4.7 && < 5 - - brick < 1.11 + - brick - extra - microlens - microlens-mtl diff --git a/stack.yaml b/stack.yaml index 696136d..547265b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,3 @@ -resolver: lts-20.26 +resolver: lts-21.11 packages: - . diff --git a/stack.yaml.lock b/stack.yaml.lock index ea5a850..30cbd43 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -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