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.Types (ParseResponse, RemovalLikelihood(..))
|
||||||
import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths)
|
import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths)
|
||||||
import Unused.Grouping (CurrentGrouping(..), groupedResponses)
|
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
|
data Options = Options
|
||||||
{ oSearchRunner :: SearchRunner
|
{ oSearchRunner :: SearchRunner
|
||||||
@ -31,7 +31,7 @@ main = withInterruptHandler $
|
|||||||
pFooter = "CLI USAGE: $ cat path/to/ctags | cut -f1 | sort -u | unused"
|
pFooter = "CLI USAGE: $ cat path/to/ctags | cut -f1 | sort -u | unused"
|
||||||
|
|
||||||
run :: Options -> IO ()
|
run :: Options -> IO ()
|
||||||
run options = do
|
run options = withoutCursor $ do
|
||||||
hSetBuffering stdout NoBuffering
|
hSetBuffering stdout NoBuffering
|
||||||
|
|
||||||
terms <- pure . lines =<< getContents
|
terms <- pure . lines =<< getContents
|
||||||
|
@ -13,13 +13,12 @@ data SearchRunner = SearchWithProgress | SearchWithoutProgress
|
|||||||
renderHeader :: [String] -> IO ()
|
renderHeader :: [String] -> IO ()
|
||||||
renderHeader terms = do
|
renderHeader terms = do
|
||||||
resetScreen
|
resetScreen
|
||||||
hideCursor
|
|
||||||
printAnalysisHeader terms
|
printAnalysisHeader terms
|
||||||
|
|
||||||
executeSearch :: SearchRunner -> [String] -> IO [String]
|
executeSearch :: SearchRunner -> [String] -> IO [String]
|
||||||
executeSearch runner terms = do
|
executeSearch runner terms = do
|
||||||
renderHeader terms
|
renderHeader terms
|
||||||
runSearch runner terms <* resetScreen <* showCursor
|
runSearch runner terms <* resetScreen
|
||||||
|
|
||||||
printAnalysisHeader :: [String] -> IO ()
|
printAnalysisHeader :: [String] -> IO ()
|
||||||
printAnalysisHeader terms = do
|
printAnalysisHeader terms = do
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module Unused.CLI.Util
|
module Unused.CLI.Util
|
||||||
( resetScreen
|
( resetScreen
|
||||||
|
, withoutCursor
|
||||||
, withInterruptHandler
|
, withInterruptHandler
|
||||||
, module System.Console.ANSI
|
, module System.Console.ANSI
|
||||||
) where
|
) where
|
||||||
@ -11,6 +12,11 @@ import System.Posix.Signals (Handler(Catch), installHandler, keyboardSignal)
|
|||||||
import Control.Concurrent (ThreadId, myThreadId)
|
import Control.Concurrent (ThreadId, myThreadId)
|
||||||
import System.Exit (ExitCode(ExitFailure))
|
import System.Exit (ExitCode(ExitFailure))
|
||||||
|
|
||||||
|
withoutCursor :: IO a -> IO a
|
||||||
|
withoutCursor body = do
|
||||||
|
hideCursor
|
||||||
|
body <* showCursor
|
||||||
|
|
||||||
resetScreen :: IO ()
|
resetScreen :: IO ()
|
||||||
resetScreen = do
|
resetScreen = do
|
||||||
clearScreen
|
clearScreen
|
||||||
|
Loading…
Reference in New Issue
Block a user