1import qualified Streamly.Prelude as S
2import qualified Streamly.Fold as FL
3-- import qualified Streamly.Memory.Array as A
4import qualified Streamly.Memory.ArrayStream as AS
5import qualified Streamly.FileSystem.Handle as FH
6import qualified System.IO as FH
7-- import qualified Streamly.FileSystem.FD as FH
8-- import qualified Streamly.String as SS
11import System.Environment (getArgs)
12import System.IO (IOMode(..), hSeek, SeekMode(..))
14cat :: FH.Handle -> IO ()
15cat src = S.runFold (FH.writeArrays FH.stdout) $ FH.readArraysOf (256*1024) src
17-- cat src = FH.write FH.stdout $ FH.read src
19cp :: FH.Handle -> FH.Handle -> IO ()
20cp src dst = S.runFold (FH.writeArrays dst) $ FH.readArraysOf (256*1024) src
22-- cp src dst = FH.write dst $ FH.read src
24ord' :: Num a => Char -> a
25ord' = (fromIntegral . ord)
27wcl :: FH.Handle -> IO ()
28wcl src = print =<< (S.length
33wcl src = print =<< (S.length
34 $ flip SS.foldLines FL.drain
40grepc :: String -> FH.Handle -> IO ()
41grepc pat src = print . (subtract 1) =<< (S.length
42 $ FL.splitOnSeq (A.fromList (map ord' pat)) FL.drain
46avgll :: FH.Handle -> IO ()
47avgll src = print =<< (S.runFold avg
48 $ S.splitBySuffix (== ord' '\n') FL.length
50 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
51 toDouble = fmap (fromIntegral :: Int -> Double)
53llhisto :: FH.Handle -> IO ()
54llhisto src = print =<< (S.runFold (FL.classify FL.length)
56 $ S.splitBySuffix (== ord' '\n') FL.length
59 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
63 name <- fmap head getArgs
64 src <- FH.openFile name ReadMode
65 let rewind = hSeek src AbsoluteSeek 0
67 rewind >> putStrLn "cat" >> cat src -- Unix cat program
68 rewind >> putStr "wcl " >> wcl src -- Unix wc -l program
69 -- rewind >> putStr "grepc " >> grepc "aaaa" src -- Unix grep -c program
70 rewind >> putStr "avgll " >> avgll src -- get average line length
71 rewind >> putStr "llhisto " >> llhisto src -- get line length histogram
73 dst <- FH.openFile "dst-xyz.txt" WriteMode
74 rewind >> putStr "cp " >> cp src dst -- Unix cp program
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list