vty-6.0: A simple terminal UI library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Graphics.Vty.Config

Description

Vty supports a configuration file format and provides a corresponding VtyUserConfig data type. The VtyUserConfig can be provided to platform packages' mkVty functions to customize the application's use of Vty.

Debug

debugLog

Format:

 "debugLog" string

The value of the environment variable VTY_DEBUG_LOG is equivalent to a debugLog entry at the end of the last config file.

Input Processing

map

Format:

 "map" term string key modifier_list
 where
     key := KEsc | KChar Char | KBS ... (same as Key)
     modifier_list := "[" modifier+ "]"
     modifier := MShift | MCtrl | MMeta | MAlt
     term := "_" | string

E.g., if the contents are

 map _       "\ESC[B"    KUp   []
 map _       "\ESC[1;3B" KDown [MAlt]
 map "xterm" "\ESC[D"    KLeft []

Then the bytes "\ESC[B" will result in the KUp event on all terminals. The bytes "\ESC[1;3B" will result in the event KDown with the MAlt modifier on all terminals. The bytes "\ESC[D" will result in the KLeft event when TERM is xterm.

If a debug log is requested then vty will output the current input table to the log in the above format. A workflow for using this is to set VTY_DEBUG_LOG. Run the application. Check the debug log for incorrect mappings. Add corrected mappings to $HOME/.vty/config.

Unicode Character Width Maps

widthMap

Format:

 "widthMap" string string

E.g.,

  widthMap "xterm" "/home/user/.vty/xterm_map.dat"

This directive specifies the path to a Unicode character width map (the second argument) that should correspond to the terminal named by first argument. Unicode character width maps can be produced either by running platform packages' width table tools or by calling the library routine buildUnicodeWidthTable. Vty platform packages should use these configuration settings to attempt to load and install the specified width map.

Synopsis

Documentation

type InputMap = [(Maybe String, String, Event)] Source #

Mappings from input bytes to event in the order specified. Later entries take precedence over earlier in the case multiple entries have the same byte string.

data VtyUserConfig Source #

A Vty core library configuration. Platform-specific details are not included in the VtyUserConfig.

Constructors

VtyUserConfig 

Fields

  • configDebugLog :: Maybe FilePath

    Debug information is appended to this file if not Nothing.

  • configInputMap :: InputMap

    The (input byte, output event) pairs extend the internal input table of VTY and the table from terminfo.

    See Graphics.Vty.Config module documentation for documentation of the map directive.

  • configTermWidthMaps :: [(String, FilePath)]

    Terminal width map files.

  • configAllowCustomUnicodeWidthTables :: Maybe Bool

    Whether to permit custom Unicode width table loading by mkVty. Just False indicates that table loading should not be performed. Other values permit table loading.

    If a table load is attempted and fails, information about the failure will be logged to the debug log if the configuration specifies one. If no custom table is loaded (or if a load fails), the built-in character width table will be used.

userConfig :: IO VtyUserConfig Source #

Load a configuration from vtyConfigPath and $VTY_CONFIG_FILE. If none is found, build a default configuration.

parseConfigFile :: FilePath -> IO VtyUserConfig Source #

Parse a Vty configuration file.

Lines in config files that fail to parse are ignored. Later entries take precedence over earlier ones.

data ConfigUpdateResult Source #

The result of a configuration change attempt made by addConfigWidthMap.

Constructors

ConfigurationCreated

A new configuration file file was written with the new width table entry.

ConfigurationModified

An existing configuration file was modified with the new width table entry.

ConfigurationConflict String

The attempted width table entry could not be written to the configuration due to a conflict; the argument here is the width table file path for the conflicting entry.

ConfigurationRedundant

No change was made because the existing configuration already contains the specified mapping.

addConfigWidthMap Source #

Arguments

:: FilePath

The configuration file path of the configuration to modify or create.

-> String

The TERM value for the widthMap directive.

-> FilePath

The width table file path for the directive.

-> IO ConfigUpdateResult 

Add a widthMap directive to the Vty configuration file at the specified path.

If the configuration path refers to a configuration that already contains the directive for the specified map and terminal type, the configuration file will not be modified. If the file does not contain the directive, it will be appended to the file.

If the configuration path does not exist, a new configuration file will be created and any directories in the path will also be created.

This returns a ConfigUpdateResult indicating the change to the configuration. This does not handle exceptions raised by file or directory permissions issues.