@@ -9,6 +9,7 @@ import Data.Semigroup ((<>))
99import System.Environment (getArgs, getProgName)
1010import System.Exit (exitFailure)
1111import System.Console.GetOpt
12+import Text.Read (readMaybe)
1213
1314import Graphics.Vty.Config (terminalWidthTablePath, currentTerminalName, vtyConfigPath)
1415import Graphics.Vty.UnicodeWidthTable.IO
@@ -16,12 +17,16 @@ import Graphics.Vty.UnicodeWidthTable.Query
1617
1718data Arg = Help
1819 | OutputPath String
20+ | TableUpperBound String
1921 deriving (Eq, Show)
2022
2123options :: Config -> [OptDescr Arg]
2224options config =
2325 [ Option "h" ["help"] (NoArg Help)
2426 "This help output"
27+ , Option "b" ["bound"] (ReqArg TableUpperBound "MAX_CHAR")
28+ ("The maximum Unicode code point to test when building the table " <>
29+ "(default: " <> (show $ fromEnum $ configBound config) <> ")")
2530 , Option "p" ["path"] (ReqArg OutputPath "PATH")
2631 ("The output path to write to (default: " <>
2732 fromMaybe "<none>" (configOutputPath config) <> ")")
@@ -29,12 +34,14 @@ options config =
2934
3035data Config =
3136 Config { configOutputPath :: Maybe FilePath
37+ , configBound :: Char
3238 }
3339 deriving (Show)
3440
3541mkDefaultConfig :: IO Config
3642mkDefaultConfig = do
3743 Config <$> terminalWidthTablePath
44+ <*> pure defaultUnicodeTableUpperBound
3845
3946usage :: IO ()
4047usage = do
@@ -53,6 +60,10 @@ usage = do
5360updateConfigFromArg :: Arg -> Config -> Config
5461updateConfigFromArg Help c =
5562 c
63+updateConfigFromArg (TableUpperBound s) c =
64+ case readMaybe s of
65+ Nothing -> error $ "Invalid table upper bound: " <> show s
66+ Just v -> c { configBound = toEnum v }
5667updateConfigFromArg (OutputPath p) c =
5768 c { configOutputPath = Just p }
5869
@@ -79,7 +90,7 @@ main = do
7990 Just path -> return path
8091
8192 putStrLn "Querying terminal:"
82− builtTable <- buildUnicodeWidthTable
93+ builtTable <- buildUnicodeWidthTable $ configBound config
8394 writeUnicodeWidthTable outputPath builtTable
8495 putStrLn $ "\nOutput table written to " <> outputPath
8596