Home > Software design >  Colored ghci output on PowerShell
Colored ghci output on PowerShell

Time:04-21

Some time ago, I stumbled upon this. However, since I'm using Windows, I'm unable to run it. Hence, I decided to create a .ps1 version of it so I would be able to run it in PowerShell. However I've been getting the following error:

Line |
  25 |  Invoke-Expression (Get-Command ghci).Path $args 2>&1 | `
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | A positional parameter cannot be found that accepts argument 'System.Object[]'.

My complete code can be found here and the specific part where the error lies is as follows:

Invoke-Expression (Get-Command ghci).Path $args 2>&1 | `
    sed "$load_failed `
         $load_done `
         $no_instance `
         $interactive `
         $double_colon ` 
         $right_arrow `
         $right_arrow2 `
         $parenthesis ` 
         $left_blacket `
         $right_blacket `
         $double_colon `
         $calc_operators `
         $string `
         $char" 

Also, the original code I'm trying to convert, written in shell script(.sh), is as follows

exec "`which ghc`" --interactive ${1 "$@"} 2>&1 |\
    sed "$load_failed\
         $load_done\
         $no_instance\
         $interactive\
         $double_colon\
         $right_arrow\
         $right_arrow2\
         $parenthesis\
         $left_blacket\
         $right_blacket\
         $double_colon\
         $calc_operators\
         $string\
         $char"

And I'd like to clarify that I have installed sed on my PowerShell. Thank you in advance.

Update

I've managed to resolve the earlier mentioned error thanks to @Mike Anthony's suggestion to use @args instead of $args. However, I seem to be getting another error as shown below:

sed: 13: "s/^Failed, modules load ...": unbalanced brackets ([])

Apparently there seems to be an error with the following part of my code:

$load_failed="s/^Failed, modules loaded:/$RED&$RESET/;"
$load_done="s/done./$GREEN&$RESET/g;"
$double_colon="s/::/$PURPLE&$RESET/g;"
$right_arrow="s/\->/$PURPLE&$RESET/g;"
$right_arrow2="s/=>/$PURPLE&$RESET/g;"
$calc_operators="s/[ \-\/*]/$PURPLE&$RESET/g;"
$char="s/'\\?.'/$RED&$RESET/g;"
$string="s/`"[^`"]*`"/$RED&$RESET/g;"
$parenthesis="s/[{}()]/$BLUE&$RESET/g;"
$left_blacket="s/\[\([^09]\)/$BLUE[$RESET\1/g;"
$right_blacket="s/\]/$BLUE&$RESET/g;"
$no_instance="s/^\s*No instance/$RED&$RESET/g;"
$interactive="s/^<[^>]*>/$RED&$RESET/g;"

and more specifically:

$string="s/`"[^`"]*`"/$RED&$RESET/g;"

The original code written in shell script reads:

string="s/\"[^\"]*\"/$RED&$RESET/g;"

I'm really confused where the unbalanced brackets are so any help would be greatly appreciated.

CodePudding user response:

I don't think you need Invoke-Expression at all, just use ghci as if you would on the command line e.g. (assuming ghc is added to your PATH variable)

$ret = ghci @args

CodePudding user response:

Seems like there are two layers of escaping going on.

Try:

$string="s/`"[^\`"]*`"/$CYAN&$RESET/g;"

Instead of:

$string="s/`"[^`"]*`"/$RED&$RESET/g;"
  • Related