From d81cbaafde66f4b96af2f01ba56743089fd87c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 14 Jan 2025 20:16:55 +0100 Subject: Common blink var for whole terminal output --- src/Terminal.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Terminal.hs') diff --git a/src/Terminal.hs b/src/Terminal.hs index bf50c58..84dfb91 100644 --- a/src/Terminal.hs +++ b/src/Terminal.hs @@ -4,9 +4,12 @@ module Terminal ( initTerminalOutput, newLine, redrawLine, + terminalBlinkStatus, ) where import Control.Concurrent +import Control.Concurrent.STM +import Control.Monad import Data.Text (Text) import Data.Text qualified as T @@ -17,6 +20,7 @@ import System.IO data TerminalOutput = TerminalOutput { outNumLines :: MVar Int + , outBlinkVar :: TVar Bool } data TerminalLine = TerminalLine @@ -27,6 +31,10 @@ data TerminalLine = TerminalLine initTerminalOutput :: IO TerminalOutput initTerminalOutput = do outNumLines <- newMVar 0 + outBlinkVar <- newTVarIO False + void $ forkIO $ forever $ do + threadDelay 500000 + atomically $ writeTVar outBlinkVar . not =<< readTVar outBlinkVar return TerminalOutput {..} newLine :: TerminalOutput -> Text -> IO TerminalLine @@ -43,3 +51,6 @@ redrawLine TerminalLine {..} text = do let moveBy = total - lineNum T.putStr $ "\ESC[s\ESC[" <> T.pack (show moveBy) <> "F" <> text <> "\ESC[u" hFlush stdout + +terminalBlinkStatus :: TerminalOutput -> STM Bool +terminalBlinkStatus TerminalOutput {..} = readTVar outBlinkVar -- cgit v1.2.3