Skip to content

Commit

Permalink
Improved rendering of nonprintable characters - now as hex code!
Browse files Browse the repository at this point in the history
  • Loading branch information
SOwOphie committed Jul 8, 2016
1 parent 03ae764 commit 1e96a5c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion WSEdit/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fqn = ("WSEdit.Data." ++)

-- | Version number constant.
version :: String
version = "1.0.0.4 RC"
version = "1.0.0.5 RC"

-- | Upstream URL.
upstream :: String
Expand Down
10 changes: 6 additions & 4 deletions WSEdit/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module WSEdit.Output
import Control.Monad (foldM)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.RWS.Strict (ask, get)
import Data.Char (toLower)
import Data.Char (ord, toLower)
import Data.Default (def)
import Data.Ix (inRange)
import Data.Maybe (fromMaybe)
Expand All @@ -36,6 +36,7 @@ import Graphics.Vty ( Attr
, translateX, update, vertCat, withStyle
, (<|>), (<->)
)
import Numeric (showHex)
import Safe (lookupJustDef, minimumNote)

import WSEdit.Data ( EdConfig ( drawBg, edDesign, escape, keywords
Expand Down Expand Up @@ -79,8 +80,9 @@ fqn = ("WSEdit.Output." ++)

-- | Returns the display width of a given char in a given column.
charWidth :: Int -> Char -> WSEdit Int
charWidth n '\t' = (\w -> w - (n-1) `mod` w) . tabWidth <$> ask
charWidth _ _ = return 1
charWidth n '\t' = (\w -> w - (n-1) `mod` w) . tabWidth <$> ask
charWidth _ c | charClass c == Unprintable = return $ length (showHex (ord c) "") + 3
| otherwise = return 1

-- | Returns the display width of a given string starting at a given column.
stringWidth :: Int -> String -> WSEdit Int
Expand Down Expand Up @@ -133,7 +135,7 @@ charRep hl pos _ c = do
hl
(dHLStyles d)
, if charClass c == Unprintable
then "?"
then "?#" ++ showHex (ord c) ";"
else [c]
)

Expand Down
2 changes: 1 addition & 1 deletion wsedit.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wsedit
version: 1.0.0.4
version: 1.0.0.5
synopsis: A simple terminal source code editor.
description:
homepage:
Expand Down

0 comments on commit 1e96a5c

Please sign in to comment.