【问题标题】:How to set GHCi prompt to display modules separated by a custom separator?如何设置 GHCi 提示以显示由自定义分隔符分隔的模块?
【发布时间】:2020-12-28 11:53:51
【问题描述】:

目前这是我的 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

【问题讨论】:

    标签: haskell prompt ghci


    【解决方案1】:

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

    【讨论】:

    • 非常感谢!我有一个问题,我使用了您在上面提供给我的代码并将其设置为:link,结果是这样的:link,但是,每当我按下 ctrl-l(清除屏幕)它变成这样:link。您是否知道为什么会发生这种情况以及我如何使它看起来像:link 每当我清除终端屏幕时? @Aplet123
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    相关资源
    最近更新 更多