首页 > 解决方案 > 如何设置 GHCi 提示以显示由自定义分隔符分隔的模块?

问题描述

目前这是我的 ghci 提示符的样子:

在此处输入图像描述

我想让它看起来像这样:

在此处输入图像描述

或者像这样

在此处输入图像描述

关于如何做到这一点的任何想法?我的配置(ghci.conf)文件的内容如下所示

:set prompt "\ESC[33m\STX[%s]\ESC[38;5;86m\STX \x03BB > \ESC[0m\STX"

在其中我遵循了以下语法:

https://downloads.haskell.org/ghc/8.8.1-alpha1/docs/html/users_guide/ghci.html#ghci-cmd-:set%20prompt

标签: haskellpromptghci

解决方案


您可以使用prompt-function而不是prompt为提示运行更高级的 Haskell 函数。ghci.conf这是您的第二个提示的示例:

:{
prompter :: [String] -> Int -> IO String
prompter modules line = return $
    concat [ "\ESC[33m\STX["
           , Data.List.intercalate ", " modules
           , "]\ESC[38;5;86m\STX \x03BB > \ESC[0m\STX"
           ]
:}

:set prompt-function prompter

或者,对于数字,您可以使用zipWith

:{
prompter :: [String] -> Int -> IO String
prompter modules line = return $
    concat [ "\ESC[33m\STX["
           -- this is the only line that changed
           , Data.List.intercalate ", " $ zipWith (\n m -> concat [show n, ".", m]) [1..] modules
           , "]\ESC[38;5;86m\STX \x03BB > \ESC[0m\STX"
           ]
:}

:set prompt-function prompter

我将把它作为编写续行的练习,但它非常相似,只涉及prompt-cont-function.


推荐阅读