Home > Software design >  How to not display duplicate modules on ghci prompt
How to not display duplicate modules on ghci prompt

Time:04-17

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.

CodePudding user response:

By using nub which removes duplicate elements from a list (see: 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
  • Related