@@ -51,7 +51,10 @@ import Graphics.Vty.Output.Interface
5151import Graphics.Vty.Picture
5252import Graphics.Vty.Image
5353import Graphics.Vty.Attributes
54+import Graphics.Vty.UnicodeWidthTable.IO
55+import Graphics.Vty.UnicodeWidthTable.Install
5456
57+import qualified Control.Exception as E
5558import Control.Monad (when)
5659import Control.Concurrent.STM
5760
@@ -110,10 +113,43 @@ data Vty = Vty
110113mkVty :: Config -> IO Vty
111114mkVty appConfig = do
112115 config <- (<> appConfig) <$> userConfig
116+ installWidthTable config
113117 input <- inputForConfig config
114118 out <- outputForConfig config
115119 intMkVty input out
116120
121+installWidthTable :: Config -> IO ()
122+installWidthTable c = do
123+ let doLog s = case debugLog c of
124+ Nothing -> return ()
125+ Just path -> appendFile path $ "installWidthTable: " <> s <> "\n"
126+
127+ customInstalled <- isCustomTableReady
128+ when (not customInstalled) $ do
129+ mTerm <- currentTerminalName
130+ case mTerm of
131+ Nothing ->
132+ doLog "No current terminal name available"
133+ Just currentTerm ->
134+ case lookup currentTerm (termWidthMaps c) of
135+ Nothing ->
136+ doLog "Current terminal not found in custom character width mapping list"
137+ Just path -> do
138+ tableResult <- readUnicodeWidthTable path
139+ case tableResult of
140+ Left msg ->
141+ doLog $ "Error reading custom character width table " <>
142+ "at " <> show path <> ": " <> msg
143+ Right table -> do
144+ installResult <- E.try $ installUnicodeWidthTable table
145+ case installResult of
146+ Left (e::E.SomeException) ->
147+ doLog $ "Error installing unicode table (" <>
148+ show path <> ": " <> show e
149+ Right () ->
150+ doLog $ "Successfully installed Unicode width table " <>
151+ " from " <> show path
152+
117153intMkVty :: Input -> Output -> IO Vty
118154intMkVty input out = do
119155 reserveDisplay out