PowerShell / ProjectMercury

An interactive shell to work with AI-powered assistance providers
MIT License
52 stars 13 forks source link

Improve syntax highlighting for bash/pwsh and add the parameter `-streaming` to `/render` #149

Closed daxian-dbw closed 4 months ago

daxian-dbw commented 4 months ago

PR Summary

Improve syntax highlighting for bash/pwsh and add the parameter -streaming to /render.

  1. Fix the regular expression used for native command options like --word to not capture the preceding whitespaces.
  2. Make the regex consume the potential value specified in the form of --word=value, so that the value part won't be matched by other rules.
  3. Make PowerShell syntax able to capture native command options too.
  4. Update the regex for PowerShell command to be more accurate and able to capture names without dash - in it.
  5. Add the parameter -streaming to /render to render in streaming manner.

I will use the below markdown-1 as an example to show the difference before and after the change for PowerShell rendering.

1. VM:
   ```powershell
   (get-command) |az account list | az storage add
   $frontendSubnet = New-AzVirtualNetwork -Name frontendSubnet -AddressPrefix "10.0.1.0/24" -Credential (Get-Credential)
   $def = abc | def | ggg | get-com
   $ppp = (abc -abc | def | get-ppp)
   gcloud INSTANCE_NAME \
       --image-family=ubuntu-2004-lts \
       --image-project=ubuntu-os-cloud \
       --machine-type=e2 --use-polling

**Before the change**

![image](https://github.com/PowerShell/AISH/assets/127450/c49e00bb-80af-4e92-83b1-d7c413310d2a)

**After the change**

![image](https://github.com/PowerShell/AISH/assets/127450/46716cc5-2b13-4535-889b-c782bb94e915)

Now use the below markdown-2 as an example to show the difference for bash rendering
  1. VM:
    gcloud INSTANCE_NAME \
       --image-family=ubuntu-2004-lts \
       --image-project=ubuntu-os-cloud \
       --machine-type=e2 --use-polling

Before the change (streaming rendering is messed up)

image

After the change

image