]> Git — Sourcephile - julm/worksheets.git/blob - unicode.hs
update
[julm/worksheets.git] / unicode.hs
1 #!/usr/bin/env nix
2 #! nix --experimental-features ``nix-command flakes`` shell --impure --expr ``
3 #! nix let nixpkgs = builtins.getFlake "nixpkgs"; in
4 #! nix let pkgs = import nixpkgs {}; in
5 #! nix [ (pkgs.haskellPackages.ghcWithPackages (haskellPkgs: with haskellPkgs; [
6 #! nix turtle
7 #! nix unicode-transforms
8 #! nix ])) ]
9 #! nix ``
10 #! nix --command runhaskell
11
12 {-# LANGUAGE GHC2024 #-}
13 {-# LANGUAGE BlockArguments #-}
14 {-# LANGUAGE OverloadedStrings #-}
15
16 import Control.Monad (forM_)
17 import Data.Char (chr, ord)
18 import Data.Function ((&))
19 import Data.List qualified as List
20 import Data.Text (Text)
21 import Data.Text qualified as Text
22 import Data.Text.Normalize
23 import System.Environment (lookupEnv)
24 import Text.Printf qualified as Printf
25 import Turtle
26
27 main :: IO ()
28 main = do
29 term <- lookupEnv "TERM"
30 forM_ combs \comb -> do
31 forM_ baseChars \baseChar -> do
32 let txt = baseChar <> comb
33 putStrLn $ analyse txt
34 when (term == Just "xterm-ghostty") $
35 shells ("ghostty +show-face --string=" <> txt) empty
36 putStrLn ""
37
38 baseChars = ["ɑ", "ɛ", "y"]
39
40 combs =
41 [ combiningDiacriticalMarks
42 , combiningDiacriticalMarksExtended
43 , combiningDiacriticalMarksForSymbols
44 , combiningHalfMarks
45 ]
46 & mconcat
47 combiningDiacriticalMarks =
48 [ chr c & Text.singleton
49 | c <- [0x0300 .. 0x036F]
50 ]
51 combiningDiacriticalMarksExtended =
52 [ chr c & Text.singleton
53 | c <- [0x1AB0 .. 0x1AEB]
54 ]
55 combiningDiacriticalMarksForSymbols =
56 [ chr c & Text.singleton
57 | c <- [0x20D0 .. 0x20F0]
58 ]
59 combiningHalfMarks =
60 [ chr c & Text.singleton
61 | c <- [0xFE20 .. 0xFE2F]
62 ]
63
64 analyse :: Text -> String
65 analyse text = do
66 List.intercalate " " $
67 [ Printf.printf
68 "%20s: %-5s"
69 (text & normalize NFKD & escape)
70 (text & normalize NFKD)
71 ]
72
73 escape :: Text -> Text
74 escape txt =
75 txt
76 & Text.unpack
77 & foldMap (\c -> Printf.printf "\\x%X" (ord c))
78 & Text.pack