Created
September 9, 2019 20:44
-
-
Save glguy/a802eaaac5a00ab41e3c3ca33507634b to your computer and use it in GitHub Desktop.
Terminal character widths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import System.Console.ANSI | |
import System.IO | |
import Data.List | |
import Data.Traversable | |
import Graphics.Text.Width (wcwidth) | |
import Data.Char | |
import Data.Foldable | |
import Text.Printf | |
isAssigned c = | |
case generalCategory c of | |
NotAssigned -> False | |
Surrogate -> False | |
Control -> False | |
_ -> True | |
main :: IO () | |
main = | |
withFile "output.txt" WriteMode $ \h -> | |
do hSetBuffering stdout NoBuffering | |
for_ ['\0'..] $ \i -> | |
hPrint h =<< | |
if isAssigned i | |
then charWidth i | |
else return 1 | |
charWidth :: Char -> IO Int | |
charWidth c = | |
do printf "\r%06x: " (ord c) | |
putChar c | |
Just (_row, col) <- getCursorPosition0 | |
return (col - 8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal-version: 2.4 | |
name: widths | |
version: 0.1.0.0 | |
license: ISC | |
license-file: LICENSE | |
author: Eric Mertens | |
maintainer: [email protected] | |
extra-source-files: CHANGELOG.md | |
executable widths | |
main-is: Main.hs | |
build-depends: base ^>=4.12.0.0, ansi-terminal ^>=0.10, vty ^>=5.25.1 | |
default-language: Haskell2010 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment