mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Wrap cursor management into one function
This commit is contained in:
parent
233f83bdf8
commit
2d65555b60
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user