1import qualified Streamly.Prelude as S
2import qualified Streamly.Data.Fold as FL
3-- import qualified Streamly.Memory.Array as A
4import qualified Streamly.FileSystem.Handle as FH
5import qualified System.IO as FH
6-- import qualified Streamly.FileSystem.FD as FH
7-- import qualified Streamly.Data.Unicode.Stream as US
9import qualified Streamly.Internal.Data.Fold as FL
10import qualified Streamly.Internal.Memory.ArrayStream as AS
11import qualified Streamly.Internal.FileSystem.Handle as IFH
14import System.Environment (getArgs)
15import System.IO (IOMode(..), hSeek, SeekMode(..))
17cat :: FH.Handle -> IO ()
19 S.fold (FH.writeChunks FH.stdout)
20 $ IFH.toChunksWithBufferOf (256*1024) src
22-- cat src = S.fold (FH.write FH.stdout) $ FH.read src
24cp :: FH.Handle -> FH.Handle -> IO ()
26 S.fold (FH.writeChunks dst)
27 $ IFH.toChunksWithBufferOf (256*1024) src
29-- cp src dst = S.fold (FH.write dst) $ FH.read src
31ord' :: Num a => Char -> a
32ord' = (fromIntegral . ord)
34wcl :: FH.Handle -> IO ()
35wcl src = print =<< (S.length
40wcl src = print =<< (S.length
41 $ flip US.lines FL.drain
47grepc :: String -> FH.Handle -> IO ()
48grepc pat src = print . (subtract 1) =<< (S.length
49 $ FL.splitOnSeq (A.fromList (map ord' pat)) FL.drain
53avgll :: FH.Handle -> IO ()
54avgll src = print =<< (S.fold avg
55 $ S.splitWithSuffix (== ord' '\n') FL.length
56 $ S.unfold FH.read src)
57 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
58 toDouble = fmap (fromIntegral :: Int -> Double)
60llhisto :: FH.Handle -> IO ()
61llhisto src = print =<< (S.fold (FL.classify FL.length)
63 $ S.splitWithSuffix (== ord' '\n') FL.length
64 $ S.unfold FH.read src)
66 bucket n = let i = n `mod` 10 in if i > 9 then (9,n) else (i,n)
70 name <- fmap head getArgs
71 src <- FH.openFile name ReadMode
72 let rewind = hSeek src AbsoluteSeek 0
74 rewind >> putStrLn "cat" >> cat src -- Unix cat program
75 rewind >> putStr "wcl " >> wcl src -- Unix wc -l program
76 -- rewind >> putStr "grepc " >> grepc "aaaa" src -- Unix grep -c program
77 rewind >> putStr "avgll " >> avgll src -- get average line length
78 rewind >> putStr "llhisto " >> llhisto src -- get line length histogram
80 dst <- FH.openFile "dst-xyz.txt" WriteMode
81 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