PowerShell上的彩色GHCI输出

发布于 2025-01-21 21:21:09 字数 2798 浏览 0 评论 0原文

不久前,我偶然发现了 this 。但是,由于我正在使用Windows,因此无法运行它。因此,我决定创建一个.ps1版本,因此我可以在PowerShell中运行它。但是,我一直在遇到以下错误:

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

可以找到我的完整代码在这里谎言如下:

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" 

另外,我要转换的原始代码,用shell脚本(.sh)编写,如下所示

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"

,我想澄清一下我已经在我的Powershell。先感谢您。

更新

我已经设法解决了以下提到的错误,多亏了 @mike Anthony 建议使用@args而不是$ $ args。但是,我似乎会遇到另一个错误,如下所示:

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

显然,我的代码的以下部分似乎存在错误:

$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;"

更具体地说:

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

用Shell脚本编写的原始代码读:

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

我真的很困惑不平衡的括号因此,任何帮助将不胜感激。

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.

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

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

发布评论

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

评论(2

¢蛋碎的人ぎ生 2025-01-28 21:21:09

我认为您根本不需要Invoke-Expression,只需使用GHCI就好像您在命令行中一样(假设GHC已添加到路径变量中)

$ret = ghci @args

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
葬シ愛 2025-01-28 21:21:09

似乎有两层逃脱。

尝试:

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

而不是:

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

Seems like there are two layers of escaping going on.

Try:

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

Instead of:

$string="s/`"[^`"]*`"/$RED&$RESET/g;"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文