diff --git a/README.md b/README.md
index 4edb248..e358f0d 100644
--- a/README.md
+++ b/README.md
@@ -47,16 +47,19 @@ chmod +x install.sh
This is a little exemple of an custom theme.
If you are using `format_top/bottom` & `corner_top/bottom`, `format` will be ignored.
For making a single line prompt use `format`, and double line `format_top/bottom`.
+N.B : `path_slash_color` & `path_words_color` works with single and double line shell prompt.
Exemple :
```json
{
"name": "test",
"format": "[bold green][[{user}@{host}]][/][white][[{cwd}]] >>[/]",
- "format_top": "[bold cyan]{user}@{host}[/]",
- "format_bottom": "[bold yellow]{cwd}[/]",
+ "format_top": "[[[bold cyan]{user}[/]@[bold cyan]{host}[/]]]",
+ "format_bottom": "[[{cwd}]]",
"corner_top": "[bold magenta]\u250c[/]",
"corner_bottom": "[bold magenta]\u2514[/]",
- "ls_colors": "di=34:fi=37:ln=36:pi=33:so=35:ex=32"
+ "ls_colors": "di=34:fi=37:ln=36:pi=33:so=35:ex=32",
+ "path_slash_color": "cyan",
+ "path_words_color": "yellow"
}
```
@@ -64,7 +67,7 @@ The name of the theme is `test`, no matter what the file is named.
So enter the command : `settheme test`.
This is the result :
-
+
---
diff --git a/Shell/Themes/ThemeLoader.cs b/Shell/Themes/ThemeLoader.cs
index 3edbfe5..854cfb0 100644
--- a/Shell/Themes/ThemeLoader.cs
+++ b/Shell/Themes/ThemeLoader.cs
@@ -56,12 +56,29 @@ public static string[] ToStringValue(DefaultThemesEnum theme, string currentDire
},
DefaultThemesEnum.Light =>
new string[] {
- $"[white]\u250c[[{Environment.UserName}@{Environment.MachineName}]]\n\u2514[[{currentDirectory}]][/] >> ",
+ $"[white]\u250c[[[/][silver]{Environment.UserName}[/][red]@[/][silver]{Environment.MachineName}[/][white]]]\n\u2514[[[/]{ColorizePathLight("red", "silver", currentDirectory)}[white]]][/] >> ",
"di=37:fi=30:ln=36:pi=33:so=35:ex=32"
},
_ => new string[] { "[[[yellow]*[/]]] - Unknown theme" }
};
}
+
+ ///
+ /// Colors each character in the path for the Light theme:
+ /// '/' is colored red, other characters are colored silver.
+ ///
+ private static string ColorizePathLight(string slashColor, string wordsColor,string path)
+ {
+ var sb = new System.Text.StringBuilder();
+ foreach (var c in path)
+ {
+ if (c == '/')
+ sb.Append($"[{slashColor}]/[/]");
+ else
+ sb.Append($"[{wordsColor}]{c}[/]");
+ }
+ return sb.ToString();
+ }
///
/// Loads a custom theme from the ~/.nihilist_shell/themes/ directory,
@@ -101,22 +118,44 @@ public static string[] LoadCustomTheme(string themeName, string currentDirectory
string? formatBottom = data["format_bottom"]?.ToString();
string? cornerTop = data["corner_top"]?.ToString();
string? cornerBottom = data["corner_bottom"]?.ToString();
+ string? pathSlashColor = data["path_slash_color"]?.ToString();
+ string? pathWordsColor = data["path_words_color"]?.ToString();
string? colors = data["ls_colors"]?.ToString() ?? "di=34:fi=37:ln=36:pi=33:so=35:ex=32";
if (cornerTop != null && cornerBottom != null && formatTop != null && formatBottom != null)
{
- string prompt = $"{cornerTop}{formatTop.Replace("{user}", Environment.UserName).Replace("{host}", Environment.MachineName)}\n" +
- $"{cornerBottom}{formatBottom.Replace("{cwd}", currentDirectory)} >> ";
- return new[] { prompt, colors };
+ if (pathSlashColor != null && pathWordsColor != null)
+ {
+ string prompt = $"{cornerTop}{formatTop.Replace("{user}", Environment.UserName).Replace("{host}", Environment.MachineName)}\n" +
+ $"{cornerBottom}{formatBottom.Replace("{cwd}", ColorizePathLight(pathSlashColor, pathWordsColor, currentDirectory))} >> ";
+ return new[] { prompt, colors };
+ }
+ else
+ {
+ string prompt = $"{cornerTop}{formatTop.Replace("{user}", Environment.UserName).Replace("{host}", Environment.MachineName)}\n" +
+ $"{cornerBottom}{formatBottom.Replace("{cwd}", currentDirectory)} >> ";
+ return new[] { prompt, colors };
+ }
}
if (format != null)
{
- string prompt = format
- .Replace("{user}", Environment.UserName)
- .Replace("{host}", Environment.MachineName)
- .Replace("{cwd}", currentDirectory);
- return new[] { prompt, colors };
+ if (pathSlashColor != null && pathWordsColor != null)
+ {
+ string prompt = format
+ .Replace("{user}", Environment.UserName)
+ .Replace("{host}", Environment.MachineName)
+ .Replace("{cwd}", ColorizePathLight(pathSlashColor, pathWordsColor, currentDirectory));
+ return new[] { prompt, colors };
+ }
+ else
+ {
+ string prompt = format
+ .Replace("{user}", Environment.UserName)
+ .Replace("{host}", Environment.MachineName)
+ .Replace("{cwd}", currentDirectory);
+ return new[] { prompt, colors };
+ }
}
}
}