diff --git a/color.d b/color.d index d1e8c48..89bab58 100644 --- a/color.d +++ b/color.d @@ -2,7 +2,11 @@ import std.typecons : Flag; alias UseColor = Flag!"UseColor"; -alias ZshEscapes = Flag!"ZshEscapes"; +enum Escapes { + none, + bash, + zsh +} mixin(makeColorFunction("cyan", 36)); mixin(makeColorFunction("green", 32)); @@ -17,10 +21,17 @@ string makeColorFunction(string name, int code) import std.conv : to; return ` - string ` ~ name ~ `(ZshEscapes escapes) + string ` ~ name ~ `(Escapes escapes) { string ret = "\33[` ~ code.to!string ~ `m"; - return escapes ? zshEscape(ret) : ret; + final switch (escapes) { + case Escapes.none: + return ret; + case Escapes.bash: + return bashEscape(ret); + case Escapes.zsh: + return zshEscape(ret); + } } `; } @@ -29,3 +40,8 @@ string zshEscape(string code) { return "%{" ~ code ~ "%}"; } + +string bashEscape(string code) +{ + return `\[` ~ code ~ `\]`; +} diff --git a/git.d b/git.d index 8cb4051..279592e 100644 --- a/git.d +++ b/git.d @@ -35,7 +35,7 @@ struct RepoStatus { * escapes = Whether or not ZSH escapes are needed. Ignored if no colors are desired. * */ -string stringRepOfStatus(Duration allottedTime, UseColor colors, ZshEscapes escapes) +string stringRepOfStatus(Duration allottedTime, UseColor colors, Escapes escapes) { // getRepoStatus will return null if we are not in a repo auto status = getRepoStatus(allottedTime); @@ -44,7 +44,7 @@ string stringRepOfStatus(Duration allottedTime, UseColor colors, ZshEscapes esca // Local function that colors a source string if the colors flag is set. string colorText(string source, - string function(ZshEscapes) colorFunction) + string function(Escapes) colorFunction) { if (!colors) return source; diff --git a/promptd-path.d b/promptd-path.d index 222b876..4b9dc51 100644 --- a/promptd-path.d +++ b/promptd-path.d @@ -49,7 +49,7 @@ void main(string[] args) } string versionString = q"EOS -promptd-path by Matt Kline, version 0.2 +promptd-path by Matt Kline, version 0.3 Part of the promptd tool set EOS"; diff --git a/promptd-vcs.d b/promptd-vcs.d index f9bba39..c7c8fff 100644 --- a/promptd-vcs.d +++ b/promptd-vcs.d @@ -12,7 +12,7 @@ void main(string[] args) { uint timeLimit = 500; bool noColor; - bool zsh; + bool bash, zsh; try { getopt(args, @@ -22,22 +22,34 @@ void main(string[] args) "version|v", { writeAndSucceed(versionString); }, "time-limit|t", &timeLimit, "no-color", &noColor, + "bash|b", &bash, "zsh|z", &zsh); } catch (GetOptException ex) { writeAndFail(ex.msg, "\n", helpString); } + if (bash && zsh) + writeAndFail("Both --bash and --zsh specified. Wat."); + + Escapes escapesToUse; + if (bash) + escapesToUse = Escapes.bash; + else if (zsh) + escapesToUse = Escapes.zsh; + else // Redundant (none is the default), but more explicit. + escapesToUse = Escapes.none; + string vcsInfo = stringRepOfStatus( timeLimit.msecs, noColor ? UseColor.no : UseColor.yes, - zsh ? ZshEscapes.yes : ZshEscapes.no); + escapesToUse); write(vcsInfo); } string versionString = q"EOS -promptd-vcs by Matt Kline, version 0.2 +promptd-vcs by Matt Kline, version 0.3 Part of the promptd tool set EOS"; @@ -67,7 +79,11 @@ Options: --no-color Disables colored output, which is on by default - --zsh|z + --bash, -b + Used to emit additional escapes needed for color sequences in Bash prompts. + Ignored if --no-color is specified. + + --zsh, -z Used to emit additional escapes needed for color sequences in ZSH prompts. Ignored if --no-color is specified.