From 87fc24e34aad273b0052115cfcfa9efe18a13af8 Mon Sep 17 00:00:00 2001 From: mbays Date: Sun, 28 May 2023 00:00:00 +0000 Subject: [PATCH] strip non-esc control chars --- ANSIColour.hs | 5 ++++- diohsc.hs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ANSIColour.hs b/ANSIColour.hs index 8a4feab..12e7198 100644 --- a/ANSIColour.hs +++ b/ANSIColour.hs @@ -28,7 +28,7 @@ module ANSIColour , visibleLength , splitAtVisible , escapePromptCSI - , sanitiseNonCSI + , sanitiseForDisplay , Colour(..) ) where @@ -156,6 +156,9 @@ sanitiseNonCSI s = isCSI = T.take 1 post' == "[" in pre <> (if isCSI then "\ESC" else "\\ESC") <> sanitiseNonCSI post' +sanitiseForDisplay :: T.Text -> T.Text +sanitiseForDisplay = sanitiseNonCSI . T.filter (\c -> c == '\ESC' || wcwidth c >= 0) + -- |append \STX to each CSI sequence, as required in Haskeline prompts. -- See https://github.com/judah/haskeline/wiki/ControlSequencesInPrompt escapePromptCSI :: String -> String diff --git a/diohsc.hs b/diohsc.hs index a3eeab2..489f50a 100644 --- a/diohsc.hs +++ b/diohsc.hs @@ -1277,7 +1277,7 @@ handleCommandLine Just cmd -> (T.lines . T.decodeUtf8With T.lenientDecode <$>) . doRestrictedFilter (filterShell cmd []) . BL.concat . (appendNewline . T.encodeUtf8 <$>) where appendNewline = (`BL.snoc` 10) - (Right <$>) . applyFilter . (sanitiseNonCSI <$>) $ case textType of + (Right <$>) . applyFilter . (sanitiseForDisplay <$>) $ case textType of "gemini" -> let opts = GemRenderOpts ansi' preOpt pageWidth linkDescFirst in printGemDoc opts (showUriRefFull ansi' ais uri) $ parseGemini bodyText -- 2.11.4.GIT