如何在 ghci 提示符下不显示重复模块
How to not display duplicate modules on ghci prompt
目前我的 ghci 提示是这样的:
而且我想这样做,这样我的提示就不会显示重复的模块,如下所示:
但我真的不知道怎么做。我的配置(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"
提前致谢。
通过使用 nub
从列表中删除重复元素(参见:https://hoogle.haskell.org/?hoogle=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
是 Data.List 模块的一部分,我还必须包括:
import Data.List
目前我的 ghci 提示是这样的:
而且我想这样做,这样我的提示就不会显示重复的模块,如下所示:
但我真的不知道怎么做。我的配置(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"
提前致谢。
通过使用 nub
从列表中删除重复元素(参见:https://hoogle.haskell.org/?hoogle=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
是 Data.List 模块的一部分,我还必须包括:
import Data.List