-# Revision history for line-indexed-file-cursor
+# Revision history for line-indexed-cursor
-## 0.1.0.0 -- YYYY-mm-dd
+## 0.1.0.0 -- 2023-08-23
* First version. Released on an unsuspecting world.
cabal-version: 3.0
name: line-indexed-cursor
version: 0.1.0.0
+synopsis: Line-indexed file reader.
+description: Lazily builds the index with the line numbers while reading the file making it possible to rewind to them quickly later.
license: MIT
license-file: LICENSE
author: Evgenii Akentev
-Wincomplete-record-updates -Wredundant-constraints -Widentities
-Wunused-packages -Wmissing-deriving-strategies
-
library
import: warnings
exposed-modules: System.IO.LineIndexedCursor
import Data.Maybe (fromMaybe)
import qualified Data.Array as A
import Data.ByteString (ByteString, hGetLine)
-import Control.Concurrent.MVar
+import Control.Concurrent.MVar (MVar, newMVar, readMVar, modifyMVar, modifyMVar_)
import System.IO (Handle, hTell, hSeek, SeekMode(..), hIsEOF)
defaultListCapacity :: Integer
l'' <- getCurrentLine c
l'' `shouldBe` Just "Pellentesque accumsan dolor at nisl pulvinar, ut bibendum diam egestas."
- ln' <- goToLine c 3
- ln' `shouldBe` 3
-
- ln'' <- goToLine c 2
- ln'' `shouldBe` 2
-
- ln''' <- goToLine c 1
- ln''' `shouldBe` 1
-
- ln'''' <- goToLine c 0
- ln'''' `shouldBe` 0
-
it "goToLine works" $ \(_, c) -> do
ln <- goToLine c 10
ln `shouldBe` 10
s <- getCursorState c
s `shouldBe` [0,57,117,191,244,316,384,429,511,561,616,668,715,761,799,851,907,941,981,1024,1068]
- it "read line, then go to beginning and forth" $ \(_, c) -> do
+ it "read line, then go to the beginning and forth" $ \(_, c) -> do
cln <- getCurrentLineNumber c
cln `shouldBe` 0
ln'''' <- goToLine c 10
ln'''' `shouldBe` 10
+
+ ln''''' <- goToLine c 3
+ ln''''' `shouldBe` 3
+
+ ln'''''' <- goToLine c 2
+ ln'''''' `shouldBe` 2
+
+ ln''''''' <- goToLine c 1
+ ln''''''' `shouldBe` 1
+
+ ln'''''''' <- goToLine c 0
+ ln'''''''' `shouldBe` 0
\ No newline at end of file