如何在 ghci 提示符下不显示重复的模块

发布于 2025-01-21 02:30:53 字数 1649 浏览 1 评论 0 原文

目前,这就是我的GHCI提示的样子:

”在此处输入图像描述

,我想做到这一点,以便我的提示不显示重复模块,如下所示:

​T真的弄清楚了如何。我的配置(ghci.conf)文件的内容如下所示:

:set +m

import qualified IPPrint
import qualified Language.Haskell.HsColour as HsColour
import qualified Language.Haskell.HsColour.Colourise as HsColour
import qualified Language.Haskell.HsColour.Output as HsColour

let myColourPrefs = HsColour.defaultColourPrefs { HsColour.conid = [HsColour.Foreground HsColour.Yellow, HsColour.Bold], HsColour.conop = [HsColour.Foreground HsColour.Yellow], HsColour.string = [HsColour.Foreground HsColour.Green], HsColour.char = [HsColour.Foreground HsColour.Cyan], HsColour.number = [HsColour.Foreground HsColour.Red, HsColour.Bold], HsColour.layout = [HsColour.Foreground HsColour.White], HsColour.keyglyph = [HsColour.Foreground HsColour.White] }

let myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow

:set -interactive-print=myPrint

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

谢谢您。

Currently this is how my ghci prompt looks like:

enter image description here

and I want to make it so that my prompt doesn't display duplicate modules as shown below:

enter image description here

but I can't really figure out how. My configuration(ghci.conf) file's contents is as shown below:

:set +m

import qualified IPPrint
import qualified Language.Haskell.HsColour as HsColour
import qualified Language.Haskell.HsColour.Colourise as HsColour
import qualified Language.Haskell.HsColour.Output as HsColour

let myColourPrefs = HsColour.defaultColourPrefs { HsColour.conid = [HsColour.Foreground HsColour.Yellow, HsColour.Bold], HsColour.conop = [HsColour.Foreground HsColour.Yellow], HsColour.string = [HsColour.Foreground HsColour.Green], HsColour.char = [HsColour.Foreground HsColour.Cyan], HsColour.number = [HsColour.Foreground HsColour.Red, HsColour.Bold], HsColour.layout = [HsColour.Foreground HsColour.White], HsColour.keyglyph = [HsColour.Foreground HsColour.White] }

let myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow

:set -interactive-print=myPrint

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

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2025-01-28 02:30:53

通过使用 nub 从列表中删除重复元素(请参阅:),我能够从模块列表中删除重复元素,如下所示:

“在此处输入图像描述”

为了做代码,代码也必须必须被修改为:

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

并且由于 nub 是数据的一部分。清单模块,我还必须包括:

import Data.List

By using nub which removes duplicate elements from a list (see: https://hoogle.haskell.org/?hoogle=nub), I was able to remove duplicate elements from the module list as shown below:

enter image description here

In order to do that the code also has to be modified to:

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

and since nub is part of the Data.List module, I had to also include:

import Data.List
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文