Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress rendering zero-width space #125

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/Client/Image/PackedImage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,33 @@ instance Semigroup Image' where

instance IsString Image' where fromString = string defAttr

-- | Predicate for characters that should be output to screen.
isOutput :: Char -> Bool
isOutput '\x200b' = False -- zero-width space that terminals typically misdraw
isOutput _ = True

text' :: Attr -> S.Text -> Image'
text' a s
| S.null s = EmptyImage'
| otherwise = HorizText' a s (wcswidth (S.unpack s)) (S.length s) EmptyImage'
| S.null s = EmptyImage'
-- optimization to avoid copying the text if nothing will be filtered
| S.all isOutput s = HorizText' a s (wcswidth (S.unpack s)) (S.length s) EmptyImage'
| S.null s' = EmptyImage'
| otherwise = HorizText' a s' (wcswidth (S.unpack s')) (S.length s') EmptyImage'
where
s' = S.filter isOutput s

char :: Attr -> Char -> Image'
char a c = HorizText' a (S.singleton c) (wcwidth c) 1 EmptyImage'
char a c
| isOutput c = HorizText' a (S.singleton c) (wcwidth c) 1 EmptyImage'
| otherwise = EmptyImage'

string :: Attr -> String -> Image'
string a s
| null s = EmptyImage'
| otherwise = HorizText' a t (wcswidth s) (S.length t) EmptyImage'
where t = S.pack s
| otherwise = HorizText' a t (wcswidth s') (S.length t) EmptyImage'
where
s' = filter isOutput s
t = S.pack s'

splitImage :: Int {- ^ image width -} -> Image' -> (Image',Image')
splitImage _ EmptyImage' = (EmptyImage', EmptyImage')
Expand Down
Loading