diff options
author | James Crayne <jim.crayne@gmail.com> | 2018-05-29 01:05:54 +0000 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2018-05-29 01:05:54 +0000 |
commit | 1a958b20ebc9ee24dc5ac5dfe505ff7f8f3434e6 (patch) | |
tree | cbcce9ee4c44307825d265e1b8e9c479c8180acf /examples | |
parent | fe905494c23a56cc21afd702381486de5d892cf8 (diff) |
utf8boldify function definition
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dhtd.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 291d0530..4f26fc16 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -80,6 +80,9 @@ import Data.Aeson as J (ToJSON, FromJSON) | |||
80 | import qualified Data.Aeson as J | 80 | import qualified Data.Aeson as J |
81 | import qualified Data.ByteString.Lazy as L | 81 | import qualified Data.ByteString.Lazy as L |
82 | import qualified Data.ByteString.Char8 as B | 82 | import qualified Data.ByteString.Char8 as B |
83 | import qualified Data.Text as T | ||
84 | import qualified Data.Text.Encoding as E | ||
85 | import qualified Data.Text.Encoding.Error as E | ||
83 | import Control.Concurrent.Tasks | 86 | import Control.Concurrent.Tasks |
84 | import System.IO.Error | 87 | import System.IO.Error |
85 | import qualified Data.Serialize as S | 88 | import qualified Data.Serialize as S |
@@ -1521,7 +1524,15 @@ showMsg (n,(flg,(snapshot,iocm))) = B.concat [bool " " "h " flg, showmsg' (snap | |||
1521 | where | 1524 | where |
1522 | showmsg' (snapshot,In cm) = B.concat [Tox.vNick snapshot,"> ", pshow cm] | 1525 | showmsg' (snapshot,In cm) = B.concat [Tox.vNick snapshot,"> ", pshow cm] |
1523 | showmsg' (snapshot,Out cm) = B.concat [utf8boldify (Tox.vNick snapshot),": ",pshow cm] | 1526 | showmsg' (snapshot,Out cm) = B.concat [utf8boldify (Tox.vNick snapshot),": ",pshow cm] |
1524 | utf8boldify s = s | 1527 | utf8boldify s = boldify (T.decodeUtf8With E.lenientDecode s) |
1528 | where | ||
1529 | boldify :: T.Text -> B.ByteString | ||
1530 | boldify j = E.encodeUtf8 $ T.map addIt j | ||
1531 | where addIt x = let o = ord x in case o of | ||
1532 | _ | o <= 90 && o >= 65 -> chr (o + 119743) | ||
1533 | _ | o <= 122 && o >= 97 -> chr (o + 119737) | ||
1534 | _ -> x | ||
1535 | |||
1525 | 1536 | ||
1526 | main :: IO () | 1537 | main :: IO () |
1527 | main = runResourceT $ liftBaseWith $ \resT -> do | 1538 | main = runResourceT $ liftBaseWith $ \resT -> do |