    -- | The Unix implementation entry point for Vty. This module and
    -- @Graphics.Vty.Platform.Unix.Settings@ are the only modules you should
    -- ever need to import from this package; the rest is exported for
    -- testing purposes only.
    --
    -- This module provides 'mkVty' to create Vty handles for Unix
    -- terminals. Once a 'Vty' handle has been created, the rest of Vty's
    -- API can be used it with as usual; see the @vty@ package for details.
    module Graphics.Vty.Platform.Unix
      ( mkVty
      , mkVtyWithSettings
      )
    where

    import Control.Monad (when)

    import Graphics.Vty (Vty, installCustomWidthTable, mkVtyFromPair)
    import Graphics.Vty.Config (VtyUserConfig(..))

    import Graphics.Vty.Platform.Unix.Settings
    import Graphics.Vty.Platform.Unix.Output
    import Graphics.Vty.Platform.Unix.Input

    -- | Create a Vty handle. At most one handle should be created
    -- at a time for a given terminal device. Uses the default
    -- values for 'UnixSettings'. If you need to override those, use
    -- 'mkVtyWithSettings'.
    --
    -- This may raise
    -- 'Graphics.Vty.Platform.Unix.Settings.VtyUnixConfigurationError'.
    mkVty :: VtyUserConfig
          -- ^ The user's Vty configuration or the result of
          -- 'Graphics.Vty.Config.defaultConfig'.
          -> IO Vty
    mkVty :: VtyUserConfig -> IO Vty
    mkVty VtyUserConfig
    userConfig =
        VtyUserConfig -> UnixSettings -> IO Vty
    mkVtyWithSettings VtyUserConfig
    userConfig (UnixSettings -> IO Vty) -> IO UnixSettings -> IO Vty
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< IO UnixSettings
    defaultSettings

    -- | Create a Vty handle. At most one handle should be created
    -- at a time for a given terminal device.
    --
    -- This also uses the value of @TERM@ to attempt to load and
    -- install a Unicode character width table map. For details, see
    -- 'Graphics.Vty.UnicodeWidthTable.Install.installUnicodeWidthTable'.
    --
    -- This may raise
    -- 'Graphics.Vty.Platform.Unix.Settings.VtyUnixConfigurationError'.
    mkVtyWithSettings :: VtyUserConfig
                      -- ^ The user's Vty configuration or the result of
                      -- 'defaultConfig'.
                      -> UnixSettings
                      -- ^ Runtime settings.
                      -> IO Vty
    mkVtyWithSettings :: VtyUserConfig -> UnixSettings -> IO Vty
    mkVtyWithSettings VtyUserConfig
    userConfig UnixSettings
    settings = do
        Bool -> IO () -> IO ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (VtyUserConfig -> Maybe Bool
    configAllowCustomUnicodeWidthTables VtyUserConfig
    userConfig Maybe Bool -> Maybe Bool -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Bool -> Maybe Bool
    forall a. a -> Maybe a
    Just Bool
    False) (IO () -> IO ()) -> IO () -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            Maybe FilePath -> Maybe FilePath -> [(FilePath, FilePath)] -> IO ()
    installCustomWidthTable (VtyUserConfig -> Maybe FilePath
    configDebugLog VtyUserConfig
    userConfig)
                                    (FilePath -> Maybe FilePath
    forall a. a -> Maybe a
    Just (FilePath -> Maybe FilePath) -> FilePath -> Maybe FilePath
    forall a b. (a -> b) -> a -> b
    $ UnixSettings -> FilePath
    settingTermName UnixSettings
    settings)
                                    (VtyUserConfig -> [(FilePath, FilePath)]
    configTermWidthMaps VtyUserConfig
    userConfig)

        input <- VtyUserConfig -> UnixSettings -> IO Input
    buildInput VtyUserConfig
    userConfig UnixSettings
    settings
        out <- buildOutput userConfig settings
        mkVtyFromPair input out