diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-01-14 20:16:55 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-01-14 20:34:19 +0100 |
commit | d81cbaafde66f4b96af2f01ba56743089fd87c77 (patch) | |
tree | 0cc5590da7c43542ccb83a2fdd619c0fdde8b522 /src/Terminal.hs | |
parent | 03b5f52091a6a25218911255eb00439384bd24c4 (diff) |
Common blink var for whole terminal output
Diffstat (limited to 'src/Terminal.hs')
-rw-r--r-- | src/Terminal.hs | 11 |
1 files changed, 11 insertions, 0 deletions
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 |