如何设置 GHCi 提示以显示由自定义分隔符分隔的模块?

问题描述

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

enter image description here

我想让它看起来像这样:

enter image description here

或者像这样

enter image description here

关于我如何做到这一点的任何想法?我的配置(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

解决方法

您可以使用 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," $ 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