If the hg program is not found, then there used to be a Lua script
error. I fixed that in the earlier commit in this PR. But the fix
was incomplete, and the hg prompt still appended " ()" instead of
not appending anything (which is how the svn prompt behaves when
the svn program is not found).
Cmder's hg prompt didn't use async prompt filtering yet.
Cmder's svn prompt only used async prompt filtering if a special config
variable was set (the commit which contributed it seems to have
misunderstood the git config settings for the git async prompt).
This commit makes the following changes:
1. Adds async prompt filtering for hg.
2. Makes async prompt filtering for svn the default.
3. Removes the prompt_overrideSvnStatusOptIn variable.
4. Fixes a bug where any errors during `svn status` in the svn prompt
accidentally show up in the terminal.
5. Fixes a bug where any errors during `hg branch` in the hg prompt
turn into Lua errors.
6. Simplifies the code for colors in the hg and svn prompts.
7. Clean up the svn prompt code and make it consistent with the git
and hg prompt code.
- `getGitStatusSetting`: use local variables, improve regex pattern, use return status codes instead of echo strings
- `getSimpleGitBranch`: better error handling, use local variables
- Simplified conditional checks
The `string.gsub()` function in Lua always uses Lua patterns (which are
similar to regular expressions). Cmder's custom prompt wants to perform
simple plain text find/replace operations on strings. `string.gsub()`
is the right Lua function for that, but since it always uses Lua
patterns it's necessary to apply escaping to the input strings otherwise
they can get misinterpreted and cause runtime errors.
For example, if the current working directory name contains a percent
sign, such as literally "My%20Home".
This change fixes that. It introduces a helper function `gsub_plain()`
which behaves like `string.gsub()` but applies appropriate escaping to
convert the plain text input strings into the corresponding Lua
patterns so that it can achieve plain text find/replace operations.
It also introduces separate helper functions for escaping the `find` and
`replace` parameters for `string.gsub()`, since they have different
escaping rules.