diohsc 0.1.14.2 → 0.1.14.3
raw patch · 8 files changed
+43/−46 lines, 8 files
Files
- ANSIColour.hs +11/−11
- LineClient.hs +6/−2
- Makefile +8/−19
- Pager.hs +11/−9
- TextGemini.hs +2/−1
- Version.hs +1/−1
- diohsc.cabal +1/−1
- diohsc.hs +3/−2
ANSIColour.hs view
@@ -104,17 +104,18 @@ applyIf True = id applyIf False = const id +mapTail :: (a -> a) -> [a] -> [a]+mapTail _ [] = []+mapTail f (a:as) = a:(f<$>as) + endCSI :: Char -> Bool endCSI c = '@' <= c && c <= '~' -- |strip all CSI escape sequences stripCSI :: T.Text -> T.Text-stripCSI s =- let (pre,post) = T.breakOn "\ESC[" s- in if T.null post then pre- else (pre <>) . stripCSI . T.drop 1 .- T.dropWhile (not . endCSI) $ T.drop 2 post+stripCSI = T.concat . mapTail dropCSI . T.splitOn "\ESC["+ where dropCSI = T.drop 1 . T.dropWhile (not . endCSI) visibleLength :: (Integral i) => T.Text -> i visibleLength = fromIntegral . wcLength . stripCSI@@ -150,12 +151,11 @@ -- (buggy terminals make these sequences a potential security hole; -- see e.g. https://nvd.nist.gov/vuln/detail/CVE-2020-9366 ) sanitiseNonCSI :: T.Text -> T.Text-sanitiseNonCSI s =- let (pre,post) = T.breakOn "\ESC" s- in if T.null post then pre else- let post' = T.drop 1 post- isCSI = T.take 1 post' == "["- in pre <> (if isCSI then "\ESC" else "\\ESC") <> sanitiseNonCSI post'+sanitiseNonCSI = T.concat . mapTail escapeEsc . T.splitOn "\ESC"+ where+ escapeEsc s = case T.take 1 s of+ "[" -> T.cons '\ESC' s+ _ -> "\\ESC" <> s -- |strip all C0 and C1 control chars stripControl :: T.Text -> T.Text
LineClient.hs view
@@ -19,8 +19,12 @@ import qualified Codec.MIME.Parse as MIME import qualified Codec.MIME.Type as MIME import Control.Applicative (Alternative, empty)-import Control.Monad.Catch-import Control.Monad.State+import Control.Monad (forM_, guard, join, mplus, msum,+ mzero, unless, void, when, (<=<))+import Control.Monad.Catch (SomeException, bracket,+ displayException, handle)+import Control.Monad.IO.Class (MonadIO, liftIO)+import Control.Monad.State (get, gets, lift, modify) import Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT) import Data.Bifunctor (second)
Makefile view
@@ -1,28 +1,17 @@-VERSION=0.1.14.2+VERSION=0.1.14.3 GHCOPTS=-threaded -DICONV -DMAGIC -ignore-package regex-compat-tdfa -.PHONY: build install clean-build:- @echo "NOTE: All haskell dependencies must be installed for this to build." 1>&2- @echo "Probably you want to skip directly to \"make install\"" 1>&2- @echo "" 1>&2- cabal build-install:+.PHONY: warn install build+warn:+ @echo "Use \"make install\" to download and compile dependencies and install diohsc"+install: *.hs cabal update && cabal install+build: *.hs+ cabal build diohsc: *.hs- ghc --make -Wall ${GHCOPTS} diohsc.hs-diohsc-O: *.hs- ghc -o $@ --make -O -Wall ${GHCOPTS} diohsc.hs-diohsc-dynamic: *.hs- ghc -o $@ --make -dynamic -Wall ${GHCOPTS} diohsc.hs-diohsc-static:- ghc -o $@ --make ${GHCOPTS} -optl-static -optl-pthread diohsc.hs-diohsc-prof: *.hs- ghc -o $@ --make ${GHCOPTS} -rtsopts -prof -fprof-auto diohsc.hs-clean:- rm diohsc *.hi *.o+ cabal install -O2 --installdir . --overwrite-policy=always diohsc.1: diohsc.1.md pandoc --standalone -f markdown -t man < diohsc.1.md | sed 's/\$$VERSION/${VERSION}/g' >| diohsc.1
Pager.hs view
@@ -13,15 +13,17 @@ module Pager where -import Control.Monad (when)-import Control.Monad.IO.Class (MonadIO, liftIO)-import Data.Char (toLower)-import Data.Maybe (fromMaybe, isJust)-import Safe (readMay)-import System.IO (hFlush, stdout)+import Control.Exception (throw)+import Control.Monad (when)+import Control.Monad.IO.Class (MonadIO, liftIO)+import Data.Char (toLower)+import Data.Maybe (fromMaybe, isJust)+import Safe (readMay)+import System.IO (hFlush, stdout) -import qualified Data.Text.Lazy as T-import qualified Data.Text.Lazy.IO as T+import qualified Data.Text.Lazy as T+import qualified Data.Text.Lazy.IO as T+import qualified System.Console.Haskeline as HL import ANSIColour import Prompt@@ -45,7 +47,7 @@ c <- liftIO . promptChar $ drop (col + 4 - termWidth) " --" liftIO $ putStrLn "" case toLower <$> c of- Nothing -> return ()+ Nothing -> throw HL.Interrupt Just 'q' -> return () Just c' | c' == '\n' || c' == '\r' -> return () Just c' | Just m <- readMay (c':""), m > 0 -> printLinesPaged' m Nothing ls
TextGemini.hs view
@@ -14,7 +14,8 @@ module TextGemini where -import Control.Monad.State+import Control.Monad (forM)+import Control.Monad.State (State, evalState, gets, modify) import Data.Maybe (catMaybes, isJust, mapMaybe) import ANSIColour
Version.hs view
@@ -16,4 +16,4 @@ programName = "diohsc" version :: String-version = "0.1.14.2"+version = "0.1.14.3"
diohsc.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: diohsc-version: 0.1.14.2+version: 0.1.14.3 license: GPL-3 license-file: COPYING maintainer: mbays@sdf.org
diohsc.hs view
@@ -16,8 +16,9 @@ module Main where -import Control.Monad.Catch-import Control.Monad.State+import Control.Monad (join, unless, when)+import Control.Monad.Catch (bracketOnError)+import Control.Monad.State (execStateT) import Data.Hashable (hash) import Data.Maybe