-- Copyright (C) 2002-2003 David Roundy
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2, or (at your option)
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; see the file COPYING.  If not, write to
-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-- Boston, MA 02110-1301, USA.

module Darcs.UI.SelectChanges
    ( -- * Working with changes
      WhichChanges(..)
    , viewChanges
    , withSelectedPatchFromRepo
    , runSelection
    , selectionContextPrim
    , selectionContextGeneric
    , selectionContext
    , PatchSelectionContext(allowSkipAll)
    , printSummary
    -- * Interactive selection utils
    , PatchSelectionOptions(..)
    , InteractiveSelectionM
    , InteractiveSelectionContext(..)
    -- ** Navigating the patchset
    , currentPatch
    , skipMundane
    , skipOne
    , backOne
    , backAll
    , showCur
    -- ** Decisions
    , decide
    , decideWholeFile
    -- ** Prompts and queries
    , isSingleFile
    , currentFile
    , promptUser
    , prompt
    , KeyPress(..)
    , keysFor
    , helpFor
    , askAboutDepends
    ) where

import Prelude ()
import Darcs.Prelude

import Control.Monad ( liftM, unless, when, (>=>) )
import Control.Monad.Identity ( Identity (..) )
import Control.Monad.Reader
    ( ReaderT
    , asks
    , runReaderT
    )
import Control.Monad.State
    ( StateT, execStateT, gets
    , modify, runStateT, state
    )
import Control.Monad.Trans ( liftIO )
import Data.List ( intercalate, union )
import Data.Maybe ( isJust, catMaybes )
import System.Exit ( exitSuccess )

import Darcs.Patch
    ( IsRepoType, RepoPatch, PrimOf
    , commuteFLorComplain, invert
    , listTouchedFiles, fromPrims
    )
import qualified Darcs.Patch ( thing, things, summary )
import Darcs.Patch.Apply ( Apply, ApplyState )
import Darcs.Patch.Choices
    ( PatchChoices, Slot (..), LabelledPatch
    , mkPatchChoices, forceFirsts
    , forceFirst, forceLast, forceMatchingFirst
    , forceMatchingLast, getChoices
    , makeEverythingLater, makeEverythingSooner
    , forceMiddle, patchChoices
    , patchSlot
    , refineChoices, selectAllMiddles
    , separateFirstFromMiddleLast
    , substitute, label, unLabel
    , labelPatches
    )
import Darcs.Patch.Commute ( Commute )
import Darcs.Patch.Info ( PatchInfo )
import Darcs.Patch.Inspect ( PatchInspect )
import Darcs.Patch.Invert ( Invert )
import Darcs.Patch.Match ( haveNonrangeMatch, matchAPatch )
import Darcs.Patch.Named.Wrapped ( anonymous )
import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, n2pia )
import Darcs.Patch.Set ( PatchSet(..), patchSet2RL )
import Darcs.Patch.Show ( ShowPatch, ShowContextPatch )
import Darcs.Patch.Split ( Splitter(applySplitter,canonizeSplit) )
import Darcs.Patch.TouchesFiles ( selectNotTouching, deselectNotTouching )
import Darcs.Patch.Type ( PatchType (..) )
import Darcs.Patch.Witnesses.Eq ( unsafeCompare )
import Darcs.Patch.Witnesses.Ordered
    ( (:>) (..), (:||:) (..), FL (..)
    , RL (..), filterFL, lengthFL, mapFL
    , mapFL_FL, spanFL, spanFL_M
    , (+>+), (+<<+), (+>>+)
    )
import Darcs.Patch.Witnesses.Sealed
    ( FlippedSeal (..), Sealed2 (..)
    , flipSeal, seal2, unseal2
    )
import Darcs.Patch.Witnesses.WZipper
    ( FZipper (..), left, right
    , rightmost, toEnd, toStart
    )
import Darcs.Repository ( Repository, repoLocation, readRepo, readTentativeRepo )
import Darcs.UI.External ( editText )
import Darcs.UI.Options.All
    ( Verbosity(..), Summary(..)
    , WithContext(..), SelectDeps(..), MatchFlag )
import Darcs.UI.PrintPatch
    ( printFriendly, printPatch
    , printPatchPager, showFriendly )
import Darcs.Util.English ( Noun (..), englishNum, capitalize )
import Darcs.Util.Printer ( prefix, putDocLn, putDocLnWith, greenText )
import Darcs.Util.Printer.Color ( fancyPrinters )
import Darcs.Util.Prompt ( PromptConfig (..), askUser, promptChar )
import Darcs.Util.Tree ( Tree )


-- | When asking about patches, we either ask about them in
-- oldest-first or newest first (with respect to the current ordering
-- of the repository), and we either want an initial segment or a
-- final segment of the poset of patches.
--
-- 'First': ask for an initial
-- segment, first patches first (default for all pull-like commands)
--
-- 'FirstReversed': ask for an initial segment, last patches first
-- (used to ask about dependencies in record, and for pull-like
-- commands with the @--reverse@ flag).
--
-- 'LastReversed': ask for a final segment, last patches first. (default
-- for unpull-like commands, except for selecting *primitive* patches in
-- rollback)
--
-- 'Last': ask for a final segment, first patches first. (used for selecting
-- primitive patches in rollback, and for unpull-like commands with the
-- @--reverse@ flag
--
-- IOW: First = initial segment
--      Last = final segment
--      Reversed = start with the newest patch instead of oldest
-- As usual, terminology is not, ahem, very intuitive.
data WhichChanges = Last | LastReversed | First | FirstReversed deriving (WhichChanges -> WhichChanges -> Bool
(WhichChanges -> WhichChanges -> Bool)
-> (WhichChanges -> WhichChanges -> Bool) -> Eq WhichChanges
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WhichChanges -> WhichChanges -> Bool
$c/= :: WhichChanges -> WhichChanges -> Bool
== :: WhichChanges -> WhichChanges -> Bool
$c== :: WhichChanges -> WhichChanges -> Bool
Eq, Int -> WhichChanges -> ShowS
[WhichChanges] -> ShowS
WhichChanges -> String
(Int -> WhichChanges -> ShowS)
-> (WhichChanges -> String)
-> ([WhichChanges] -> ShowS)
-> Show WhichChanges
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WhichChanges] -> ShowS
$cshowList :: [WhichChanges] -> ShowS
show :: WhichChanges -> String
$cshow :: WhichChanges -> String
showsPrec :: Int -> WhichChanges -> ShowS
$cshowsPrec :: Int -> WhichChanges -> ShowS
Show)

-- | A 'WhichChanges' is 'backward' if the segment of patches we ask for
-- is at the opposite end of where we start to present them.
backward :: WhichChanges -> Bool
backward :: WhichChanges -> Bool
backward w :: WhichChanges
w = WhichChanges
w WhichChanges -> WhichChanges -> Bool
forall a. Eq a => a -> a -> Bool
== WhichChanges
Last Bool -> Bool -> Bool
|| WhichChanges
w WhichChanges -> WhichChanges -> Bool
forall a. Eq a => a -> a -> Bool
== WhichChanges
FirstReversed

-- | A 'WhichChanges' is reversed if the order in which patches are presented
-- is latest (or newest) patch first.
reversed :: WhichChanges -> Bool
reversed :: WhichChanges -> Bool
reversed w :: WhichChanges
w = WhichChanges
w WhichChanges -> WhichChanges -> Bool
forall a. Eq a => a -> a -> Bool
== WhichChanges
LastReversed Bool -> Bool -> Bool
|| WhichChanges
w WhichChanges -> WhichChanges -> Bool
forall a. Eq a => a -> a -> Bool
== WhichChanges
FirstReversed

-- | The type of the function we use to filter patches when @--match@ is
-- given.
data MatchCriterion p = MatchCriterion
   { MatchCriterion p -> Bool
mcHasNonrange :: Bool
   , MatchCriterion p
-> forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool
mcFunction :: forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool
   }

data PatchSelectionOptions = PatchSelectionOptions
  { PatchSelectionOptions -> Verbosity
verbosity :: Verbosity
  , PatchSelectionOptions -> [MatchFlag]
matchFlags :: [MatchFlag]
  , PatchSelectionOptions -> Bool
interactive :: Bool
  , PatchSelectionOptions -> SelectDeps
selectDeps :: SelectDeps
  , PatchSelectionOptions -> Summary
summary :: Summary
  , PatchSelectionOptions -> WithContext
withContext :: WithContext
  }

-- | A @PatchSelectionContext@ contains all the static settings for selecting
-- patches. See "PatchSelectionM"
data PatchSelectionContext p = PSC { PatchSelectionContext p -> PatchSelectionOptions
opts :: PatchSelectionOptions
                                   , PatchSelectionContext p -> Maybe (Splitter p)
splitter :: Maybe (Splitter p)
                                   , PatchSelectionContext p -> Maybe [String]
files :: Maybe [FilePath]
                                   , PatchSelectionContext p -> MatchCriterion p
matchCriterion :: MatchCriterion p
                                   , PatchSelectionContext p -> String
jobname :: String
                                   , PatchSelectionContext p -> Bool
allowSkipAll :: Bool
                                   , PatchSelectionContext p -> Maybe (Tree IO)
pristine :: Maybe (Tree IO)
                                   , PatchSelectionContext p -> WhichChanges
whichChanges :: WhichChanges
                                   }

-- | A 'PatchSelectionContext' for selecting 'Prim' patches.
selectionContextPrim :: WhichChanges
                     -> String
                     -> PatchSelectionOptions
                     -> Maybe (Splitter prim)
                     -> Maybe [FilePath]
                     -> Maybe (Tree IO)
                     -> PatchSelectionContext prim
selectionContextPrim :: WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter prim)
-> Maybe [String]
-> Maybe (Tree IO)
-> PatchSelectionContext prim
selectionContextPrim whch :: WhichChanges
whch jn :: String
jn o :: PatchSelectionOptions
o spl :: Maybe (Splitter prim)
spl fs :: Maybe [String]
fs p :: Maybe (Tree IO)
p =
 PSC :: forall (p :: * -> * -> *).
PatchSelectionOptions
-> Maybe (Splitter p)
-> Maybe [String]
-> MatchCriterion p
-> String
-> Bool
-> Maybe (Tree IO)
-> WhichChanges
-> PatchSelectionContext p
PSC { opts :: PatchSelectionOptions
opts = PatchSelectionOptions
o
     , splitter :: Maybe (Splitter prim)
splitter = Maybe (Splitter prim)
spl
     , files :: Maybe [String]
files = Maybe [String]
fs
     , matchCriterion :: MatchCriterion prim
matchCriterion = MatchCriterion prim
forall (p :: * -> * -> *). MatchCriterion p
triv
     , jobname :: String
jobname = String
jn
     , allowSkipAll :: Bool
allowSkipAll = Bool
True
     , pristine :: Maybe (Tree IO)
pristine = Maybe (Tree IO)
p
     , whichChanges :: WhichChanges
whichChanges = WhichChanges
whch
     }

-- | A 'PatchSelectionContext' for selecting full patches ('PatchInfoAnd' patches)
selectionContext :: (IsRepoType rt, RepoPatch p)
                 => WhichChanges -> String -> PatchSelectionOptions
                 -> Maybe (Splitter (PatchInfoAnd rt p))
                 -> Maybe [FilePath]
                 -> PatchSelectionContext (PatchInfoAnd rt p)
selectionContext :: WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PatchInfoAnd rt p))
-> Maybe [String]
-> PatchSelectionContext (PatchInfoAnd rt p)
selectionContext whch :: WhichChanges
whch jn :: String
jn o :: PatchSelectionOptions
o spl :: Maybe (Splitter (PatchInfoAnd rt p))
spl fs :: Maybe [String]
fs =
 PSC :: forall (p :: * -> * -> *).
PatchSelectionOptions
-> Maybe (Splitter p)
-> Maybe [String]
-> MatchCriterion p
-> String
-> Bool
-> Maybe (Tree IO)
-> WhichChanges
-> PatchSelectionContext p
PSC { opts :: PatchSelectionOptions
opts = PatchSelectionOptions
o
     , splitter :: Maybe (Splitter (PatchInfoAnd rt p))
splitter = Maybe (Splitter (PatchInfoAnd rt p))
spl
     , files :: Maybe [String]
files = Maybe [String]
fs
     , matchCriterion :: MatchCriterion (PatchInfoAnd rt p)
matchCriterion = (forall wX wY.
 PatchInfoAnd rt p wX wY -> Sealed2 (PatchInfoAnd rt p))
-> [MatchFlag] -> MatchCriterion (PatchInfoAnd rt p)
forall (rt :: RepoType) (p :: * -> * -> *) (q :: * -> * -> *).
(IsRepoType rt, RepoPatch p, Invert q) =>
(forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p))
-> [MatchFlag] -> MatchCriterion q
iswanted forall wX wY.
PatchInfoAnd rt p wX wY -> Sealed2 (PatchInfoAnd rt p)
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
seal2 (PatchSelectionOptions -> [MatchFlag]
matchFlags PatchSelectionOptions
o)
     , jobname :: String
jobname = String
jn
     , allowSkipAll :: Bool
allowSkipAll = Bool
True
     , pristine :: Maybe (Tree IO)
pristine = Maybe (Tree IO)
forall a. Maybe a
Nothing
     , whichChanges :: WhichChanges
whichChanges = WhichChanges
whch
     }

-- | A generic 'PatchSelectionContext'.
selectionContextGeneric :: (IsRepoType rt, RepoPatch p, Invert q)
                        => (forall wX wY . q wX wY -> Sealed2 (PatchInfoAnd rt p))
                        -> WhichChanges
                        -> String
                        -> PatchSelectionOptions
                        -> Maybe [FilePath]
                        -> PatchSelectionContext q
selectionContextGeneric :: (forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p))
-> WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe [String]
-> PatchSelectionContext q
selectionContextGeneric extract :: forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p)
extract whch :: WhichChanges
whch jn :: String
jn o :: PatchSelectionOptions
o fs :: Maybe [String]
fs =
 PSC :: forall (p :: * -> * -> *).
PatchSelectionOptions
-> Maybe (Splitter p)
-> Maybe [String]
-> MatchCriterion p
-> String
-> Bool
-> Maybe (Tree IO)
-> WhichChanges
-> PatchSelectionContext p
PSC { opts :: PatchSelectionOptions
opts = PatchSelectionOptions
o
     , splitter :: Maybe (Splitter q)
splitter = Maybe (Splitter q)
forall a. Maybe a
Nothing
     , files :: Maybe [String]
files = Maybe [String]
fs
     , matchCriterion :: MatchCriterion q
matchCriterion = (forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p))
-> [MatchFlag] -> MatchCriterion q
forall (rt :: RepoType) (p :: * -> * -> *) (q :: * -> * -> *).
(IsRepoType rt, RepoPatch p, Invert q) =>
(forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p))
-> [MatchFlag] -> MatchCriterion q
iswanted forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p)
extract (PatchSelectionOptions -> [MatchFlag]
matchFlags PatchSelectionOptions
o)
     , jobname :: String
jobname = String
jn
     , allowSkipAll :: Bool
allowSkipAll = Bool
True
     , pristine :: Maybe (Tree IO)
pristine = Maybe (Tree IO)
forall a. Maybe a
Nothing
     , whichChanges :: WhichChanges
whichChanges = WhichChanges
whch
     }

-- | The dynamic parameters for interactive selection of patches.
data InteractiveSelectionContext p wX wY =
 ISC { InteractiveSelectionContext p wX wY -> Int
total :: Int                           -- ^ total number of patches
     , InteractiveSelectionContext p wX wY -> Int
current :: Int                         -- ^ number of already-seen patches
     , InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps :: FZipper (LabelledPatch p) wX wY -- ^ the patches we offer
     , InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices :: PatchChoices p wX wY        -- ^ the user's choices
     }

type PatchSelectionM p a = ReaderT (PatchSelectionContext p) a

type InteractiveSelectionM p wX wY a =
    StateT (InteractiveSelectionContext p wX wY)
           (PatchSelectionM p IO) a

-- Common match criteria

-- | For commands without @--match@, 'triv' matches all patches
triv :: MatchCriterion p
triv :: MatchCriterion p
triv = MatchCriterion :: forall (p :: * -> * -> *).
Bool
-> (forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool)
-> MatchCriterion p
MatchCriterion { mcHasNonrange :: Bool
mcHasNonrange = Bool
False, mcFunction :: forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool
mcFunction = \ _ _ -> Bool
True }

-- | 'iswanted' selects patches according to the given match flags
iswanted :: forall rt p q
          . (IsRepoType rt, RepoPatch p, Invert q)
         => (forall wX wY . q wX wY -> Sealed2 (PatchInfoAnd rt p))
         -> [MatchFlag]
         -> MatchCriterion q
iswanted :: (forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p))
-> [MatchFlag] -> MatchCriterion q
iswanted extract :: forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p)
extract mflags :: [MatchFlag]
mflags = MatchCriterion :: forall (p :: * -> * -> *).
Bool
-> (forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool)
-> MatchCriterion p
MatchCriterion
    { mcHasNonrange :: Bool
mcHasNonrange = PatchType rt p -> [MatchFlag] -> Bool
forall (rt :: RepoType) (p :: * -> * -> *).
(IsRepoType rt, Matchable p) =>
PatchType rt p -> [MatchFlag] -> Bool
haveNonrangeMatch (PatchType rt p
forall (rt :: RepoType) (p :: * -> * -> *). PatchType rt p
PatchType :: PatchType rt p) [MatchFlag]
mflags
    , mcFunction :: forall wA wB. WhichChanges -> LabelledPatch q wA wB -> Bool
mcFunction = forall wA wB. WhichChanges -> LabelledPatch q wA wB -> Bool
isWantedMcFunction
    }
  where
    isWantedMcFunction :: WhichChanges -> LabelledPatch q wY wX -> Bool
isWantedMcFunction w :: WhichChanges
w = (forall wX wY. PatchInfoAnd rt p wX wY -> Bool)
-> Sealed2 (PatchInfoAnd rt p) -> Bool
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 ([MatchFlag] -> PatchInfoAnd rt p wX wY -> Bool
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
(IsRepoType rt, Matchable p) =>
[MatchFlag] -> PatchInfoAnd rt p wX wY -> Bool
matchAPatch [MatchFlag]
mflags) (Sealed2 (PatchInfoAnd rt p) -> Bool)
-> (LabelledPatch q wY wX -> Sealed2 (PatchInfoAnd rt p))
-> LabelledPatch q wY wX
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WhichChanges -> q wY wX -> Sealed2 (PatchInfoAnd rt p)
forall wY wX.
WhichChanges -> q wY wX -> Sealed2 (PatchInfoAnd rt p)
extract_reverse WhichChanges
w (q wY wX -> Sealed2 (PatchInfoAnd rt p))
-> (LabelledPatch q wY wX -> q wY wX)
-> LabelledPatch q wY wX
-> Sealed2 (PatchInfoAnd rt p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LabelledPatch q wY wX -> q wY wX
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel
    -- TODO inverting should not be necessary here, at least I would expect
    --
    -- prop> matchAPatch (invert x) == matchAPatch x
    extract_reverse :: WhichChanges -> q wY wX -> Sealed2 (PatchInfoAnd rt p)
extract_reverse w :: WhichChanges
w = if WhichChanges -> Bool
reversed WhichChanges
w then q wX wY -> Sealed2 (PatchInfoAnd rt p)
forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p)
extract (q wX wY -> Sealed2 (PatchInfoAnd rt p))
-> (q wY wX -> q wX wY) -> q wY wX -> Sealed2 (PatchInfoAnd rt p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. q wY wX -> q wX wY
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert else q wY wX -> Sealed2 (PatchInfoAnd rt p)
forall wX wY. q wX wY -> Sealed2 (PatchInfoAnd rt p)
extract

-- | Run a 'PatchSelection' action in the given 'PatchSelectionContext'.
runSelection :: forall p wX wY . ( Invert p, Commute p, Apply p, PatchInspect p, ShowPatch p
                                 , ShowContextPatch p, ApplyState p ~ Tree )
             => FL p wX wY
             -> PatchSelectionContext p
             -> IO ((FL p :> FL p) wX wY)
runSelection :: FL p wX wY
-> PatchSelectionContext p -> IO ((:>) (FL p) (FL p) wX wY)
runSelection ps :: FL p wX wY
ps psc :: PatchSelectionContext p
psc = ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY)
-> PatchSelectionContext p -> IO ((:>) (FL p) (FL p) wX wY)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (FL p wX wY
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY)
forall wY wX.
FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
selection FL p wX wY
ps) PatchSelectionContext p
psc where
  selection :: FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
selection
    | WhichChanges -> Bool
reversed WhichChanges
whch = ((:>) (FL p) (FL p) wX wY -> (:>) (FL p) (FL p) wY wX)
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY)
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (:>) (FL p) (FL p) wX wY -> (:>) (FL p) (FL p) wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert (ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY)
 -> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX))
-> (FL p wY wX
    -> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY))
-> FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FL p wX wY
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY)
forall wY wX.
FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
doit (FL p wX wY
 -> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY))
-> (FL p wY wX -> FL p wX wY)
-> FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wX wY)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FL p wY wX -> FL p wX wY
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert
    | Bool
otherwise = FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
forall wY wX.
FL p wY wX
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wY wX)
doit
  -- efficiency note: we should first filterUnwanted to apply matchers,
  -- as this often requires to read only metadata; then filterNotTouching
  -- applies path restrictions which needs to read patch contents
  doit :: FL p wA wB
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wA wB)
doit =
    (PatchChoices p wA wB -> (:>) (FL p) (FL p) wA wB)
-> ReaderT (PatchSelectionContext p) IO (PatchChoices p wA wB)
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wA wB)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((:>) (FL p) (FL p) wA wB -> (:>) (FL p) (FL p) wA wB
forall wA wB. (:>) (FL p) (FL p) wA wB -> (:>) (FL p) (FL p) wA wB
canonizeAfterSplitter ((:>) (FL p) (FL p) wA wB -> (:>) (FL p) (FL p) wA wB)
-> (PatchChoices p wA wB -> (:>) (FL p) (FL p) wA wB)
-> PatchChoices p wA wB
-> (:>) (FL p) (FL p) wA wB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wA wB -> (:>) (FL p) (FL p) wA wB
forall wA wB. PatchChoices p wA wB -> (:>) (FL p) (FL p) wA wB
selectedPatches) (ReaderT (PatchSelectionContext p) IO (PatchChoices p wA wB)
 -> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wA wB))
-> (FL p wA wB
    -> ReaderT (PatchSelectionContext p) IO (PatchChoices p wA wB))
-> FL p wA wB
-> ReaderT (PatchSelectionContext p) IO ((:>) (FL p) (FL p) wA wB)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    PatchChoices p wA wB
-> ReaderT (PatchSelectionContext p) IO (PatchChoices p wA wB)
forall wA wB.
PatchChoices p wA wB -> PatchSelectionM p IO (PatchChoices p wA wB)
selectChanges (PatchChoices p wA wB
 -> ReaderT (PatchSelectionContext p) IO (PatchChoices p wA wB))
-> (FL p wA wB -> PatchChoices p wA wB)
-> FL p wA wB
-> ReaderT (PatchSelectionContext p) IO (PatchChoices p wA wB)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wA wB -> PatchChoices p wA wB
forall wX wY. PatchChoices p wX wY -> PatchChoices p wX wY
filterNotTouching (PatchChoices p wA wB -> PatchChoices p wA wB)
-> (FL p wA wB -> PatchChoices p wA wB)
-> FL p wA wB
-> PatchChoices p wA wB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wA wB -> PatchChoices p wA wB
forall wX wY. PatchChoices p wX wY -> PatchChoices p wX wY
filterUnwanted (PatchChoices p wA wB -> PatchChoices p wA wB)
-> (FL p wA wB -> PatchChoices p wA wB)
-> FL p wA wB
-> PatchChoices p wA wB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FL p wA wB -> PatchChoices p wA wB
forall (p :: * -> * -> *) wX wY. FL p wX wY -> PatchChoices p wX wY
patchChoices

  -- configuration
  whch :: WhichChanges
whch = PatchSelectionContext p -> WhichChanges
forall (p :: * -> * -> *). PatchSelectionContext p -> WhichChanges
whichChanges PatchSelectionContext p
psc
  fs :: Maybe [String]
fs = PatchSelectionContext p -> Maybe [String]
forall (p :: * -> * -> *).
PatchSelectionContext p -> Maybe [String]
files PatchSelectionContext p
psc
  os :: PatchSelectionOptions
os = PatchSelectionContext p -> PatchSelectionOptions
forall (p :: * -> * -> *).
PatchSelectionContext p -> PatchSelectionOptions
opts PatchSelectionContext p
psc
  crit :: MatchCriterion p
crit = PatchSelectionContext p -> MatchCriterion p
forall (p :: * -> * -> *).
PatchSelectionContext p -> MatchCriterion p
matchCriterion PatchSelectionContext p
psc
  mspl :: Maybe (Splitter p)
mspl = PatchSelectionContext p -> Maybe (Splitter p)
forall (p :: * -> * -> *).
PatchSelectionContext p -> Maybe (Splitter p)
splitter PatchSelectionContext p
psc

  -- after selecting with a splitter, the results may not be canonical
  canonizeAfterSplitter :: (FL p :> FL p) wA wB -> (FL p :> FL p) wA wB
  canonizeAfterSplitter :: (:>) (FL p) (FL p) wA wB -> (:>) (FL p) (FL p) wA wB
canonizeAfterSplitter (x :: FL p wA wZ
x :> y :: FL p wZ wB
y) =
    let canonizeIfNeeded :: FL p wX wY -> FL p wX wY
canonizeIfNeeded = (FL p wX wY -> FL p wX wY)
-> (Splitter p -> FL p wX wY -> FL p wX wY)
-> Maybe (Splitter p)
-> FL p wX wY
-> FL p wX wY
forall b a. b -> (a -> b) -> Maybe a -> b
maybe FL p wX wY -> FL p wX wY
forall a. a -> a
id Splitter p -> FL p wX wY -> FL p wX wY
forall (p :: * -> * -> *).
Splitter p -> forall wX wY. FL p wX wY -> FL p wX wY
canonizeSplit Maybe (Splitter p)
mspl
    in FL p wA wZ -> FL p wA wZ
forall wX wY. FL p wX wY -> FL p wX wY
canonizeIfNeeded FL p wA wZ
x FL p wA wZ -> FL p wZ wB -> (:>) (FL p) (FL p) wA wB
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL p wZ wB -> FL p wZ wB
forall wX wY. FL p wX wY -> FL p wX wY
canonizeIfNeeded FL p wZ wB
y

  -- retrieve the results of patch selection
  selectedPatches :: PatchChoices p wA wB -> (FL p :> FL p) wA wB
  selectedPatches :: PatchChoices p wA wB -> (:>) (FL p) (FL p) wA wB
selectedPatches pc :: PatchChoices p wA wB
pc
    | WhichChanges -> Bool
backward WhichChanges
whch =
        case PatchChoices p wA wB
-> (:>)
     (FL (LabelledPatch p))
     (FL (LabelledPatch p) :> FL (LabelledPatch p))
     wA
     wB
forall (p :: * -> * -> *) wX wY.
Commute p =>
PatchChoices p wX wY
-> (:>)
     (FL (LabelledPatch p))
     (FL (LabelledPatch p) :> FL (LabelledPatch p))
     wX
     wY
getChoices PatchChoices p wA wB
pc of
          fc :: FL (LabelledPatch p) wA wZ
fc :> mc :: FL (LabelledPatch p) wZ wZ
mc :> lc :: FL (LabelledPatch p) wZ wB
lc -> (forall wW wY. LabelledPatch p wW wY -> p wW wY)
-> FL (LabelledPatch p) wA wZ -> FL p wA wZ
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY. LabelledPatch p wW wY -> p wW wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel (FL (LabelledPatch p) wA wZ
fc FL (LabelledPatch p) wA wZ
-> FL (LabelledPatch p) wZ wZ -> FL (LabelledPatch p) wA wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (LabelledPatch p) wZ wZ
mc) FL p wA wZ -> FL p wZ wB -> (:>) (FL p) (FL p) wA wB
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> (forall wW wY. LabelledPatch p wW wY -> p wW wY)
-> FL (LabelledPatch p) wZ wB -> FL p wZ wB
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY. LabelledPatch p wW wY -> p wW wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel FL (LabelledPatch p) wZ wB
lc
    | Bool
otherwise =
        case PatchChoices p wA wB
-> (:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wA wB
forall (p :: * -> * -> *) wX wZ.
PatchChoices p wX wZ
-> (:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wX wZ
separateFirstFromMiddleLast PatchChoices p wA wB
pc of
          xs :: FL (LabelledPatch p) wA wZ
xs :> ys :: FL (LabelledPatch p) wZ wB
ys -> (forall wW wY. LabelledPatch p wW wY -> p wW wY)
-> FL (LabelledPatch p) wA wZ -> FL p wA wZ
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY. LabelledPatch p wW wY -> p wW wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel FL (LabelledPatch p) wA wZ
xs FL p wA wZ -> FL p wZ wB -> (:>) (FL p) (FL p) wA wB
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> (forall wW wY. LabelledPatch p wW wY -> p wW wY)
-> FL (LabelledPatch p) wZ wB -> FL p wZ wB
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY. LabelledPatch p wW wY -> p wW wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel FL (LabelledPatch p) wZ wB
ys

  selectChanges :: PatchChoices p wA wB
                -> PatchSelectionM p IO (PatchChoices p wA wB)
  selectChanges :: PatchChoices p wA wB -> PatchSelectionM p IO (PatchChoices p wA wB)
selectChanges
    | PatchSelectionOptions -> Bool
interactive PatchSelectionOptions
os = (forall wU wV.
 FL (LabelledPatch p) wU wV
 -> PatchChoices p wU wV
 -> ReaderT (PatchSelectionContext p) IO (PatchChoices p wU wV))
-> PatchChoices p wA wB
-> PatchSelectionM p IO (PatchChoices p wA wB)
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(Commute p, Monad m) =>
(forall wU wV.
 FL (LabelledPatch p) wU wV
 -> PatchChoices p wU wV -> m (PatchChoices p wU wV))
-> PatchChoices p wX wY -> m (PatchChoices p wX wY)
refineChoices forall wU wV.
FL (LabelledPatch p) wU wV
-> PatchChoices p wU wV
-> ReaderT (PatchSelectionContext p) IO (PatchChoices p wU wV)
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, ShowPatch p, ShowContextPatch p,
 PatchInspect p, ApplyState p ~ Tree) =>
FL (LabelledPatch p) wX wY
-> PatchChoices p wX wY
-> PatchSelectionM p IO (PatchChoices p wX wY)
textSelect
    | Bool
otherwise      = PatchChoices p wA wB -> PatchSelectionM p IO (PatchChoices p wA wB)
forall (m :: * -> *) a. Monad m => a -> m a
return (PatchChoices p wA wB
 -> PatchSelectionM p IO (PatchChoices p wA wB))
-> (PatchChoices p wA wB -> PatchChoices p wA wB)
-> PatchChoices p wA wB
-> PatchSelectionM p IO (PatchChoices p wA wB)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wA wB -> PatchChoices p wA wB
forall wX wY. PatchChoices p wX wY -> PatchChoices p wX wY
promote

  promote :: PatchChoices p wX wY -> PatchChoices p wX wY
promote
    | WhichChanges -> Bool
backward WhichChanges
whch = PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
PatchChoices p wX wY -> PatchChoices p wX wY
makeEverythingLater
    | Bool
otherwise     = PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
Commute p =>
PatchChoices p wX wY -> PatchChoices p wX wY
makeEverythingSooner
  demote :: PatchChoices p wX wY -> PatchChoices p wX wY
demote
    | WhichChanges -> Bool
backward WhichChanges
whch = PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
Commute p =>
PatchChoices p wX wY -> PatchChoices p wX wY
makeEverythingSooner
    | Bool
otherwise     = PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
PatchChoices p wX wY -> PatchChoices p wX wY
makeEverythingLater

  filterNotTouching :: PatchChoices p wX wY -> PatchChoices p wX wY
filterNotTouching
    | WhichChanges -> Bool
backward WhichChanges
whch = Maybe [String] -> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) =>
Maybe [String] -> PatchChoices p wX wY -> PatchChoices p wX wY
selectNotTouching Maybe [String]
fs
    | Bool
otherwise     = Maybe [String] -> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) =>
Maybe [String] -> PatchChoices p wX wY -> PatchChoices p wX wY
deselectNotTouching Maybe [String]
fs

  -- when using @--match@, remove unmatched patches
  -- not depended upon by matched patches
  filterUnwanted :: PatchChoices p wA wB -> PatchChoices p wA wB
  filterUnwanted :: PatchChoices p wA wB -> PatchChoices p wA wB
filterUnwanted
    | MatchCriterion p -> Bool
forall (p :: * -> * -> *). MatchCriterion p -> Bool
mcHasNonrange MatchCriterion p
crit =
        case PatchSelectionOptions -> SelectDeps
selectDeps PatchSelectionOptions
os of
          NoDeps -> PatchChoices p wA wB -> PatchChoices p wA wB
forall wX wY. PatchChoices p wX wY -> PatchChoices p wX wY
deselectUnwanted
          _      -> PatchChoices p wA wB -> PatchChoices p wA wB
forall wX wY. PatchChoices p wX wY -> PatchChoices p wX wY
demote (PatchChoices p wA wB -> PatchChoices p wA wB)
-> (PatchChoices p wA wB -> PatchChoices p wA wB)
-> PatchChoices p wA wB
-> PatchChoices p wA wB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wA wB -> PatchChoices p wA wB
forall wX wY. PatchChoices p wX wY -> PatchChoices p wX wY
selectWanted
    | Bool
otherwise = PatchChoices p wA wB -> PatchChoices p wA wB
forall a. a -> a
id

  selectWanted :: PatchChoices p wA wB -> PatchChoices p wA wB
selectWanted
    | WhichChanges -> Bool
backward WhichChanges
whch = (forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forall (p :: * -> * -> *) wA wB.
Commute p =>
(forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forceMatchingLast forall wX wY. LabelledPatch p wX wY -> Bool
iswanted_
    | Bool
otherwise     = (forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forall (p :: * -> * -> *) wA wB.
Commute p =>
(forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forceMatchingFirst forall wX wY. LabelledPatch p wX wY -> Bool
iswanted_
  deselectUnwanted :: PatchChoices p wA wB -> PatchChoices p wA wB
deselectUnwanted
    | WhichChanges -> Bool
backward WhichChanges
whch = (forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forall (p :: * -> * -> *) wA wB.
Commute p =>
(forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forceMatchingFirst (Bool -> Bool
not (Bool -> Bool)
-> (LabelledPatch p wX wY -> Bool) -> LabelledPatch p wX wY -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LabelledPatch p wX wY -> Bool
forall wX wY. LabelledPatch p wX wY -> Bool
iswanted_)
    | Bool
otherwise     = (forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forall (p :: * -> * -> *) wA wB.
Commute p =>
(forall wX wY. LabelledPatch p wX wY -> Bool)
-> PatchChoices p wA wB -> PatchChoices p wA wB
forceMatchingLast (Bool -> Bool
not (Bool -> Bool)
-> (LabelledPatch p wX wY -> Bool) -> LabelledPatch p wX wY -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LabelledPatch p wX wY -> Bool
forall wX wY. LabelledPatch p wX wY -> Bool
iswanted_)
  iswanted_ :: LabelledPatch p wA wB -> Bool
iswanted_ = MatchCriterion p -> WhichChanges -> LabelledPatch p wA wB -> Bool
forall (p :: * -> * -> *).
MatchCriterion p
-> forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool
mcFunction MatchCriterion p
crit WhichChanges
whch

  {- end of runSelection -}

-- | The equivalent of 'runSelection' for the @darcs log@ command
viewChanges :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree)
            => PatchSelectionOptions -> [Sealed2 p] -> IO ()
viewChanges :: PatchSelectionOptions -> [Sealed2 p] -> IO ()
viewChanges ps_opts :: PatchSelectionOptions
ps_opts = PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView PatchSelectionOptions
ps_opts Maybe Int
forall a. Maybe a
Nothing 0 []

-- | The type of the answers to a "shall I [wiggle] that [foo]?" question
-- They are found in a [[KeyPress]] bunch, each list representing a set of
-- answers which belong together
data KeyPress = KeyPress { KeyPress -> Char
kp     :: Char
                           , KeyPress -> String
kpHelp :: String }

-- | Generates the help for a set of basic and advanced 'KeyPress' groups.
helpFor :: String -> [[KeyPress]] -> [[KeyPress]] -> String
helpFor :: String -> [[KeyPress]] -> [[KeyPress]] -> String
helpFor jn :: String
jn basicKeypresses :: [[KeyPress]]
basicKeypresses advancedKeyPresses :: [[KeyPress]]
advancedKeyPresses =
  [String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [ "How to use "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++":" ]
            [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String] -> [[String]] -> [String]
forall a. [a] -> [[a]] -> [a]
intercalate [""] (([KeyPress] -> [String]) -> [[KeyPress]] -> [[String]]
forall a b. (a -> b) -> [a] -> [b]
map ((KeyPress -> String) -> [KeyPress] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map KeyPress -> String
help) [[KeyPress]]
keypresses)
            [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [ ""
               , "?: show this help"
               , ""
               , "<Space>: accept the current default (which is capitalized)"
               ]
  where help :: KeyPress -> String
help i :: KeyPress
i = KeyPress -> Char
kp KeyPress
iChar -> ShowS
forall a. a -> [a] -> [a]
:(": "String -> ShowS
forall a. [a] -> [a] -> [a]
++KeyPress -> String
kpHelp KeyPress
i)
        keypresses :: [[KeyPress]]
keypresses = [[KeyPress]]
basicKeypresses [[KeyPress]] -> [[KeyPress]] -> [[KeyPress]]
forall a. [a] -> [a] -> [a]
++ [[KeyPress]]
advancedKeyPresses

-- | The keys used by a list of 'keyPress' groups.
keysFor :: [[KeyPress]] -> [Char]
keysFor :: [[KeyPress]] -> String
keysFor = ([KeyPress] -> String) -> [[KeyPress]] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((KeyPress -> Char) -> [KeyPress] -> String
forall a b. (a -> b) -> [a] -> [b]
map KeyPress -> Char
kp)

-- | The function for selecting a patch to amend record. Read at your own risks.
withSelectedPatchFromRepo
    :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree)
    => String   -- name of calling command (always "amend" as of now)
    -> Repository rt p wR wU wT
    -> PatchSelectionOptions
    -> (forall wA . (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wA wR -> IO ())
    -> IO ()
withSelectedPatchFromRepo :: String
-> Repository rt p wR wU wT
-> PatchSelectionOptions
-> (forall wA.
    (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wA wR -> IO ())
-> IO ()
withSelectedPatchFromRepo jn :: String
jn repository :: Repository rt p wR wU wT
repository o :: PatchSelectionOptions
o job :: forall wA.
(:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wA wR -> IO ()
job = do
    PatchSet rt p Origin wR
patchSet <- Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
readRepo Repository rt p wR wU wT
repository
    Maybe
  (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wR)
sp <- String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) Origin wR
-> FL (WithSkipped (PatchInfoAnd rt p)) wR wR
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wR))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn ([MatchFlag] -> PatchInfoAnd rt p wA wB -> Bool
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
(IsRepoType rt, Matchable p) =>
[MatchFlag] -> PatchInfoAnd rt p wX wY -> Bool
matchAPatch ([MatchFlag] -> PatchInfoAnd rt p wA wB -> Bool)
-> [MatchFlag] -> PatchInfoAnd rt p wA wB -> Bool
forall a b. (a -> b) -> a -> b
$ PatchSelectionOptions -> [MatchFlag]
matchFlags PatchSelectionOptions
o) (PatchSet rt p Origin wR -> RL (PatchInfoAnd rt p) Origin wR
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
patchSet2RL PatchSet rt p Origin wR
patchSet) FL (WithSkipped (PatchInfoAnd rt p)) wR wR
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
    case Maybe
  (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wR)
sp of
        Just (FlippedSeal (skipped :: FL (PatchInfoAnd rt p) wX wZ
skipped :> selected' :: PatchInfoAnd rt p wZ wR
selected')) -> (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wX wR -> IO ()
forall wA.
(:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wA wR -> IO ()
job (FL (PatchInfoAnd rt p) wX wZ
skipped FL (PatchInfoAnd rt p) wX wZ
-> PatchInfoAnd rt p wZ wR
-> (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wX wR
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> PatchInfoAnd rt p wZ wR
selected')
        Nothing ->
            String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ "Cancelling " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " since no patch was selected."

data SkippedReason = SkippedAutomatically | SkippedManually

data WithSkipped p wX wY = WithSkipped
    { WithSkipped p wX wY -> SkippedReason
_skippedReason :: SkippedReason
    , WithSkipped p wX wY -> p wX wY
skippedPatch :: p wX wY
    }

-- | This ensures that the selected patch commutes freely with the skipped
-- patches, including pending and also that the skipped sequences has an
-- ending context that matches the recorded state, z, of the repository.
wspfr :: forall rt p wX wY wU. (RepoPatch p, ApplyState p ~ Tree)
      => String
      -> (forall wA wB . (PatchInfoAnd rt p) wA wB -> Bool)
      -> RL (PatchInfoAnd rt p) wX wY
      -> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
      -> IO (Maybe (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr :: String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr _ _ NilRL _ = Maybe
  (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe
  (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
forall a. Maybe a
Nothing
wspfr jn :: String
jn matches :: forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches remaining :: RL (PatchInfoAnd rt p) wX wY
remaining@(pps :: RL (PatchInfoAnd rt p) wX wY
pps:<:p :: PatchInfoAnd rt p wY wY
p) skipped :: FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped
    | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ PatchInfoAnd rt p wY wY -> Bool
forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches PatchInfoAnd rt p wY wY
p = String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches RL (PatchInfoAnd rt p) wX wY
pps
                            (SkippedReason
-> PatchInfoAnd rt p wY wY -> WithSkipped (PatchInfoAnd rt p) wY wY
forall (p :: * -> * -> *) wX wY.
SkippedReason -> p wX wY -> WithSkipped p wX wY
WithSkipped SkippedReason
SkippedAutomatically PatchInfoAnd rt p wY wY
p WithSkipped (PatchInfoAnd rt p) wY wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped)
    | Bool
otherwise =
    case (:>) (PatchInfoAnd rt p) (FL (PatchInfoAnd rt p)) wY wU
-> Either
     (Sealed2 (PatchInfoAnd rt p))
     ((:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wY wU)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p (FL p) wX wY -> Either (Sealed2 p) ((:>) (FL p) p wX wY)
commuteFLorComplain (PatchInfoAnd rt p wY wY
p PatchInfoAnd rt p wY wY
-> FL (PatchInfoAnd rt p) wY wU
-> (:>) (PatchInfoAnd rt p) (FL (PatchInfoAnd rt p)) wY wU
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> (forall wW wY.
 WithSkipped (PatchInfoAnd rt p) wW wY -> PatchInfoAnd rt p wW wY)
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> FL (PatchInfoAnd rt p) wY wU
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY.
WithSkipped (PatchInfoAnd rt p) wW wY -> PatchInfoAnd rt p wW wY
forall (p :: * -> * -> *) wX wY. WithSkipped p wX wY -> p wX wY
skippedPatch FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped) of
    Left _  -> do String -> IO ()
putStrLn "\nSkipping depended-upon patch:"
                  PatchInfoAnd rt p wY wY -> IO ()
forall wX wY. PatchInfoAnd rt p wX wY -> IO ()
defaultPrintFriendly PatchInfoAnd rt p wY wY
p
                  String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches RL (PatchInfoAnd rt p) wX wY
pps (SkippedReason
-> PatchInfoAnd rt p wY wY -> WithSkipped (PatchInfoAnd rt p) wY wY
forall (p :: * -> * -> *) wX wY.
SkippedReason -> p wX wY -> WithSkipped p wX wY
WithSkipped SkippedReason
SkippedAutomatically PatchInfoAnd rt p wY wY
p WithSkipped (PatchInfoAnd rt p) wY wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped)

    Right (skipped' :: FL (PatchInfoAnd rt p) wY wZ
skipped' :> p' :: PatchInfoAnd rt p wZ wU
p') -> do
        PatchInfoAnd rt p wY wY -> IO ()
forall wX wY. PatchInfoAnd rt p wX wY -> IO ()
defaultPrintFriendly PatchInfoAnd rt p wY wY
p
        Char
yorn <- PromptConfig -> IO Char
promptChar
                    PromptConfig :: String -> String -> String -> Maybe Char -> String -> PromptConfig
PromptConfig { pPrompt :: String
pPrompt = String
prompt'
                                 , pBasicCharacters :: String
pBasicCharacters = [[KeyPress]] -> String
keysFor [[KeyPress]]
basicOptions
                                 , pAdvancedCharacters :: String
pAdvancedCharacters = [[KeyPress]] -> String
keysFor [[KeyPress]]
advancedOptions
                                 , pDefault :: Maybe Char
pDefault = Char -> Maybe Char
forall a. a -> Maybe a
Just 'n'
                                 , pHelp :: String
pHelp = "?h" }
        case Char
yorn of
            'y' -> Maybe
  (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe
   (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
 -> IO
      (Maybe
         (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)))
-> Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall a b. (a -> b) -> a -> b
$ FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU
-> Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
forall a. a -> Maybe a
Just (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU
 -> Maybe
      (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
-> FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU
-> Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
forall a b. (a -> b) -> a -> b
$ (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wY wU
-> FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU
forall (a :: * -> * -> *) wX wY. a wX wY -> FlippedSeal a wY
flipSeal ((:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wY wU
 -> FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)
-> (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wY wU
-> FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU
forall a b. (a -> b) -> a -> b
$ FL (PatchInfoAnd rt p) wY wZ
skipped' FL (PatchInfoAnd rt p) wY wZ
-> PatchInfoAnd rt p wZ wU
-> (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wY wU
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> PatchInfoAnd rt p wZ wU
p'
            'n' -> IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
nextPatch
            'j' -> IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
nextPatch
            'k' -> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall wQ.
RL (PatchInfoAnd rt p) wX wQ
-> FL (WithSkipped (PatchInfoAnd rt p)) wQ wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
previousPatch RL (PatchInfoAnd rt p) wX wY
remaining FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped
            'v' -> PatchInfoAnd rt p wY wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatch PatchInfoAnd rt p wY wY
p IO ()
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
repeatThis
            'p' -> PatchInfoAnd rt p wY wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatchPager PatchInfoAnd rt p wY wY
p IO ()
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
repeatThis
            'x' -> do Doc -> IO ()
putDocLn (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Doc -> Doc
prefix "    " (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ PatchInfoAnd rt p wY wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
Darcs.Patch.summary PatchInfoAnd rt p wY wY
p
                      IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
repeatThis
            'q' -> do String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ (ShowS
capitalize String
jn) String -> ShowS
forall a. [a] -> [a] -> [a]
++ " cancelled."
                      IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall a. IO a
exitSuccess
            _   -> do String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> [[KeyPress]] -> [[KeyPress]] -> String
helpFor String
jn [[KeyPress]]
basicOptions [[KeyPress]]
advancedOptions
                      IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
repeatThis
  where repeatThis :: IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
repeatThis = String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches (RL (PatchInfoAnd rt p) wX wY
ppsRL (PatchInfoAnd rt p) wX wY
-> PatchInfoAnd rt p wY wY -> RL (PatchInfoAnd rt p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<:PatchInfoAnd rt p wY wY
p) FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped
        prompt' :: String
prompt' = "Shall I " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " this patch?"
        nextPatch :: IO
  (Maybe
     (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
nextPatch = String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches RL (PatchInfoAnd rt p) wX wY
pps (SkippedReason
-> PatchInfoAnd rt p wY wY -> WithSkipped (PatchInfoAnd rt p) wY wY
forall (p :: * -> * -> *) wX wY.
SkippedReason -> p wX wY -> WithSkipped p wX wY
WithSkipped SkippedReason
SkippedManually PatchInfoAnd rt p wY wY
pWithSkipped (PatchInfoAnd rt p) wY wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>:FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped)
        previousPatch :: RL (PatchInfoAnd rt p) wX wQ
                      -> FL (WithSkipped (PatchInfoAnd rt p)) wQ wU
                      -> IO (Maybe (FlippedSeal
                              (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
        previousPatch :: RL (PatchInfoAnd rt p) wX wQ
-> FL (WithSkipped (PatchInfoAnd rt p)) wQ wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
previousPatch remaining' :: RL (PatchInfoAnd rt p) wX wQ
remaining' NilFL = String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wQ
-> FL (WithSkipped (PatchInfoAnd rt p)) wQ wQ
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wQ))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches RL (PatchInfoAnd rt p) wX wQ
remaining' FL (WithSkipped (PatchInfoAnd rt p)) wQ wQ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
        previousPatch remaining' :: RL (PatchInfoAnd rt p) wX wQ
remaining' (WithSkipped sk :: SkippedReason
sk prev :: PatchInfoAnd rt p wQ wY
prev :>: skipped'' :: FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped'') =
            case SkippedReason
sk of
                SkippedManually -> String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wU.
(RepoPatch p, ApplyState p ~ Tree) =>
String
-> (forall wA wB. PatchInfoAnd rt p wA wB -> Bool)
-> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
wspfr String
jn forall wA wB. PatchInfoAnd rt p wA wB -> Bool
matches (RL (PatchInfoAnd rt p) wX wQ
remaining' RL (PatchInfoAnd rt p) wX wQ
-> PatchInfoAnd rt p wQ wY -> RL (PatchInfoAnd rt p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: PatchInfoAnd rt p wQ wY
prev) FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped''
                SkippedAutomatically -> RL (PatchInfoAnd rt p) wX wY
-> FL (WithSkipped (PatchInfoAnd rt p)) wY wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
forall wQ.
RL (PatchInfoAnd rt p) wX wQ
-> FL (WithSkipped (PatchInfoAnd rt p)) wQ wU
-> IO
     (Maybe
        (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU))
previousPatch (RL (PatchInfoAnd rt p) wX wQ
remaining' RL (PatchInfoAnd rt p) wX wQ
-> PatchInfoAnd rt p wQ wY -> RL (PatchInfoAnd rt p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: PatchInfoAnd rt p wQ wY
prev) FL (WithSkipped (PatchInfoAnd rt p)) wY wU
skipped''
        basicOptions :: [[KeyPress]]
basicOptions =
                    [[ Char -> String -> KeyPress
KeyPress 'y' (String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " this patch")
                     , Char -> String -> KeyPress
KeyPress 'n' ("don't " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " it")
                     , Char -> String -> KeyPress
KeyPress 'j' "skip to next patch"
                     , Char -> String -> KeyPress
KeyPress 'k' "back up to previous patch"
                    ]]
        advancedOptions :: [[KeyPress]]
advancedOptions =
                    [[ Char -> String -> KeyPress
KeyPress 'v' "view this patch in full"
                     , Char -> String -> KeyPress
KeyPress 'p' "view this patch in full with pager"
                     , Char -> String -> KeyPress
KeyPress 'x' "view a summary of this patch"
                     , Char -> String -> KeyPress
KeyPress 'q' ("cancel " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn)
                    ]]
        defaultPrintFriendly :: PatchInfoAnd rt p wX wY -> IO ()
defaultPrintFriendly =
          Maybe (Tree IO)
-> Verbosity
-> Summary
-> WithContext
-> PatchInfoAnd rt p wX wY
-> IO ()
forall (p :: * -> * -> *) wX wY.
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
printFriendly Maybe (Tree IO)
forall a. Maybe a
Nothing Verbosity
NormalVerbosity Summary
NoSummary WithContext
NoContext

-- | Runs a function on the underlying @PatchChoices@ object
liftChoices :: StateT (PatchChoices p wX wY) Identity a
            -> InteractiveSelectionM p wX wY a
liftChoices :: StateT (PatchChoices p wX wY) Identity a
-> InteractiveSelectionM p wX wY a
liftChoices act :: StateT (PatchChoices p wX wY) Identity a
act = do
  PatchChoices p wX wY
ch <- (InteractiveSelectionContext p wX wY -> PatchChoices p wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (PatchChoices p wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices
  let (result :: a
result, _) = Identity (a, PatchChoices p wX wY) -> (a, PatchChoices p wX wY)
forall a. Identity a -> a
runIdentity (Identity (a, PatchChoices p wX wY) -> (a, PatchChoices p wX wY))
-> Identity (a, PatchChoices p wX wY) -> (a, PatchChoices p wX wY)
forall a b. (a -> b) -> a -> b
$ StateT (PatchChoices p wX wY) Identity a
-> PatchChoices p wX wY -> Identity (a, PatchChoices p wX wY)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT StateT (PatchChoices p wX wY) Identity a
act PatchChoices p wX wY
ch
  (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> StateT
      (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc {choices :: PatchChoices p wX wY
choices = PatchChoices p wX wY
ch} -- Should this be ch or the result of runState?
  a -> InteractiveSelectionM p wX wY a
forall (m :: * -> *) a. Monad m => a -> m a
return a
result

-- | @justDone n@ notes that @n@ patches have just been processed
justDone :: Int -> InteractiveSelectionM p wX wY ()
justDone :: Int -> InteractiveSelectionM p wX wY ()
justDone n :: Int
n = (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc{ current :: Int
current = InteractiveSelectionContext p wX wY -> Int
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> Int
current InteractiveSelectionContext p wX wY
isc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n}

-- | The actual interactive selection process.
textSelect :: ( Commute p, Invert p, ShowPatch p, ShowContextPatch p
              , PatchInspect p, ApplyState p ~ Tree )
           => FL (LabelledPatch p) wX wY
           -> PatchChoices p wX wY
           -> PatchSelectionM p IO (PatchChoices p wX wY)
textSelect :: FL (LabelledPatch p) wX wY
-> PatchChoices p wX wY
-> PatchSelectionM p IO (PatchChoices p wX wY)
textSelect lps' :: FL (LabelledPatch p) wX wY
lps' pcs :: PatchChoices p wX wY
pcs = do
    InteractiveSelectionContext p wX wY
userSelection <- StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> InteractiveSelectionContext p wX wY
-> PatchSelectionM p IO (InteractiveSelectionContext p wX wY)
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m s
execStateT (StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (p :: * -> * -> *) wX wY.
(Commute p, ShowPatch p) =>
InteractiveSelectionM p wX wY ()
skipMundane StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                                 StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                                 StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall wX wY.
StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
textSelectIfAny)
                     ISC :: forall (p :: * -> * -> *) wX wY.
Int
-> Int
-> FZipper (LabelledPatch p) wX wY
-> PatchChoices p wX wY
-> InteractiveSelectionContext p wX wY
ISC { total :: Int
total = FL (LabelledPatch p) wX wY -> Int
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Int
lengthFL FL (LabelledPatch p) wX wY
lps'
                         , current :: Int
current = 0
                         , lps :: FZipper (LabelledPatch p) wX wY
lps = RL (LabelledPatch p) wX wX
-> FL (LabelledPatch p) wX wY -> FZipper (LabelledPatch p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> FL a wY wZ -> FZipper a wX wZ
FZipper RL (LabelledPatch p) wX wX
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL FL (LabelledPatch p) wX wY
lps'
                         , choices :: PatchChoices p wX wY
choices = PatchChoices p wX wY
pcs }
    PatchChoices p wX wY -> PatchSelectionM p IO (PatchChoices p wX wY)
forall (m :: * -> *) a. Monad m => a -> m a
return (PatchChoices p wX wY
 -> PatchSelectionM p IO (PatchChoices p wX wY))
-> PatchChoices p wX wY
-> PatchSelectionM p IO (PatchChoices p wX wY)
forall a b. (a -> b) -> a -> b
$ InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices InteractiveSelectionContext p wX wY
userSelection
    where textSelectIfAny :: StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
textSelectIfAny = do
            FZipper (LabelledPatch p) wX wY
z <- (InteractiveSelectionContext p wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FZipper (LabelledPatch p) wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps
            Bool
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FZipper (LabelledPatch p) wX wY -> Bool
forall (p :: * -> * -> *) wX wY. FZipper p wX wY -> Bool
rightmost FZipper (LabelledPatch p) wX wY
z) (StateT
   (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
 -> StateT
      (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ())
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall a b. (a -> b) -> a -> b
$
              StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, ShowPatch p, ShowContextPatch p,
 PatchInspect p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
textSelect'

textSelect' :: ( Commute p, Invert p, ShowPatch p, ShowContextPatch p
               , PatchInspect p, ApplyState p ~ Tree )
            => InteractiveSelectionM p wX wY ()
textSelect' :: InteractiveSelectionM p wX wY ()
textSelect' = do
  FZipper (LabelledPatch p) wX wY
z <- (InteractiveSelectionContext p wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FZipper (LabelledPatch p) wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps
  Bool
done <- if Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FZipper (LabelledPatch p) wX wY -> Bool
forall (p :: * -> * -> *) wX wY. FZipper p wX wY -> Bool
rightmost FZipper (LabelledPatch p) wX wY
z
           then InteractiveSelectionM p wX wY Bool
forall (p :: * -> * -> *) wX wY.
(Invert p, Commute p, ShowPatch p, ShowContextPatch p,
 PatchInspect p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY Bool
textSelectOne
           else InteractiveSelectionM p wX wY Bool
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, ShowPatch p, ShowContextPatch p,
 ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY Bool
lastQuestion
  Bool
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
done (InteractiveSelectionM p wX wY ()
 -> InteractiveSelectionM p wX wY ())
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, ShowPatch p, ShowContextPatch p,
 PatchInspect p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
textSelect'

optionsBasic :: String -> String -> [KeyPress]
optionsBasic :: String -> String -> [KeyPress]
optionsBasic jn :: String
jn aThing :: String
aThing =
    [ Char -> String -> KeyPress
KeyPress 'y' (String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" this "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
aThing)
    , Char -> String -> KeyPress
KeyPress 'n' ("don't "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" it")
    , Char -> String -> KeyPress
KeyPress 'w' "wait and decide later, defaulting to no" ]

optionsFile :: String -> [KeyPress]
optionsFile :: String -> [KeyPress]
optionsFile jn :: String
jn =
    [ Char -> String -> KeyPress
KeyPress 's' ("don't "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" the rest of the changes to this file")
    , Char -> String -> KeyPress
KeyPress 'f' (String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" the rest of the changes to this file") ]

optionsView :: String -> String -> [KeyPress]
optionsView :: String -> String -> [KeyPress]
optionsView aThing :: String
aThing someThings :: String
someThings =
    [ Char -> String -> KeyPress
KeyPress 'v' ("view this "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
aThingString -> ShowS
forall a. [a] -> [a] -> [a]
++" in full")
    , Char -> String -> KeyPress
KeyPress 'p' ("view this "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
aThingString -> ShowS
forall a. [a] -> [a] -> [a]
++" in full with pager")
    , Char -> String -> KeyPress
KeyPress 'l' ("list all selected "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
someThings) ]

optionsSummary :: String -> [KeyPress]
optionsSummary :: String -> [KeyPress]
optionsSummary aThing :: String
aThing =
    [ Char -> String -> KeyPress
KeyPress 'x' ("view a summary of this "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
aThing) ]

optionsQuit :: String -> Bool -> String -> [KeyPress]
optionsQuit :: String -> Bool -> String -> [KeyPress]
optionsQuit jn :: String
jn allowsa :: Bool
allowsa someThings :: String
someThings =
    [ Char -> String -> KeyPress
KeyPress 'd' (String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" selected "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
someThingsString -> ShowS
forall a. [a] -> [a] -> [a]
++
                    ", skipping all the remaining "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
someThings)
            | Bool
allowsa ]
    [KeyPress] -> [KeyPress] -> [KeyPress]
forall a. [a] -> [a] -> [a]
++
    [ Char -> String -> KeyPress
KeyPress 'a' (String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" all the remaining "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
someThings)
    , Char -> String -> KeyPress
KeyPress 'q' ("cancel "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
jn) ]

optionsNav :: String -> Bool -> [KeyPress]
optionsNav :: String -> Bool -> [KeyPress]
optionsNav aThing :: String
aThing isLast :: Bool
isLast=
    [ Char -> String -> KeyPress
KeyPress 'j' ("skip to next "String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
aThing) | Bool -> Bool
not Bool
isLast ]
    [KeyPress] -> [KeyPress] -> [KeyPress]
forall a. [a] -> [a] -> [a]
++
    [ Char -> String -> KeyPress
KeyPress 'k' ("back up to previous "String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
aThing)
    , Char -> String -> KeyPress
KeyPress 'g' ("start over from the first "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
aThing)]

optionsSplit :: Maybe (Splitter a) -> String -> [KeyPress]
optionsSplit :: Maybe (Splitter a) -> String -> [KeyPress]
optionsSplit split :: Maybe (Splitter a)
split aThing :: String
aThing
    | Just _ <- Maybe (Splitter a)
split
             = [ Char -> String -> KeyPress
KeyPress 'e' ("interactively edit this "String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
aThing) ]
    | Bool
otherwise = []

optionsLast :: String -> String -> ([[KeyPress]], [[KeyPress]])
optionsLast :: String -> String -> ([[KeyPress]], [[KeyPress]])
optionsLast jn :: String
jn aThing :: String
aThing =
  (String -> Bool -> [KeyPress]
optionsNav String
aThing Bool
True[KeyPress] -> [[KeyPress]] -> [[KeyPress]]
forall a. a -> [a] -> [a]
:
   [[ Char -> String -> KeyPress
KeyPress 'y' "confirm this operation"
    , Char -> String -> KeyPress
KeyPress 'q' ("cancel " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn) ]
    , [ Char -> String -> KeyPress
KeyPress 'l' "list all selected" ]
   ]
  ,[[Char -> String -> KeyPress
KeyPress 'a' "confirm this operation"
    , Char -> String -> KeyPress
KeyPress 'd' "confirm this operation"
    , Char -> String -> KeyPress
KeyPress 'n' ("cancel " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn) ]])

options :: (ShowPatch p)
        => Bool
        -> InteractiveSelectionM p wX wY ([[KeyPress]],[[KeyPress]])
options :: Bool -> InteractiveSelectionM p wX wY ([[KeyPress]], [[KeyPress]])
options single :: Bool
single = do
  Maybe (Splitter p)
split <- (PatchSelectionContext p -> Maybe (Splitter p))
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (Maybe (Splitter p))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> Maybe (Splitter p)
forall (p :: * -> * -> *).
PatchSelectionContext p -> Maybe (Splitter p)
splitter
  String
jn <- (PatchSelectionContext p -> String)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> String
forall (p :: * -> * -> *). PatchSelectionContext p -> String
jobname
  Bool
allowsa <- (PatchSelectionContext p -> Bool)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> Bool
forall (p :: * -> * -> *). PatchSelectionContext p -> Bool
allowSkipAll
  String
aThing <- StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
thing
  String
someThings <- StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
things
  PatchSelectionOptions
o <- (PatchSelectionContext p -> PatchSelectionOptions)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     PatchSelectionOptions
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> PatchSelectionOptions
forall (p :: * -> * -> *).
PatchSelectionContext p -> PatchSelectionOptions
opts
  ([[KeyPress]], [[KeyPress]])
-> InteractiveSelectionM p wX wY ([[KeyPress]], [[KeyPress]])
forall (m :: * -> *) a. Monad m => a -> m a
return ([String -> String -> [KeyPress]
optionsBasic String
jn String
aThing]
         ,[Maybe (Splitter p) -> String -> [KeyPress]
forall (a :: * -> * -> *).
Maybe (Splitter a) -> String -> [KeyPress]
optionsSplit Maybe (Splitter p)
split String
aThing]
         [[KeyPress]] -> [[KeyPress]] -> [[KeyPress]]
forall a. [a] -> [a] -> [a]
++ [String -> [KeyPress]
optionsFile String
jn | Bool
single]
         [[KeyPress]] -> [[KeyPress]] -> [[KeyPress]]
forall a. [a] -> [a] -> [a]
++ [String -> String -> [KeyPress]
optionsView String
aThing String
someThings [KeyPress] -> [KeyPress] -> [KeyPress]
forall a. [a] -> [a] -> [a]
++
                if PatchSelectionOptions -> Summary
summary PatchSelectionOptions
o Summary -> Summary -> Bool
forall a. Eq a => a -> a -> Bool
== Summary
YesSummary
                    then []
                    else String -> [KeyPress]
optionsSummary String
aThing]
         [[KeyPress]] -> [[KeyPress]] -> [[KeyPress]]
forall a. [a] -> [a] -> [a]
++ [String -> Bool -> String -> [KeyPress]
optionsQuit String
jn Bool
allowsa String
someThings]
         [[KeyPress]] -> [[KeyPress]] -> [[KeyPress]]
forall a. [a] -> [a] -> [a]
++ [String -> Bool -> [KeyPress]
optionsNav String
aThing Bool
False]
         )

-- | Returns a @Sealed2@ version of the patch we are asking the user
-- about.
currentPatch :: InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
currentPatch :: InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
currentPatch = do
  FZipper _ lps_todo :: FL (LabelledPatch p) wY wY
lps_todo <- (InteractiveSelectionContext p wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FZipper (LabelledPatch p) wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps
  case FL (LabelledPatch p) wY wY
lps_todo of
    NilFL -> Maybe (Sealed2 (LabelledPatch p))
-> InteractiveSelectionM
     p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Sealed2 (LabelledPatch p))
forall a. Maybe a
Nothing
    (lp :: LabelledPatch p wY wY
lp:>:_) -> Maybe (Sealed2 (LabelledPatch p))
-> InteractiveSelectionM
     p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Sealed2 (LabelledPatch p))
 -> InteractiveSelectionM
      p wX wY (Maybe (Sealed2 (LabelledPatch p))))
-> Maybe (Sealed2 (LabelledPatch p))
-> InteractiveSelectionM
     p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall a b. (a -> b) -> a -> b
$ Sealed2 (LabelledPatch p) -> Maybe (Sealed2 (LabelledPatch p))
forall a. a -> Maybe a
Just (LabelledPatch p wY wY -> Sealed2 (LabelledPatch p)
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
Sealed2 LabelledPatch p wY wY
lp)

-- | Returns the patches we have yet to ask the user about.
todo :: InteractiveSelectionM p wX wY (FlippedSeal (FL (LabelledPatch p)) wY)
todo :: InteractiveSelectionM
  p wX wY (FlippedSeal (FL (LabelledPatch p)) wY)
todo = do
    (FZipper _ lps_todo :: FL (LabelledPatch p) wY wY
lps_todo) <- (InteractiveSelectionContext p wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FZipper (LabelledPatch p) wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps
    FlippedSeal (FL (LabelledPatch p)) wY
-> InteractiveSelectionM
     p wX wY (FlippedSeal (FL (LabelledPatch p)) wY)
forall (m :: * -> *) a. Monad m => a -> m a
return (FL (LabelledPatch p) wY wY -> FlippedSeal (FL (LabelledPatch p)) wY
forall (a :: * -> * -> *) wX wY. a wX wY -> FlippedSeal a wY
FlippedSeal FL (LabelledPatch p) wY wY
lps_todo)

-- | Modify the underlying @PatchChoices@ by some function
modifyChoices :: (PatchChoices p wX wY -> PatchChoices p wX wY)
              -> InteractiveSelectionM p wX wY ()
modifyChoices :: (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
modifyChoices f :: PatchChoices p wX wY -> PatchChoices p wX wY
f = (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc{choices :: PatchChoices p wX wY
choices = PatchChoices p wX wY -> PatchChoices p wX wY
f (PatchChoices p wX wY -> PatchChoices p wX wY)
-> PatchChoices p wX wY -> PatchChoices p wX wY
forall a b. (a -> b) -> a -> b
$ InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices InteractiveSelectionContext p wX wY
isc}

-- | returns @Just f@ if the 'currentPatch' only modifies @f@,
-- @Nothing@ otherwise.
currentFile :: (PatchInspect p)
            => InteractiveSelectionM p wX wY (Maybe FilePath)
currentFile :: InteractiveSelectionM p wX wY (Maybe String)
currentFile = do
  Maybe (Sealed2 (LabelledPatch p))
c <- InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
currentPatch
  Maybe String -> InteractiveSelectionM p wX wY (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> InteractiveSelectionM p wX wY (Maybe String))
-> Maybe String -> InteractiveSelectionM p wX wY (Maybe String)
forall a b. (a -> b) -> a -> b
$ case Maybe (Sealed2 (LabelledPatch p))
c of
             Nothing -> Maybe String
forall a. Maybe a
Nothing
             Just (Sealed2 lp :: LabelledPatch p wX wY
lp) ->
                 case LabelledPatch p wX wY -> [String]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [String]
listTouchedFiles LabelledPatch p wX wY
lp of
                   [f :: String
f] -> String -> Maybe String
forall a. a -> Maybe a
Just String
f
                   _ -> Maybe String
forall a. Maybe a
Nothing

-- | @decide True@ selects the current patch, and @decide False@ deselects
-- it.
decide :: Commute p
       => Bool
       -> LabelledPatch p wT wU
       -> InteractiveSelectionM p wX wY ()
decide :: Bool -> LabelledPatch p wT wU -> InteractiveSelectionM p wX wY ()
decide takeOrDrop :: Bool
takeOrDrop lp :: LabelledPatch p wT wU
lp = do
    WhichChanges
whch <- (PatchSelectionContext p -> WhichChanges)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     WhichChanges
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> WhichChanges
forall (p :: * -> * -> *). PatchSelectionContext p -> WhichChanges
whichChanges
    if WhichChanges -> Bool
backward WhichChanges
whch Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
takeOrDrop -- we go backward xor we are dropping
    then (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
modifyChoices ((PatchChoices p wX wY -> PatchChoices p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Label -> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wA wB.
Commute p =>
Label -> PatchChoices p wA wB -> PatchChoices p wA wB
forceLast (LabelledPatch p wT wU -> Label
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> Label
label LabelledPatch p wT wU
lp)
    else (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
modifyChoices ((PatchChoices p wX wY -> PatchChoices p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Label -> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wA wB.
Commute p =>
Label -> PatchChoices p wA wB -> PatchChoices p wA wB
forceFirst (LabelledPatch p wT wU -> Label
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> Label
label LabelledPatch p wT wU
lp)

-- | like 'decide', but for all patches touching @file@
decideWholeFile :: (Commute p, PatchInspect p)
                => FilePath -> Bool -> InteractiveSelectionM p wX wY ()
decideWholeFile :: String -> Bool -> InteractiveSelectionM p wX wY ()
decideWholeFile file :: String
file takeOrDrop :: Bool
takeOrDrop =
    do
      FlippedSeal lps_todo :: FL (LabelledPatch p) wX wY
lps_todo <- InteractiveSelectionM
  p wX wY (FlippedSeal (FL (LabelledPatch p)) wY)
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionM
  p wX wY (FlippedSeal (FL (LabelledPatch p)) wY)
todo
      let patches_to_skip :: [Sealed2 (LabelledPatch p)]
patches_to_skip =
              (forall wX wY. LabelledPatch p wX wY -> Bool)
-> FL (LabelledPatch p) wX wY -> [Sealed2 (LabelledPatch p)]
forall (a :: * -> * -> *) wW wZ.
(forall wX wY. a wX wY -> Bool) -> FL a wW wZ -> [Sealed2 a]
filterFL (\lp' :: LabelledPatch p wX wY
lp' -> LabelledPatch p wX wY -> [String]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [String]
listTouchedFiles LabelledPatch p wX wY
lp' [String] -> [String] -> Bool
forall a. Eq a => a -> a -> Bool
== [String
file]) FL (LabelledPatch p) wX wY
lps_todo
      (Sealed2 (LabelledPatch p) -> InteractiveSelectionM p wX wY ())
-> [Sealed2 (LabelledPatch p)] -> InteractiveSelectionM p wX wY ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((forall wX wY.
 LabelledPatch p wX wY -> InteractiveSelectionM p wX wY ())
-> Sealed2 (LabelledPatch p) -> InteractiveSelectionM p wX wY ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 ((forall wX wY.
  LabelledPatch p wX wY -> InteractiveSelectionM p wX wY ())
 -> Sealed2 (LabelledPatch p) -> InteractiveSelectionM p wX wY ())
-> (forall wX wY.
    LabelledPatch p wX wY -> InteractiveSelectionM p wX wY ())
-> Sealed2 (LabelledPatch p)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Bool -> LabelledPatch p wX wY -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wT wU wX wY.
Commute p =>
Bool -> LabelledPatch p wT wU -> InteractiveSelectionM p wX wY ()
decide Bool
takeOrDrop) [Sealed2 (LabelledPatch p)]
patches_to_skip

-- | Undecide the current patch.
postponeNext :: Commute p => InteractiveSelectionM p wX wY ()
postponeNext :: InteractiveSelectionM p wX wY ()
postponeNext =
    do
      Just (Sealed2 lp :: LabelledPatch p wX wY
lp) <- InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
currentPatch
      (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
modifyChoices ((PatchChoices p wX wY -> PatchChoices p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Label -> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wA wB.
Commute p =>
Label -> PatchChoices p wA wB -> PatchChoices p wA wB
forceMiddle (LabelledPatch p wX wY -> Label
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> Label
label LabelledPatch p wX wY
lp)

-- | Focus the next patch.
skipOne :: InteractiveSelectionM p wX wY ()
skipOne :: InteractiveSelectionM p wX wY ()
skipOne = (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify InteractiveSelectionContext p wX wY
-> InteractiveSelectionContext p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> InteractiveSelectionContext p wX wY
so
    where so :: InteractiveSelectionContext p wX wY
-> InteractiveSelectionContext p wX wY
so x :: InteractiveSelectionContext p wX wY
x = InteractiveSelectionContext p wX wY
x{lps :: FZipper (LabelledPatch p) wX wY
lps = FZipper (LabelledPatch p) wX wY -> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY. FZipper p wX wY -> FZipper p wX wY
right (InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps InteractiveSelectionContext p wX wY
x), current :: Int
current = InteractiveSelectionContext p wX wY -> Int
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> Int
current InteractiveSelectionContext p wX wY
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+1}

-- | Focus the previous patch.
backOne :: InteractiveSelectionM p wX wY ()
backOne :: InteractiveSelectionM p wX wY ()
backOne = (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify InteractiveSelectionContext p wX wY
-> InteractiveSelectionContext p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> InteractiveSelectionContext p wX wY
so
    where so :: InteractiveSelectionContext p wX wY
-> InteractiveSelectionContext p wX wY
so isc :: InteractiveSelectionContext p wX wY
isc = InteractiveSelectionContext p wX wY
isc{lps :: FZipper (LabelledPatch p) wX wY
lps = FZipper (LabelledPatch p) wX wY -> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY. FZipper p wX wY -> FZipper p wX wY
left (InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps InteractiveSelectionContext p wX wY
isc), current :: Int
current = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max (InteractiveSelectionContext p wX wY -> Int
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> Int
current InteractiveSelectionContext p wX wY
iscInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) 0}

-- | Split the current patch (presumably a hunk), and add the replace it
-- with its parts.
splitCurrent :: Splitter p
             -> InteractiveSelectionM p wX wY ()
splitCurrent :: Splitter p -> InteractiveSelectionM p wX wY ()
splitCurrent s :: Splitter p
s = do
    FZipper lps_done :: RL (LabelledPatch p) wX wY
lps_done (lp :: LabelledPatch p wY wY
lp:>:lps_todo :: FL (LabelledPatch p) wY wY
lps_todo) <- (InteractiveSelectionContext p wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FZipper (LabelledPatch p) wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps
    case Splitter p
-> p wY wY -> Maybe (ByteString, ByteString -> Maybe (FL p wY wY))
forall (p :: * -> * -> *).
Splitter p
-> forall wX wY.
   p wX wY -> Maybe (ByteString, ByteString -> Maybe (FL p wX wY))
applySplitter Splitter p
s (LabelledPatch p wY wY -> p wY wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel LabelledPatch p wY wY
lp) of
      Nothing -> () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just (text :: ByteString
text, parse :: ByteString -> Maybe (FL p wY wY)
parse) ->
          do
            ByteString
newText <- IO ByteString
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString
 -> StateT
      (InteractiveSelectionContext p wX wY)
      (PatchSelectionM p IO)
      ByteString)
-> IO ByteString
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     ByteString
forall a b. (a -> b) -> a -> b
$ String -> ByteString -> IO ByteString
editText "darcs-patch-edit" ByteString
text
            case ByteString -> Maybe (FL p wY wY)
parse ByteString
newText of
               Nothing -> () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
               Just ps :: FL p wY wY
ps -> do
                 FL (LabelledPatch p) wY wY
lps_new <- IO (FL (LabelledPatch p) wY wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FL (LabelledPatch p) wY wY)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (FL (LabelledPatch p) wY wY)
 -> StateT
      (InteractiveSelectionContext p wX wY)
      (PatchSelectionM p IO)
      (FL (LabelledPatch p) wY wY))
-> IO (FL (LabelledPatch p) wY wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FL (LabelledPatch p) wY wY)
forall a b. (a -> b) -> a -> b
$ FL (LabelledPatch p) wY wY -> IO (FL (LabelledPatch p) wY wY)
forall (m :: * -> *) a. Monad m => a -> m a
return (FL (LabelledPatch p) wY wY -> IO (FL (LabelledPatch p) wY wY))
-> FL (LabelledPatch p) wY wY -> IO (FL (LabelledPatch p) wY wY)
forall a b. (a -> b) -> a -> b
$ Maybe Label -> FL p wY wY -> FL (LabelledPatch p) wY wY
forall (p :: * -> * -> *) wX wY.
Maybe Label -> FL p wX wY -> FL (LabelledPatch p) wX wY
labelPatches (Label -> Maybe Label
forall a. a -> Maybe a
Just (LabelledPatch p wY wY -> Label
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> Label
label LabelledPatch p wY wY
lp)) FL p wY wY
ps
                 (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc { total :: Int
total = InteractiveSelectionContext p wX wY -> Int
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> Int
total InteractiveSelectionContext p wX wY
isc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FL (LabelledPatch p) wY wY -> Int
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Int
lengthFL FL (LabelledPatch p) wY wY
lps_new Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1
                                      , lps :: FZipper (LabelledPatch p) wX wY
lps = RL (LabelledPatch p) wX wY
-> FL (LabelledPatch p) wY wY -> FZipper (LabelledPatch p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> FL a wY wZ -> FZipper a wX wZ
FZipper RL (LabelledPatch p) wX wY
lps_done
                                               (FL (LabelledPatch p) wY wY
lps_new FL (LabelledPatch p) wY wY
-> FL (LabelledPatch p) wY wY -> FL (LabelledPatch p) wY wY
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (LabelledPatch p) wY wY
lps_todo)
                                      , choices :: PatchChoices p wX wY
choices = Sealed2 (LabelledPatch p :||: FL (LabelledPatch p))
-> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
Sealed2 (LabelledPatch p :||: FL (LabelledPatch p))
-> PatchChoices p wX wY -> PatchChoices p wX wY
substitute
                                                   ((:||:) (LabelledPatch p) (FL (LabelledPatch p)) wY wY
-> Sealed2 (LabelledPatch p :||: FL (LabelledPatch p))
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
seal2 (LabelledPatch p wY wY
lp LabelledPatch p wY wY
-> FL (LabelledPatch p) wY wY
-> (:||:) (LabelledPatch p) (FL (LabelledPatch p)) wY wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY.
a1 wX wY -> a2 wX wY -> (:||:) a1 a2 wX wY
:||: FL (LabelledPatch p) wY wY
lps_new))
                                                   (InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices InteractiveSelectionContext p wX wY
isc)
                                      }

-- | Shows the patch that is actually being selected the way the user
-- should see it.
repr :: Invert p => WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
repr :: WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
repr w :: WhichChanges
w p :: LabelledPatch p wX wY
p
  | WhichChanges -> Bool
reversed WhichChanges
w = p wY wX -> Sealed2 p
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
Sealed2 (p wX wY -> p wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert (LabelledPatch p wX wY -> p wX wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel LabelledPatch p wX wY
p))
  | Bool
otherwise = p wX wY -> Sealed2 p
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
Sealed2 (LabelledPatch p wX wY -> p wX wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel LabelledPatch p wX wY
p)

-- | Returns a list of the currently selected patches, in
-- their original context, i.e., not commuted past unselected
-- patches.
selected :: (Commute p, Invert p) => InteractiveSelectionM p wX wY [Sealed2 p]
selected :: InteractiveSelectionM p wX wY [Sealed2 p]
selected = do
  WhichChanges
w <- (PatchSelectionContext p -> WhichChanges)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     WhichChanges
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> WhichChanges
forall (p :: * -> * -> *). PatchSelectionContext p -> WhichChanges
whichChanges
  PatchChoices p wX wY
chs <- (InteractiveSelectionContext p wX wY -> PatchChoices p wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (PatchChoices p wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices
  (first_chs :: FL (LabelledPatch p) wX wZ
first_chs :> _ :> last_chs :: FL (LabelledPatch p) wZ wY
last_chs) <- (:>)
  (FL (LabelledPatch p))
  (FL (LabelledPatch p) :> FL (LabelledPatch p))
  wX
  wY
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     ((:>)
        (FL (LabelledPatch p))
        (FL (LabelledPatch p) :> FL (LabelledPatch p))
        wX
        wY)
forall (m :: * -> *) a. Monad m => a -> m a
return ((:>)
   (FL (LabelledPatch p))
   (FL (LabelledPatch p) :> FL (LabelledPatch p))
   wX
   wY
 -> StateT
      (InteractiveSelectionContext p wX wY)
      (PatchSelectionM p IO)
      ((:>)
         (FL (LabelledPatch p))
         (FL (LabelledPatch p) :> FL (LabelledPatch p))
         wX
         wY))
-> (:>)
     (FL (LabelledPatch p))
     (FL (LabelledPatch p) :> FL (LabelledPatch p))
     wX
     wY
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     ((:>)
        (FL (LabelledPatch p))
        (FL (LabelledPatch p) :> FL (LabelledPatch p))
        wX
        wY)
forall a b. (a -> b) -> a -> b
$ PatchChoices p wX wY
-> (:>)
     (FL (LabelledPatch p))
     (FL (LabelledPatch p) :> FL (LabelledPatch p))
     wX
     wY
forall (p :: * -> * -> *) wX wY.
Commute p =>
PatchChoices p wX wY
-> (:>)
     (FL (LabelledPatch p))
     (FL (LabelledPatch p) :> FL (LabelledPatch p))
     wX
     wY
getChoices PatchChoices p wX wY
chs
  [Sealed2 p] -> InteractiveSelectionM p wX wY [Sealed2 p]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Sealed2 p] -> InteractiveSelectionM p wX wY [Sealed2 p])
-> [Sealed2 p] -> InteractiveSelectionM p wX wY [Sealed2 p]
forall a b. (a -> b) -> a -> b
$ if WhichChanges -> Bool
backward WhichChanges
w then (forall wW wZ. LabelledPatch p wW wZ -> Sealed2 p)
-> FL (LabelledPatch p) wZ wY -> [Sealed2 p]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL (WhichChanges -> LabelledPatch p wW wZ -> Sealed2 p
forall (p :: * -> * -> *) wX wY.
Invert p =>
WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
repr WhichChanges
w) FL (LabelledPatch p) wZ wY
last_chs else (forall wW wZ. LabelledPatch p wW wZ -> Sealed2 p)
-> FL (LabelledPatch p) wX wZ -> [Sealed2 p]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL (WhichChanges -> LabelledPatch p wW wZ -> Sealed2 p
forall (p :: * -> * -> *) wX wY.
Invert p =>
WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
repr WhichChanges
w) FL (LabelledPatch p) wX wZ
first_chs

-- | Prints the list of the selected patches. See 'selected'.
printSelected :: (Invert p, Commute p, ShowPatch p) =>
                InteractiveSelectionM p wX wY ()
printSelected :: InteractiveSelectionM p wX wY ()
printSelected = do
  String
someThings <- InteractiveSelectionM p wX wY String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
things
  PatchSelectionOptions
o <- (PatchSelectionContext p -> PatchSelectionOptions)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     PatchSelectionOptions
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> PatchSelectionOptions
forall (p :: * -> * -> *).
PatchSelectionContext p -> PatchSelectionOptions
opts
  [Sealed2 p]
s <- InteractiveSelectionM p wX wY [Sealed2 p]
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p) =>
InteractiveSelectionM p wX wY [Sealed2 p]
selected
  IO () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> InteractiveSelectionM p wX wY ())
-> IO () -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ do
    Printers -> Doc -> IO ()
putDocLnWith Printers
fancyPrinters (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Doc
greenText (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ "---- selected "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
someThingsString -> ShowS
forall a. [a] -> [a] -> [a]
++" ----"
    (Sealed2 p -> IO ()) -> [Sealed2 p] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Printers -> Doc -> IO ()
putDocLnWith Printers
fancyPrinters (Doc -> IO ()) -> (Sealed2 p -> Doc) -> Sealed2 p -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wX wY. p wX wY -> Doc) -> Sealed2 p -> Doc
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 (Verbosity -> Summary -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Verbosity -> Summary -> p wX wY -> Doc
showFriendly (PatchSelectionOptions -> Verbosity
verbosity PatchSelectionOptions
o) (PatchSelectionOptions -> Summary
summary PatchSelectionOptions
o))) [Sealed2 p]
s
    Printers -> Doc -> IO ()
putDocLnWith Printers
fancyPrinters (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Doc
greenText (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ "---- end of selected "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
someThingsString -> ShowS
forall a. [a] -> [a] -> [a]
++" ----"

printSummary :: ShowPatch p => p wX wY -> IO ()
printSummary :: p wX wY -> IO ()
printSummary = Doc -> IO ()
putDocLn (Doc -> IO ()) -> (p wX wY -> Doc) -> p wX wY -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> Doc
prefix "    " (Doc -> Doc) -> (p wX wY -> Doc) -> p wX wY -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
Darcs.Patch.summary

-- | Skips all remaining patches.
skipAll ::  InteractiveSelectionM p wX wY ()
skipAll :: InteractiveSelectionM p wX wY ()
skipAll = (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc {lps :: FZipper (LabelledPatch p) wX wY
lps = FZipper (LabelledPatch p) wX wY -> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY. FZipper p wX wY -> FZipper p wX wY
toEnd (FZipper (LabelledPatch p) wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> FZipper (LabelledPatch p) wX wY
-> FZipper (LabelledPatch p) wX wY
forall a b. (a -> b) -> a -> b
$ InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps InteractiveSelectionContext p wX wY
isc}

backAll ::  InteractiveSelectionM p wX wY ()
backAll :: InteractiveSelectionM p wX wY ()
backAll = (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc {lps :: FZipper (LabelledPatch p) wX wY
lps = FZipper (LabelledPatch p) wX wY -> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY. FZipper p wX wY -> FZipper p wX wY
toStart (FZipper (LabelledPatch p) wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> FZipper (LabelledPatch p) wX wY
-> FZipper (LabelledPatch p) wX wY
forall a b. (a -> b) -> a -> b
$ InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps InteractiveSelectionContext p wX wY
isc
                               ,current :: Int
current = 0}

isSingleFile :: PatchInspect p => p wX wY -> Bool
isSingleFile :: p wX wY -> Bool
isSingleFile p :: p wX wY
p = [String] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (p wX wY -> [String]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [String]
listTouchedFiles p wX wY
p) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 1

askConfirmation ::  InteractiveSelectionM p wX wY ()
askConfirmation :: InteractiveSelectionM p wX wY ()
askConfirmation = do
    String
jn <- (PatchSelectionContext p -> String)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> String
forall (p :: * -> * -> *). PatchSelectionContext p -> String
jobname
    IO () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> InteractiveSelectionM p wX wY ())
-> IO () -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String
jn String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["unpull", "unrecord", "obliterate"]) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
               String
yorn <- String -> IO String
askUser (String -> IO String) -> String -> IO String
forall a b. (a -> b) -> a -> b
$ "Really " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " all undecided patches? "
               case String
yorn of
                 ('y':_) -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                 _ -> IO ()
forall a. IO a
exitSuccess

-- | The singular form of the noun for items of type @p@.
thing :: (ShowPatch p) => InteractiveSelectionM p wX wY String
thing :: InteractiveSelectionM p wX wY String
thing = (p wX wY -> String
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> String
Darcs.Patch.thing (p wX wY -> String)
-> (PatchChoices p wX wY -> p wX wY)
-> PatchChoices p wX wY
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchChoices p wA wB -> p wA wB
helper) (PatchChoices p wX wY -> String)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY String
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` (InteractiveSelectionContext p wX wY -> PatchChoices p wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (PatchChoices p wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices
        where
          helper :: PatchChoices p wA wB -> p wA wB
          helper :: PatchChoices p wA wB -> p wA wB
helper = PatchChoices p wA wB -> p wA wB
forall a. HasCallStack => a
undefined

-- | The plural form of the noun for items of type @p@.
things :: (ShowPatch p) => InteractiveSelectionM p wX wY String
things :: InteractiveSelectionM p wX wY String
things = (p wX wY -> String
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> String
Darcs.Patch.things (p wX wY -> String)
-> (PatchChoices p wX wY -> p wX wY)
-> PatchChoices p wX wY
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchChoices p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchChoices p wA wB -> p wA wB
helper) (PatchChoices p wX wY -> String)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY String
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` (InteractiveSelectionContext p wX wY -> PatchChoices p wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (PatchChoices p wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> PatchChoices p wX wY
choices
        where
          helper :: PatchChoices p wA wB -> p wA wB
          helper :: PatchChoices p wA wB -> p wA wB
helper = PatchChoices p wA wB -> p wA wB
forall a. HasCallStack => a
undefined

-- | The question to ask about one patch.
prompt :: (ShowPatch p) => InteractiveSelectionM p wX wY String
prompt :: InteractiveSelectionM p wX wY String
prompt = do
  String
jn <- (PatchSelectionContext p -> String)
-> InteractiveSelectionM p wX wY String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> String
forall (p :: * -> * -> *). PatchSelectionContext p -> String
jobname
  String
aThing <- InteractiveSelectionM p wX wY String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
thing
  Int
n <- (InteractiveSelectionContext p wX wY -> Int)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY -> Int
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> Int
current
  Int
n_max <- (InteractiveSelectionContext p wX wY -> Int)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY -> Int
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY -> Int
total
  String -> InteractiveSelectionM p wX wY String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> InteractiveSelectionM p wX wY String)
-> String -> InteractiveSelectionM p wX wY String
forall a b. (a -> b) -> a -> b
$ "Shall I "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++" this "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
aThingString -> ShowS
forall a. [a] -> [a] -> [a]
++"? "
             String -> ShowS
forall a. [a] -> [a] -> [a]
++ "(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) String -> ShowS
forall a. [a] -> [a] -> [a]
++ "/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n_max String -> ShowS
forall a. [a] -> [a] -> [a]
++ ") "

-- | Asks the user about one patch, returns their answer.
promptUser :: (ShowPatch p)
           => Bool -> Char -> InteractiveSelectionM p wX wY Char
promptUser :: Bool -> Char -> InteractiveSelectionM p wX wY Char
promptUser single :: Bool
single def :: Char
def = do
  String
thePrompt <- InteractiveSelectionM p wX wY String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
prompt
  (basicOptions :: [[KeyPress]]
basicOptions,advancedOptions :: [[KeyPress]]
advancedOptions) <- Bool -> InteractiveSelectionM p wX wY ([[KeyPress]], [[KeyPress]])
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Bool -> InteractiveSelectionM p wX wY ([[KeyPress]], [[KeyPress]])
options Bool
single
  IO Char -> InteractiveSelectionM p wX wY Char
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Char -> InteractiveSelectionM p wX wY Char)
-> IO Char -> InteractiveSelectionM p wX wY Char
forall a b. (a -> b) -> a -> b
$ PromptConfig -> IO Char
promptChar PromptConfig :: String -> String -> String -> Maybe Char -> String -> PromptConfig
PromptConfig { pPrompt :: String
pPrompt = String
thePrompt
                                   , pBasicCharacters :: String
pBasicCharacters = [[KeyPress]] -> String
keysFor [[KeyPress]]
basicOptions
                                   , pAdvancedCharacters :: String
pAdvancedCharacters = [[KeyPress]] -> String
keysFor [[KeyPress]]
advancedOptions
                                   , pDefault :: Maybe Char
pDefault = Char -> Maybe Char
forall a. a -> Maybe a
Just Char
def
                                   , pHelp :: String
pHelp = "?h"
                                   }

-- | Ask the user what to do with the next patch.
textSelectOne :: ( Invert p, Commute p, ShowPatch p, ShowContextPatch p, PatchInspect p
                 , ApplyState p ~ Tree )
              => InteractiveSelectionM p wX wY Bool
textSelectOne :: InteractiveSelectionM p wX wY Bool
textSelectOne = do
 Maybe (Sealed2 (LabelledPatch p))
c <- InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
currentPatch
 case Maybe (Sealed2 (LabelledPatch p))
c of
   Nothing -> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
   Just (Sealed2 lp :: LabelledPatch p wX wY
lp) ->
       do
         String
jn <- (PatchSelectionContext p -> String)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> String
forall (p :: * -> * -> *). PatchSelectionContext p -> String
jobname
         Maybe (Splitter p)
spl <- (PatchSelectionContext p -> Maybe (Splitter p))
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (Maybe (Splitter p))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> Maybe (Splitter p)
forall (p :: * -> * -> *).
PatchSelectionContext p -> Maybe (Splitter p)
splitter
         WhichChanges
whichch <- (PatchSelectionContext p -> WhichChanges)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     WhichChanges
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> WhichChanges
forall (p :: * -> * -> *). PatchSelectionContext p -> WhichChanges
whichChanges
         let singleFile :: Bool
singleFile = p wX wY -> Bool
forall (p :: * -> * -> *) wX wY. PatchInspect p => p wX wY -> Bool
isSingleFile (LabelledPatch p wX wY -> p wX wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel LabelledPatch p wX wY
lp)
             reprCur :: Sealed2 p
reprCur = WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
forall (p :: * -> * -> *) wX wY.
Invert p =>
WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
repr WhichChanges
whichch LabelledPatch p wX wY
lp
         (basicOptions :: [[KeyPress]]
basicOptions,advancedOptions :: [[KeyPress]]
advancedOptions) <- Bool -> InteractiveSelectionM p wX wY ([[KeyPress]], [[KeyPress]])
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Bool -> InteractiveSelectionM p wX wY ([[KeyPress]], [[KeyPress]])
options Bool
singleFile
         Slot
theSlot <- StateT (PatchChoices p wX wY) Identity Slot
-> InteractiveSelectionM p wX wY Slot
forall (p :: * -> * -> *) wX wY a.
StateT (PatchChoices p wX wY) Identity a
-> InteractiveSelectionM p wX wY a
liftChoices (StateT (PatchChoices p wX wY) Identity Slot
 -> InteractiveSelectionM p wX wY Slot)
-> StateT (PatchChoices p wX wY) Identity Slot
-> InteractiveSelectionM p wX wY Slot
forall a b. (a -> b) -> a -> b
$ (PatchChoices p wX wY -> (Slot, PatchChoices p wX wY))
-> StateT (PatchChoices p wX wY) Identity Slot
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((PatchChoices p wX wY -> (Slot, PatchChoices p wX wY))
 -> StateT (PatchChoices p wX wY) Identity Slot)
-> (PatchChoices p wX wY -> (Slot, PatchChoices p wX wY))
-> StateT (PatchChoices p wX wY) Identity Slot
forall a b. (a -> b) -> a -> b
$ LabelledPatch p wX wY
-> PatchChoices p wX wY -> (Slot, PatchChoices p wX wY)
forall (p :: * -> * -> *) wA wB wX wY.
Commute p =>
LabelledPatch p wA wB
-> PatchChoices p wX wY -> (Slot, PatchChoices p wX wY)
patchSlot LabelledPatch p wX wY
lp
         let the_default :: Char
the_default = Bool -> Slot -> Char
getDefault (WhichChanges -> Bool
backward WhichChanges
whichch) Slot
theSlot
         Char
yorn <- Bool -> Char -> InteractiveSelectionM p wX wY Char
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Bool -> Char -> InteractiveSelectionM p wX wY Char
promptUser Bool
singleFile Char
the_default
         let nextPatch :: StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
nextPatch = StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (p :: * -> * -> *) wX wY.
(Commute p, ShowPatch p) =>
InteractiveSelectionM p wX wY ()
skipMundane StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur
         case Char
yorn of
               'y' -> Bool -> LabelledPatch p wX wY -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wT wU wX wY.
Commute p =>
Bool -> LabelledPatch p wT wU -> InteractiveSelectionM p wX wY ()
decide Bool
True LabelledPatch p wX wY
lp InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
skipOne InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall wX wY.
StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
nextPatch
                      InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'n' -> Bool -> LabelledPatch p wX wY -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wT wU wX wY.
Commute p =>
Bool -> LabelledPatch p wT wU -> InteractiveSelectionM p wX wY ()
decide Bool
False LabelledPatch p wX wY
lp InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
skipOne InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall wX wY.
StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
nextPatch
                      InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'w' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
Commute p =>
InteractiveSelectionM p wX wY ()
postponeNext InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
skipOne InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall wX wY.
StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
nextPatch
                      InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'e' | (Just s :: Splitter p
s) <- Maybe (Splitter p)
spl -> Splitter p -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
Splitter p -> InteractiveSelectionM p wX wY ()
splitCurrent Splitter p
s InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur
                                        InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               's' -> InteractiveSelectionM p wX wY (Maybe String)
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
InteractiveSelectionM p wX wY (Maybe String)
currentFile InteractiveSelectionM p wX wY (Maybe String)
-> (Maybe String -> InteractiveSelectionM p wX wY ())
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= InteractiveSelectionM p wX wY ()
-> (String -> InteractiveSelectionM p wX wY ())
-> Maybe String
-> InteractiveSelectionM p wX wY ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                       (() -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
                       (\f :: String
f -> String -> Bool -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Commute p, PatchInspect p) =>
String -> Bool -> InteractiveSelectionM p wX wY ()
decideWholeFile String
f Bool
False) InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall wX wY.
StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
nextPatch
                       InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'f' -> InteractiveSelectionM p wX wY (Maybe String)
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
InteractiveSelectionM p wX wY (Maybe String)
currentFile InteractiveSelectionM p wX wY (Maybe String)
-> (Maybe String -> InteractiveSelectionM p wX wY ())
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= InteractiveSelectionM p wX wY ()
-> (String -> InteractiveSelectionM p wX wY ())
-> Maybe String
-> InteractiveSelectionM p wX wY ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                       (() -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
                       (\f :: String
f -> String -> Bool -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Commute p, PatchInspect p) =>
String -> Bool -> InteractiveSelectionM p wX wY ()
decideWholeFile String
f Bool
True) InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall wX wY.
StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) ()
nextPatch
                       InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'v' -> IO Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> InteractiveSelectionM p wX wY Bool)
-> IO Bool -> InteractiveSelectionM p wX wY Bool
forall a b. (a -> b) -> a -> b
$ (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatch Sealed2 p
reprCur IO () -> IO Bool -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'p' -> IO Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> InteractiveSelectionM p wX wY Bool)
-> IO Bool -> InteractiveSelectionM p wX wY Bool
forall a b. (a -> b) -> a -> b
$ (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatchPager Sealed2 p
reprCur IO () -> IO Bool -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'l' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, Commute p, ShowPatch p) =>
InteractiveSelectionM p wX wY ()
printSelected InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'x' -> IO Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> InteractiveSelectionM p wX wY Bool)
-> IO Bool -> InteractiveSelectionM p wX wY Bool
forall a b. (a -> b) -> a -> b
$ (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printSummary Sealed2 p
reprCur IO () -> IO Bool -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'd' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
skipAll InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
               'g' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
backAll InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'a' ->
                   do
                     InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
askConfirmation
                     (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
modifyChoices ((PatchChoices p wX wY -> PatchChoices p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (PatchChoices p wX wY -> PatchChoices p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Bool -> PatchChoices p wX wY -> PatchChoices p wX wY
forall (p :: * -> * -> *) wX wY.
Commute p =>
Bool -> PatchChoices p wX wY -> PatchChoices p wX wY
selectAllMiddles (WhichChanges -> Bool
backward WhichChanges
whichch)
                     InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
skipAll
                     Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
               'q' -> IO Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> InteractiveSelectionM p wX wY Bool)
-> IO Bool -> InteractiveSelectionM p wX wY Bool
forall a b. (a -> b) -> a -> b
$
                      do String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ ShowS
capitalize String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " cancelled."
                         IO Bool
forall a. IO a
exitSuccess
               'j' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
skipOne InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'k' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
backOne InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               _   -> do
                 IO () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> InteractiveSelectionM p wX wY ())
-> (String -> IO ()) -> String -> InteractiveSelectionM p wX wY ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
putStrLn (String -> InteractiveSelectionM p wX wY ())
-> String -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ String -> [[KeyPress]] -> [[KeyPress]] -> String
helpFor String
jn [[KeyPress]]
basicOptions [[KeyPress]]
advancedOptions
                 Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

lastQuestion :: (Commute p, Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree)
             => InteractiveSelectionM p wX wY Bool
lastQuestion :: InteractiveSelectionM p wX wY Bool
lastQuestion = do
  String
jn <- (PatchSelectionContext p -> String)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> String
forall (p :: * -> * -> *). PatchSelectionContext p -> String
jobname
  String
theThings <-StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
things
  String
aThing <- StateT
  (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
InteractiveSelectionM p wX wY String
thing
  let (basicOptions :: [[KeyPress]]
basicOptions, advancedOptions :: [[KeyPress]]
advancedOptions) = String -> String -> ([[KeyPress]], [[KeyPress]])
optionsLast String
jn String
aThing
  Char
yorn <- IO Char
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Char
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Char
 -> StateT
      (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Char)
-> (PromptConfig -> IO Char)
-> PromptConfig
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PromptConfig -> IO Char
promptChar (PromptConfig
 -> StateT
      (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Char)
-> PromptConfig
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) Char
forall a b. (a -> b) -> a -> b
$
            PromptConfig :: String -> String -> String -> Maybe Char -> String -> PromptConfig
PromptConfig { pPrompt :: String
pPrompt = "Do you want to "String -> ShowS
forall a. [a] -> [a] -> [a]
++ShowS
capitalize String
jnString -> ShowS
forall a. [a] -> [a] -> [a]
++
                                      " these "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
theThingsString -> ShowS
forall a. [a] -> [a] -> [a]
++"?"
                         , pBasicCharacters :: String
pBasicCharacters = "yglqk"
                         , pAdvancedCharacters :: String
pAdvancedCharacters = "dan"
                         , pDefault :: Maybe Char
pDefault = Char -> Maybe Char
forall a. a -> Maybe a
Just 'y'
                         , pHelp :: String
pHelp = "?h"}
  case Char
yorn of c :: Char
c | Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` "yda" -> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
                 | Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` "qn" -> IO Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> InteractiveSelectionM p wX wY Bool)
-> IO Bool -> InteractiveSelectionM p wX wY Bool
forall a b. (a -> b) -> a -> b
$
                                    do String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++" cancelled."
                                       IO Bool
forall a. IO a
exitSuccess
               'g' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
backAll InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'l' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, Commute p, ShowPatch p) =>
InteractiveSelectionM p wX wY ()
printSelected InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               'k' -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY. InteractiveSelectionM p wX wY ()
backOne InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
(Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
InteractiveSelectionM p wX wY ()
showCur InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY Bool
-> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
               _ -> do
                 IO () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> InteractiveSelectionM p wX wY ())
-> (String -> IO ()) -> String -> InteractiveSelectionM p wX wY ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
putStrLn (String -> InteractiveSelectionM p wX wY ())
-> String -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ String -> [[KeyPress]] -> [[KeyPress]] -> String
helpFor "this confirmation prompt"
                    [[KeyPress]]
basicOptions [[KeyPress]]
advancedOptions
                 Bool -> InteractiveSelectionM p wX wY Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

-- | Shows the current patch as it should be seen by the user.
showCur :: (Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree)
        => InteractiveSelectionM p wX wY ()
showCur :: InteractiveSelectionM p wX wY ()
showCur = do
  PatchSelectionOptions
o <- (PatchSelectionContext p -> PatchSelectionOptions)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     PatchSelectionOptions
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> PatchSelectionOptions
forall (p :: * -> * -> *).
PatchSelectionContext p -> PatchSelectionOptions
opts
  Maybe (Tree IO)
p <- (PatchSelectionContext p -> Maybe (Tree IO))
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (Maybe (Tree IO))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> Maybe (Tree IO)
forall (p :: * -> * -> *).
PatchSelectionContext p -> Maybe (Tree IO)
pristine
  Maybe (Sealed2 (LabelledPatch p))
c <- InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p)))
currentPatch
  WhichChanges
whichch <- (PatchSelectionContext p -> WhichChanges)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     WhichChanges
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> WhichChanges
forall (p :: * -> * -> *). PatchSelectionContext p -> WhichChanges
whichChanges
  case Maybe (Sealed2 (LabelledPatch p))
c of
      Nothing -> () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just (Sealed2 lp :: LabelledPatch p wX wY
lp) -> do
             let reprCur :: Sealed2 p
reprCur = WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
forall (p :: * -> * -> *) wX wY.
Invert p =>
WhichChanges -> LabelledPatch p wX wY -> Sealed2 p
repr WhichChanges
whichch LabelledPatch p wX wY
lp
             IO () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> InteractiveSelectionM p wX wY ())
-> (Sealed2 p -> IO ())
-> Sealed2 p
-> InteractiveSelectionM p wX wY ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 (Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY.
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
printFriendly Maybe (Tree IO)
p (PatchSelectionOptions -> Verbosity
verbosity PatchSelectionOptions
o) (PatchSelectionOptions -> Summary
summary PatchSelectionOptions
o) (PatchSelectionOptions -> WithContext
withContext PatchSelectionOptions
o)) (Sealed2 p -> InteractiveSelectionM p wX wY ())
-> Sealed2 p -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ Sealed2 p
reprCur

-- | The interactive part of @darcs changes@
textView :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree)
         => PatchSelectionOptions -> Maybe Int -> Int
         -> [Sealed2 p] -> [Sealed2 p]
         -> IO ()
textView :: PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView _ _ _ _ [] = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
textView o :: PatchSelectionOptions
o n_max :: Maybe Int
n_max n :: Int
n
            ps_done :: [Sealed2 p]
ps_done ps_todo :: [Sealed2 p]
ps_todo@(p :: Sealed2 p
p:ps_todo' :: [Sealed2 p]
ps_todo') = do
      (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 (Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY.
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
printFriendly Maybe (Tree IO)
forall a. Maybe a
Nothing (PatchSelectionOptions -> Verbosity
verbosity PatchSelectionOptions
o) (PatchSelectionOptions -> Summary
summary PatchSelectionOptions
o) (PatchSelectionOptions -> WithContext
withContext PatchSelectionOptions
o)) Sealed2 p
p
      IO ()
repeatThis -- prompt the user
    where
        prev_patch :: IO ()
        prev_patch :: IO ()
prev_patch = case [Sealed2 p]
ps_done of
                       [] -> IO ()
repeatThis
                       (p' :: Sealed2 p
p':ps_done' :: [Sealed2 p]
ps_done') ->
                         PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView PatchSelectionOptions
o
                            Maybe Int
n_max (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) [Sealed2 p]
ps_done' (Sealed2 p
p'Sealed2 p -> [Sealed2 p] -> [Sealed2 p]
forall a. a -> [a] -> [a]
:[Sealed2 p]
ps_todo)
        next_patch :: IO ()
        next_patch :: IO ()
next_patch = case [Sealed2 p]
ps_todo' of
                         [] -> -- May as well work out the length now we have all
                                  -- the patches in memory
                               PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView PatchSelectionOptions
o Maybe Int
n_max
                                   Int
n [Sealed2 p]
ps_done []
                         _ -> PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView PatchSelectionOptions
o Maybe Int
n_max
                                  (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) (Sealed2 p
pSealed2 p -> [Sealed2 p] -> [Sealed2 p]
forall a. a -> [a] -> [a]
:[Sealed2 p]
ps_done) [Sealed2 p]
ps_todo'
        first_patch :: IO ()
first_patch = PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView PatchSelectionOptions
o Maybe Int
n_max 0 [] ([Sealed2 p]
ps_done[Sealed2 p] -> [Sealed2 p] -> [Sealed2 p]
forall a. [a] -> [a] -> [a]
++[Sealed2 p]
ps_todo)
        options_yn :: [KeyPress]
options_yn =
          [ Char -> String -> KeyPress
KeyPress 'y' "view this patch and go to the next"
          , Char -> String -> KeyPress
KeyPress 'n' "skip to the next patch" ]
        optionsView' :: [KeyPress]
optionsView' =
          [ Char -> String -> KeyPress
KeyPress 'v' "view this patch in full"
          , Char -> String -> KeyPress
KeyPress 'p' "view this patch in full with pager" ]
        optionsSummary' :: [KeyPress]
optionsSummary' =
          [ Char -> String -> KeyPress
KeyPress 'x' "view a summary of this patch" ]
        optionsNav' :: [KeyPress]
optionsNav' =
          [ Char -> String -> KeyPress
KeyPress 'q' "quit view changes"
          , Char -> String -> KeyPress
KeyPress 'k' "back up to previous patch"
          , Char -> String -> KeyPress
KeyPress 'j' "skip to next patch"
          , Char -> String -> KeyPress
KeyPress 'g' "start over from the first patch"
          , Char -> String -> KeyPress
KeyPress 'c' "count total patch number" ]
        basicOptions :: [[KeyPress]]
basicOptions = [ [KeyPress]
options_yn ]
        advancedOptions :: [[KeyPress]]
advancedOptions =
                     ([KeyPress]
optionsView' [KeyPress] -> [KeyPress] -> [KeyPress]
forall a. [a] -> [a] -> [a]
++
                        if PatchSelectionOptions -> Summary
summary PatchSelectionOptions
o Summary -> Summary -> Bool
forall a. Eq a => a -> a -> Bool
== Summary
YesSummary then [] else [KeyPress]
optionsSummary')
                  [KeyPress] -> [[KeyPress]] -> [[KeyPress]]
forall a. a -> [a] -> [a]
: [ [KeyPress]
optionsNav' ]
        prompt' :: String
prompt' = "Shall I view this patch? "
               String -> ShowS
forall a. [a] -> [a] -> [a]
++ "(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) String -> ShowS
forall a. [a] -> [a] -> [a]
++ "/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String -> (Int -> String) -> Maybe Int -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe "?" Int -> String
forall a. Show a => a -> String
show Maybe Int
n_max String -> ShowS
forall a. [a] -> [a] -> [a]
++ ")"
        repeatThis :: IO ()
        repeatThis :: IO ()
repeatThis = do
          Char
yorn <- PromptConfig -> IO Char
promptChar (String -> String -> String -> Maybe Char -> String -> PromptConfig
PromptConfig String
prompt' ([[KeyPress]] -> String
keysFor [[KeyPress]]
basicOptions) ([[KeyPress]] -> String
keysFor [[KeyPress]]
advancedOptions) (Char -> Maybe Char
forall a. a -> Maybe a
Just 'n') "?h")
          case Char
yorn of
            'y' -> (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatch Sealed2 p
p IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
next_patch
            'n' -> IO ()
next_patch
            'v' -> (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatch Sealed2 p
p IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
repeatThis
            'p' -> (forall wX wY. p wX wY -> IO ()) -> Sealed2 p -> IO ()
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printPatchPager Sealed2 p
p IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
repeatThis
            'x' -> do Doc -> IO ()
putDocLn (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Doc -> Doc
prefix "    " (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ (forall wX wY. p wX wY -> Doc) -> Sealed2 p -> Doc
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
Darcs.Patch.summary Sealed2 p
p
                      IO ()
repeatThis
            'q' -> IO ()
forall a. IO a
exitSuccess
            'k' -> IO ()
prev_patch
            'j' -> IO ()
next_patch
            'g' -> IO ()
first_patch
            'c' -> PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions
-> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO ()
textView PatchSelectionOptions
o
                       Maybe Int
count_n_max Int
n [Sealed2 p]
ps_done [Sealed2 p]
ps_todo
            _   -> do String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> [[KeyPress]] -> [[KeyPress]] -> String
helpFor "view changes" [[KeyPress]]
basicOptions [[KeyPress]]
advancedOptions
                      IO ()
repeatThis
        count_n_max :: Maybe Int
count_n_max | Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust Maybe Int
n_max = Maybe Int
n_max
                    | Bool
otherwise    = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$ [Sealed2 p] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Sealed2 p]
ps_done Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Sealed2 p] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Sealed2 p]
ps_todo

-- | Skips patches we should not ask the user about
skipMundane :: (Commute p, ShowPatch p)
            => InteractiveSelectionM p wX wY ()
skipMundane :: InteractiveSelectionM p wX wY ()
skipMundane = do
  (FZipper lps_done :: RL (LabelledPatch p) wX wY
lps_done lps_todo :: FL (LabelledPatch p) wY wY
lps_todo) <- (InteractiveSelectionContext p wX wY
 -> FZipper (LabelledPatch p) wX wY)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (FZipper (LabelledPatch p) wX wY)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
forall (p :: * -> * -> *) wX wY.
InteractiveSelectionContext p wX wY
-> FZipper (LabelledPatch p) wX wY
lps
  PatchSelectionOptions
o <- (PatchSelectionContext p -> PatchSelectionOptions)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     PatchSelectionOptions
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> PatchSelectionOptions
forall (p :: * -> * -> *).
PatchSelectionContext p -> PatchSelectionOptions
opts
  MatchCriterion p
crit <- (PatchSelectionContext p -> MatchCriterion p)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     (MatchCriterion p)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> MatchCriterion p
forall (p :: * -> * -> *).
PatchSelectionContext p -> MatchCriterion p
matchCriterion
  String
jn <- (PatchSelectionContext p -> String)
-> StateT
     (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> String
forall (p :: * -> * -> *). PatchSelectionContext p -> String
jobname
  WhichChanges
whichch <- (PatchSelectionContext p -> WhichChanges)
-> StateT
     (InteractiveSelectionContext p wX wY)
     (PatchSelectionM p IO)
     WhichChanges
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks PatchSelectionContext p -> WhichChanges
forall (p :: * -> * -> *). PatchSelectionContext p -> WhichChanges
whichChanges
  (skipped :: FL (LabelledPatch p) wY wZ
skipped :> unskipped :: FL (LabelledPatch p) wZ wY
unskipped) <- StateT
  (PatchChoices p wX wY)
  Identity
  ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY)
-> InteractiveSelectionM
     p wX wY ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY)
forall (p :: * -> * -> *) wX wY a.
StateT (PatchChoices p wX wY) Identity a
-> InteractiveSelectionM p wX wY a
liftChoices (StateT
   (PatchChoices p wX wY)
   Identity
   ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY)
 -> InteractiveSelectionM
      p wX wY ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY))
-> StateT
     (PatchChoices p wX wY)
     Identity
     ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY)
-> InteractiveSelectionM
     p wX wY ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY)
forall a b. (a -> b) -> a -> b
$ (forall wW wY.
 LabelledPatch p wW wY
 -> StateT (PatchChoices p wX wY) Identity Bool)
-> FL (LabelledPatch p) wY wY
-> StateT
     (PatchChoices p wX wY)
     Identity
     ((:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wY wY)
forall (a :: * -> * -> *) (m :: * -> *) wX wZ.
Monad m =>
(forall wW wY. a wW wY -> m Bool)
-> FL a wX wZ -> m ((:>) (FL a) (FL a) wX wZ)
spanFL_M
                                 ((PatchChoices p wX wY -> (Slot, PatchChoices p wX wY))
-> StateT (PatchChoices p wX wY) Identity Slot
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((PatchChoices p wX wY -> (Slot, PatchChoices p wX wY))
 -> StateT (PatchChoices p wX wY) Identity Slot)
-> (LabelledPatch p wW wY
    -> PatchChoices p wX wY -> (Slot, PatchChoices p wX wY))
-> LabelledPatch p wW wY
-> StateT (PatchChoices p wX wY) Identity Slot
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LabelledPatch p wW wY
-> PatchChoices p wX wY -> (Slot, PatchChoices p wX wY)
forall (p :: * -> * -> *) wA wB wX wY.
Commute p =>
LabelledPatch p wA wB
-> PatchChoices p wX wY -> (Slot, PatchChoices p wX wY)
patchSlot (LabelledPatch p wW wY
 -> StateT (PatchChoices p wX wY) Identity Slot)
-> (Slot -> StateT (PatchChoices p wX wY) Identity Bool)
-> LabelledPatch p wW wY
-> StateT (PatchChoices p wX wY) Identity Bool
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Bool -> StateT (PatchChoices p wX wY) Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> StateT (PatchChoices p wX wY) Identity Bool)
-> (Slot -> Bool)
-> Slot
-> StateT (PatchChoices p wX wY) Identity Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Slot -> Bool
decided)
                                 FL (LabelledPatch p) wY wY
lps_todo
  let numSkipped :: Int
numSkipped = FL (LabelledPatch p) wY wZ -> Int
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Int
lengthFL FL (LabelledPatch p) wY wZ
skipped
  Bool
-> InteractiveSelectionM p wX wY ()
-> InteractiveSelectionM p wX wY ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
numSkipped Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0) (InteractiveSelectionM p wX wY ()
 -> InteractiveSelectionM p wX wY ())
-> (IO () -> InteractiveSelectionM p wX wY ())
-> IO ()
-> InteractiveSelectionM p wX wY ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO () -> InteractiveSelectionM p wX wY ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> InteractiveSelectionM p wX wY ())
-> IO () -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ PatchSelectionOptions
-> String -> Int -> FL (LabelledPatch p) wY wZ -> IO ()
forall (p :: * -> * -> *) wY wT.
ShowPatch p =>
PatchSelectionOptions
-> String -> Int -> FL (LabelledPatch p) wY wT -> IO ()
show_skipped PatchSelectionOptions
o String
jn Int
numSkipped FL (LabelledPatch p) wY wZ
skipped
  let boringThenInteresting :: (:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wZ wY
boringThenInteresting =
          if PatchSelectionOptions -> SelectDeps
selectDeps PatchSelectionOptions
o SelectDeps -> SelectDeps -> Bool
forall a. Eq a => a -> a -> Bool
== SelectDeps
AutoDeps
          then (forall wW wY. LabelledPatch p wW wY -> Bool)
-> FL (LabelledPatch p) wZ wY
-> (:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wZ wY
forall (a :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> Bool)
-> FL a wX wZ -> (:>) (FL a) (FL a) wX wZ
spanFL (Bool -> Bool
not(Bool -> Bool)
-> (LabelledPatch p wW wY -> Bool) -> LabelledPatch p wW wY -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatchCriterion p -> WhichChanges -> LabelledPatch p wW wY -> Bool
forall (p :: * -> * -> *).
MatchCriterion p
-> forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool
mcFunction MatchCriterion p
crit WhichChanges
whichch)
                                 FL (LabelledPatch p) wZ wY
unskipped
          else FL (LabelledPatch p) wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL FL (LabelledPatch p) wZ wZ
-> FL (LabelledPatch p) wZ wY
-> (:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wZ wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL (LabelledPatch p) wZ wY
unskipped
  case (:>) (FL (LabelledPatch p)) (FL (LabelledPatch p)) wZ wY
boringThenInteresting of
    boring :: FL (LabelledPatch p) wZ wZ
boring :> interesting :: FL (LabelledPatch p) wZ wY
interesting ->
        do
          Int -> InteractiveSelectionM p wX wY ()
forall (p :: * -> * -> *) wX wY.
Int -> InteractiveSelectionM p wX wY ()
justDone (Int -> InteractiveSelectionM p wX wY ())
-> Int -> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ FL (LabelledPatch p) wZ wZ -> Int
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Int
lengthFL FL (LabelledPatch p) wZ wZ
boring Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
numSkipped
          (InteractiveSelectionContext p wX wY
 -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((InteractiveSelectionContext p wX wY
  -> InteractiveSelectionContext p wX wY)
 -> InteractiveSelectionM p wX wY ())
-> (InteractiveSelectionContext p wX wY
    -> InteractiveSelectionContext p wX wY)
-> InteractiveSelectionM p wX wY ()
forall a b. (a -> b) -> a -> b
$ \isc :: InteractiveSelectionContext p wX wY
isc -> InteractiveSelectionContext p wX wY
isc {lps :: FZipper (LabelledPatch p) wX wY
lps = RL (LabelledPatch p) wX wZ
-> FL (LabelledPatch p) wZ wY -> FZipper (LabelledPatch p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> FL a wY wZ -> FZipper a wX wZ
FZipper (RL (LabelledPatch p) wX wY
lps_done RL (LabelledPatch p) wX wY
-> FL (LabelledPatch p) wY wZ -> RL (LabelledPatch p) wX wZ
forall (p :: * -> * -> *) wX wY wZ.
RL p wX wY -> FL p wY wZ -> RL p wX wZ
+<<+ FL (LabelledPatch p) wY wZ
skipped RL (LabelledPatch p) wX wZ
-> FL (LabelledPatch p) wZ wZ -> RL (LabelledPatch p) wX wZ
forall (p :: * -> * -> *) wX wY wZ.
RL p wX wY -> FL p wY wZ -> RL p wX wZ
+<<+ FL (LabelledPatch p) wZ wZ
boring)
                                      FL (LabelledPatch p) wZ wY
interesting}
    where
      show_skipped :: PatchSelectionOptions
-> String -> Int -> FL (LabelledPatch p) wY wT -> IO ()
show_skipped o :: PatchSelectionOptions
o jn :: String
jn n :: Int
n ps :: FL (LabelledPatch p) wY wT
ps = do String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ ShowS
_nevermind_ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
_these_ Int
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ "."
                                  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PatchSelectionOptions -> Verbosity
verbosity PatchSelectionOptions
o Verbosity -> Verbosity -> Bool
forall a. Eq a => a -> a -> Bool
== Verbosity
Verbose) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
                                       FL (LabelledPatch p) wY wT -> IO ()
forall (p :: * -> * -> *) wY wT.
ShowPatch p =>
FL (LabelledPatch p) wY wT -> IO ()
showskippedpatch FL (LabelledPatch p) wY wT
ps
      _nevermind_ :: ShowS
_nevermind_ jn :: String
jn = "Will not ask whether to " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
jn String -> ShowS
forall a. [a] -> [a] -> [a]
++ " "
      _these_ :: Int -> String
_these_ n :: Int
n  = Int -> String
forall a. Show a => a -> String
show Int
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ " already decided " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ShowS
_elem_ Int
n ""
      _elem_ :: Int -> ShowS
_elem_ n :: Int
n = Int -> Noun -> ShowS
forall n. Countable n => Int -> n -> ShowS
englishNum Int
n (String -> Noun
Noun "patch")
      showskippedpatch :: ShowPatch p => FL (LabelledPatch p) wY wT -> IO ()
      showskippedpatch :: FL (LabelledPatch p) wY wT -> IO ()
showskippedpatch = [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ ([IO ()] -> IO ())
-> (FL (LabelledPatch p) wY wT -> [IO ()])
-> FL (LabelledPatch p) wY wT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wW wZ. LabelledPatch p wW wZ -> IO ())
-> FL (LabelledPatch p) wY wT -> [IO ()]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL (p wW wZ -> IO ()
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printSummary (p wW wZ -> IO ())
-> (LabelledPatch p wW wZ -> p wW wZ)
-> LabelledPatch p wW wZ
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LabelledPatch p wW wZ -> p wW wZ
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel)

decided :: Slot -> Bool
decided :: Slot -> Bool
decided InMiddle = Bool
False
decided _ = Bool
True

-- | The action bound to space, depending on the current status of the
-- patch.
getDefault :: Bool -> Slot -> Char
getDefault :: Bool -> Slot -> Char
getDefault _ InMiddle = 'w'
getDefault True InFirst  = 'n'
getDefault True InLast   = 'y'
getDefault False InFirst = 'y'
getDefault False InLast  = 'n'

askAboutDepends :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree)
                => Repository rt p wR wU wT -> FL (PrimOf p) wT wY
                -> PatchSelectionOptions
                -> [PatchInfo] -> IO [PatchInfo]
askAboutDepends :: Repository rt p wR wU wT
-> FL (PrimOf p) wT wY
-> PatchSelectionOptions
-> [PatchInfo]
-> IO [PatchInfo]
askAboutDepends repository :: Repository rt p wR wU wT
repository pa' :: FL (PrimOf p) wT wY
pa' ps_opts :: PatchSelectionOptions
ps_opts olddeps :: [PatchInfo]
olddeps = do
  -- ideally we'd just default the olddeps to yes but still ask about them.
  -- SelectChanges doesn't currently (17/12/09) offer a way to do this so would
  -- have to have this support added first.
  PatchSet rt p Origin wT
pps <- Repository rt p wR wU wT -> String -> IO (PatchSet rt p Origin wT)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> String -> IO (PatchSet rt p Origin wT)
readTentativeRepo Repository rt p wR wU wT
repository (Repository rt p wR wU wT -> String
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> String
repoLocation Repository rt p wR wU wT
repository)
  PatchInfoAnd rt p wT wY
pa <- WrappedNamed rt p wT wY -> PatchInfoAnd rt p wT wY
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
WrappedNamed rt p wX wY -> PatchInfoAnd rt p wX wY
n2pia (WrappedNamed rt p wT wY -> PatchInfoAnd rt p wT wY)
-> IO (WrappedNamed rt p wT wY) -> IO (PatchInfoAnd rt p wT wY)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` FL p wT wY -> IO (WrappedNamed rt p wT wY)
forall (p :: * -> * -> *) wX wY (rt :: RepoType).
FL p wX wY -> IO (WrappedNamed rt p wX wY)
anonymous (FL (PrimOf (FL p)) wT wY -> FL p wT wY
forall (p :: * -> * -> *) wX wY.
FromPrims p =>
FL (PrimOf p) wX wY -> p wX wY
fromPrims FL (PrimOf p) wT wY
FL (PrimOf (FL p)) wT wY
pa')
  -- FIXME: this code is completely unreadable
  FlippedSeal ps :: FL (PatchInfoAnd rt p) wX wY
ps <-
    FlippedSeal (FL (PatchInfoAnd rt p)) wY
-> IO (FlippedSeal (FL (PatchInfoAnd rt p)) wY)
forall (m :: * -> *) a. Monad m => a -> m a
return (FlippedSeal (FL (PatchInfoAnd rt p)) wY
 -> IO (FlippedSeal (FL (PatchInfoAnd rt p)) wY))
-> FlippedSeal (FL (PatchInfoAnd rt p)) wY
-> IO (FlippedSeal (FL (PatchInfoAnd rt p)) wY)
forall a b. (a -> b) -> a -> b
$ case PatchSet rt p Origin wT
pps of PatchSet _ x :: RL (PatchInfoAnd rt p) wX wT
x -> FL (PatchInfoAnd rt p) wX wY
-> FlippedSeal (FL (PatchInfoAnd rt p)) wY
forall (a :: * -> * -> *) wX wY. a wX wY -> FlippedSeal a wY
FlippedSeal (RL (PatchInfoAnd rt p) wX wT
xRL (PatchInfoAnd rt p) wX wT
-> FL (PatchInfoAnd rt p) wT wY -> FL (PatchInfoAnd rt p) wX wY
forall (p :: * -> * -> *) wX wY wZ.
RL p wX wY -> FL p wY wZ -> FL p wX wZ
+>>+(PatchInfoAnd rt p wT wY
paPatchInfoAnd rt p wT wY
-> FL (PatchInfoAnd rt p) wY wY -> FL (PatchInfoAnd rt p) wT wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>:FL (PatchInfoAnd rt p) wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL))
  let my_lps :: FL (LabelledPatch (PatchInfoAnd rt p)) wX wY
my_lps = Maybe Label
-> FL (PatchInfoAnd rt p) wX wY
-> FL (LabelledPatch (PatchInfoAnd rt p)) wX wY
forall (p :: * -> * -> *) wX wY.
Maybe Label -> FL p wX wY -> FL (LabelledPatch p) wX wY
labelPatches Maybe Label
forall a. Maybe a
Nothing FL (PatchInfoAnd rt p) wX wY
ps
      pc :: PatchChoices (PatchInfoAnd rt p) wX wY
pc = FL (LabelledPatch (PatchInfoAnd rt p)) wX wY
-> PatchChoices (PatchInfoAnd rt p) wX wY
forall (p :: * -> * -> *) wX wY.
FL (LabelledPatch p) wX wY -> PatchChoices p wX wY
mkPatchChoices FL (LabelledPatch (PatchInfoAnd rt p)) wX wY
my_lps
      tas :: [Label]
tas =
        case [Maybe Label] -> [Label]
forall a. [Maybe a] -> [a]
catMaybes ((forall wW wZ.
 LabelledPatch (PatchInfoAnd rt p) wW wZ -> Maybe Label)
-> FL (LabelledPatch (PatchInfoAnd rt p)) wX wY -> [Maybe Label]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL (\lp :: LabelledPatch (PatchInfoAnd rt p) wW wZ
lp -> if PatchInfoAnd rt p wT wY
pa PatchInfoAnd rt p wT wY -> PatchInfoAnd rt p wW wZ -> Bool
forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` LabelledPatch (PatchInfoAnd rt p) wW wZ -> PatchInfoAnd rt p wW wZ
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel LabelledPatch (PatchInfoAnd rt p) wW wZ
lp Bool -> Bool -> Bool
|| PatchInfoAnd rt p wW wZ -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info (LabelledPatch (PatchInfoAnd rt p) wW wZ -> PatchInfoAnd rt p wW wZ
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel LabelledPatch (PatchInfoAnd rt p) wW wZ
lp) PatchInfo -> [PatchInfo] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [PatchInfo]
olddeps
                                          then Label -> Maybe Label
forall a. a -> Maybe a
Just (LabelledPatch (PatchInfoAnd rt p) wW wZ -> Label
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> Label
label LabelledPatch (PatchInfoAnd rt p) wW wZ
lp) else Maybe Label
forall a. Maybe a
Nothing) FL (LabelledPatch (PatchInfoAnd rt p)) wX wY
my_lps) of

                [] -> String -> [Label]
forall a. HasCallStack => String -> a
error "askAboutDepends: []"
                tgs :: [Label]
tgs -> [Label]
tgs
  Sealed2 ps' :: FL (PatchInfoAnd rt p) wX wY
ps' <- Sealed2 (FL (PatchInfoAnd rt p))
-> IO (Sealed2 (FL (PatchInfoAnd rt p)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed2 (FL (PatchInfoAnd rt p))
 -> IO (Sealed2 (FL (PatchInfoAnd rt p))))
-> Sealed2 (FL (PatchInfoAnd rt p))
-> IO (Sealed2 (FL (PatchInfoAnd rt p)))
forall a b. (a -> b) -> a -> b
$
    case PatchChoices (PatchInfoAnd rt p) wX wY
-> (:>)
     (FL (LabelledPatch (PatchInfoAnd rt p)))
     (FL (LabelledPatch (PatchInfoAnd rt p))
      :> FL (LabelledPatch (PatchInfoAnd rt p)))
     wX
     wY
forall (p :: * -> * -> *) wX wY.
Commute p =>
PatchChoices p wX wY
-> (:>)
     (FL (LabelledPatch p))
     (FL (LabelledPatch p) :> FL (LabelledPatch p))
     wX
     wY
getChoices ([Label]
-> PatchChoices (PatchInfoAnd rt p) wX wY
-> PatchChoices (PatchInfoAnd rt p) wX wY
forall (p :: * -> * -> *) wA wB.
Commute p =>
[Label] -> PatchChoices p wA wB -> PatchChoices p wA wB
forceFirsts [Label]
tas PatchChoices (PatchInfoAnd rt p) wX wY
pc) of
      _ :> mc :: FL (LabelledPatch (PatchInfoAnd rt p)) wZ wZ
mc :> _ -> FL (PatchInfoAnd rt p) wZ wZ -> Sealed2 (FL (PatchInfoAnd rt p))
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
Sealed2 (FL (PatchInfoAnd rt p) wZ wZ -> Sealed2 (FL (PatchInfoAnd rt p)))
-> FL (PatchInfoAnd rt p) wZ wZ -> Sealed2 (FL (PatchInfoAnd rt p))
forall a b. (a -> b) -> a -> b
$ (forall wW wY.
 LabelledPatch (PatchInfoAnd rt p) wW wY -> PatchInfoAnd rt p wW wY)
-> FL (LabelledPatch (PatchInfoAnd rt p)) wZ wZ
-> FL (PatchInfoAnd rt p) wZ wZ
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY.
LabelledPatch (PatchInfoAnd rt p) wW wY -> PatchInfoAnd rt p wW wY
forall (p :: * -> * -> *) wX wY. LabelledPatch p wX wY -> p wX wY
unLabel FL (LabelledPatch (PatchInfoAnd rt p)) wZ wZ
mc
  (deps :: FL (PatchInfoAnd rt p) wX wZ
deps:>_) <- FL (PatchInfoAnd rt p) wX wY
-> PatchSelectionContext (PatchInfoAnd rt p)
-> IO
     ((:>) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wX wY)
forall (p :: * -> * -> *) wX wY.
(Invert p, Commute p, Apply p, PatchInspect p, ShowPatch p,
 ShowContextPatch p, ApplyState p ~ Tree) =>
FL p wX wY
-> PatchSelectionContext p -> IO ((:>) (FL p) (FL p) wX wY)
runSelection FL (PatchInfoAnd rt p) wX wY
ps' (PatchSelectionContext (PatchInfoAnd rt p)
 -> IO
      ((:>) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wX wY))
-> PatchSelectionContext (PatchInfoAnd rt p)
-> IO
     ((:>) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wX wY)
forall a b. (a -> b) -> a -> b
$
                 WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PatchInfoAnd rt p))
-> Maybe [String]
-> PatchSelectionContext (PatchInfoAnd rt p)
forall (rt :: RepoType) (p :: * -> * -> *).
(IsRepoType rt, RepoPatch p) =>
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PatchInfoAnd rt p))
-> Maybe [String]
-> PatchSelectionContext (PatchInfoAnd rt p)
selectionContext WhichChanges
FirstReversed "depend on" PatchSelectionOptions
ps_opts
                    { matchFlags :: [MatchFlag]
matchFlags = [], interactive :: Bool
interactive = Bool
True } Maybe (Splitter (PatchInfoAnd rt p))
forall a. Maybe a
Nothing Maybe [String]
forall a. Maybe a
Nothing
  [PatchInfo] -> IO [PatchInfo]
forall (m :: * -> *) a. Monad m => a -> m a
return ([PatchInfo] -> IO [PatchInfo]) -> [PatchInfo] -> IO [PatchInfo]
forall a b. (a -> b) -> a -> b
$ [PatchInfo]
olddeps [PatchInfo] -> [PatchInfo] -> [PatchInfo]
forall a. Eq a => [a] -> [a] -> [a]
`union` (forall wW wZ. PatchInfoAnd rt p wW wZ -> PatchInfo)
-> FL (PatchInfoAnd rt p) wX wZ -> [PatchInfo]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL forall wW wZ. PatchInfoAnd rt p wW wZ -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info FL (PatchInfoAnd rt p) wX wZ
deps