Wrap cursor management into one function

This commit is contained in:
Joshua Clayton 2016-05-15 14:35:50 -04:00
parent 233f83bdf8
commit 2d65555b60
3 changed files with 9 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import Unused.Parser (parseLines)
import Unused.Types (ParseResponse, RemovalLikelihood(..))
import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths)
import Unused.Grouping (CurrentGrouping(..), groupedResponses)
import Unused.CLI (SearchRunner(..), renderHeader, executeSearch, printParseError, printSearchResults, resetScreen, withInterruptHandler)
import Unused.CLI (SearchRunner(..), withoutCursor, renderHeader, executeSearch, printParseError, printSearchResults, resetScreen, withInterruptHandler)
data Options = Options
{ oSearchRunner :: SearchRunner
@ -31,7 +31,7 @@ main = withInterruptHandler $
pFooter = "CLI USAGE: $ cat path/to/ctags | cut -f1 | sort -u | unused"
run :: Options -> IO ()
run options = do
run options = withoutCursor $ do
hSetBuffering stdout NoBuffering
terms <- pure . lines =<< getContents

View File

@ -13,13 +13,12 @@ data SearchRunner = SearchWithProgress | SearchWithoutProgress
renderHeader :: [String] -> IO ()
renderHeader terms = do
resetScreen
hideCursor
printAnalysisHeader terms
executeSearch :: SearchRunner -> [String] -> IO [String]
executeSearch runner terms = do
renderHeader terms
runSearch runner terms <* resetScreen <* showCursor
runSearch runner terms <* resetScreen
printAnalysisHeader :: [String] -> IO ()
printAnalysisHeader terms = do

View File

@ -1,5 +1,6 @@
module Unused.CLI.Util
( resetScreen
, withoutCursor
, withInterruptHandler
, module System.Console.ANSI
) where
@ -11,6 +12,11 @@ import System.Posix.Signals (Handler(Catch), installHandler, keyboardSignal)
import Control.Concurrent (ThreadId, myThreadId)
import System.Exit (ExitCode(ExitFailure))
withoutCursor :: IO a -> IO a
withoutCursor body = do
hideCursor
body <* showCursor
resetScreen :: IO ()
resetScreen = do
clearScreen