mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-08-16 08:10:55 +03:00
Encapsulate runtime config into a withRuntime wrapper
This commit is contained in:
parent
09231cdccd
commit
ad9308a672
@ -1,7 +1,6 @@
|
||||
module Main where
|
||||
|
||||
import Options.Applicative
|
||||
import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Unused.Parser (parseResults)
|
||||
import Unused.Types (TermMatchSet, RemovalLikelihood(..))
|
||||
@ -9,7 +8,7 @@ import Unused.TermSearch (SearchResults(..), fromResults)
|
||||
import Unused.ResultsClassifier
|
||||
import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths)
|
||||
import Unused.Grouping (CurrentGrouping(..), groupedResponses)
|
||||
import Unused.CLI (SearchRunner(..), withoutCursor, renderHeader, executeSearch, withInterruptHandler)
|
||||
import Unused.CLI (SearchRunner(..), withRuntime, renderHeader, executeSearch)
|
||||
import qualified Unused.CLI.Views as V
|
||||
import Unused.Cache
|
||||
import Unused.Aliases (termsAndAliases)
|
||||
@ -27,7 +26,7 @@ data Options = Options
|
||||
}
|
||||
|
||||
main :: IO ()
|
||||
main = withInterruptHandler $
|
||||
main =
|
||||
run =<< execParser
|
||||
(withInfo parseOptions pHeader pDescription pFooter)
|
||||
where
|
||||
@ -38,9 +37,7 @@ main = withInterruptHandler $
|
||||
pFooter = "CLI USAGE: $ unused"
|
||||
|
||||
run :: Options -> IO ()
|
||||
run options = withoutCursor $ do
|
||||
hSetBuffering stdout NoBuffering
|
||||
|
||||
run options = withRuntime $ do
|
||||
terms' <- calculateTagInput options
|
||||
|
||||
case terms' of
|
||||
|
@ -1,28 +1,33 @@
|
||||
module Unused.CLI.Util
|
||||
( resetScreen
|
||||
, withoutCursor
|
||||
, withInterruptHandler
|
||||
, withRuntime
|
||||
, installChildInterruptHandler
|
||||
, module System.Console.ANSI
|
||||
) where
|
||||
|
||||
import Control.Monad (void)
|
||||
import System.Console.ANSI
|
||||
import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout)
|
||||
import Control.Exception (throwTo)
|
||||
import System.Posix.Signals (Handler(Catch), installHandler, keyboardSignal)
|
||||
import Control.Concurrent (ThreadId, myThreadId, killThread)
|
||||
import System.Exit (ExitCode(ExitFailure))
|
||||
|
||||
withoutCursor :: IO a -> IO a
|
||||
withoutCursor body = do
|
||||
hideCursor
|
||||
body <* showCursor
|
||||
withRuntime :: IO a -> IO a
|
||||
withRuntime a = do
|
||||
hSetBuffering stdout NoBuffering
|
||||
withInterruptHandler $ withoutCursor a
|
||||
|
||||
resetScreen :: IO ()
|
||||
resetScreen = do
|
||||
clearScreen
|
||||
setCursorPosition 0 0
|
||||
|
||||
withoutCursor :: IO a -> IO a
|
||||
withoutCursor body = do
|
||||
hideCursor
|
||||
body <* showCursor
|
||||
|
||||
withInterruptHandler :: IO a -> IO a
|
||||
withInterruptHandler body = do
|
||||
tid <- myThreadId
|
||||
|
Loading…
Reference in New Issue
Block a user