Skip to content

Commit 7405e4d

Browse files
write defaultTermWidthFile to config
1 parent 667438e commit 7405e4d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
4+
module Potato.Flow.DefaultTermWidthFile where
5+
6+
import Relude
7+
8+
import qualified Data.ByteString.Lazy as LBS
9+
import Data.FileEmbed (embedFile)
10+
11+
12+
defaultTermWidthFileBS :: LBS.ByteString
13+
defaultTermWidthFileBS = LBS.fromStrict $(embedFile "xterm-256color_termwidthfile")

src/Potato/Flow/Vty/Main.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Potato.Flow.Vty.OpenWindow
3131
import Potato.Flow.Vty.Alert
3232
import Potato.Flow.Vty.AppKbCmd
3333
import Potato.Flow.Vty.Attrs
34+
import Potato.Flow.DefaultTermWidthFile
3435

3536

3637
import System.Console.ANSI (hSetTitle)
@@ -39,7 +40,7 @@ import qualified System.Directory as FP
3940

4041
import Control.Concurrent
4142
import Control.Monad.NodeId
42-
import Control.Exception (handle)
43+
import Control.Exception
4344
import Data.Maybe
4445
import Data.Default
4546
import qualified Data.Text as T
@@ -125,9 +126,22 @@ potatoMainWidget child = do
125126
Just termName -> configDir FP.</> (termName <> "_termwidthfile")
126127
doesWidthMapFileExist <- FP.doesFileExist widthMapFile
127128
doesDefaultWidthMapFileExist <- FP.doesFileExist defaultWidthMapFile
129+
130+
128131
if doesWidthMapFileExist
129132
then putStrLn $ "attempting to load unicode width table file " <> widthMapFile
130-
else putStrLn $ "could not find unicode width table file " <> widthMapFile <> " using the xterm-256 one by default instead. Please run --widthtable to generate unicode width table file"
133+
else do
134+
putStrLn $ "could not find unicode width table file " <> widthMapFile <> " lease run --widthtable to generate unicode width table file"
135+
if doesDefaultWidthMapFileExist
136+
then putStrLn $ "attempting to load default unicode width table file " <> defaultWidthMapFile
137+
else do
138+
--putStrLn $ "default unicode width tabel file DNE, oops, NBD, but wide chars may not render correctly"
139+
putStrLn $ "writing default unicode width table file to" <> configDir <> "/" <> defaultWidthMapFile
140+
rslt <- try $ LBS.writeFile (configDir FP.</> defaultWidthMapFile) defaultTermWidthFileBS
141+
case rslt of
142+
Left (SomeException e) -> putStrLn $ "could not write default unicode width table file to " <> (configDir FP.</> defaultWidthMapFile) <> " got exception \"" <> show e <> "\""
143+
Right _ -> return ()
144+
131145
let
132146
cfg' = cfg'' { V.mouseMode = Just True }
133147
cfg = if doesWidthMapFileExist

tinytools-vty.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ library
3232
exposed-modules:
3333
Data.String.Unicode.Lookup
3434
Potato.Flow.TutorialState
35+
Potato.Flow.DefaultTermWidthFile
3536
Potato.Flow.Vty.Alert
3637
Potato.Flow.Vty.AppKbCmd
3738
Potato.Flow.Vty.Attrs

0 commit comments

Comments
 (0)