module LogView.LogCat where
import Control.Monad
import qualified Data.ByteString as ByteString
import qualified Data.Text.IO as Text.IO
import qualified System.Environment as Environment
import qualified System.IO as IO
import qualified Util.Log as Log
import qualified LogView.Tail as Tail
main :: IO ()
main :: IO ()
main = do
[String]
args <- IO [String]
Environment.getArgs
Handle
hdl <- case [String]
args of
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return Handle
IO.stdin
[String
fn] -> String -> IOMode -> IO Handle
IO.openFile String
fn IOMode
IO.ReadMode
[String]
_ -> forall a. HasCallStack => String -> a
error String
"usage: logcat [filename]"
Handle -> BufferMode -> IO ()
IO.hSetBuffering Handle
hdl BufferMode
IO.LineBuffering
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever forall a b. (a -> b) -> a -> b
$ do
ByteString
line <- Handle -> IO ByteString
ByteString.hGetLine Handle
hdl
let msg :: Msg
msg = ByteString -> Msg
Tail.deserialize_line ByteString
line
Text -> IO ()
Text.IO.putStrLn (Msg -> Text
Log.format_msg Msg
msg)