Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,27 @@ chmod +x install.sh
This is a little exemple of an custom theme.</br>
If you are using `format_top/bottom` & `corner_top/bottom`, `format` will be ignored.</br>
For making a single line prompt use `format`, and double line `format_top/bottom`.</br>
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"
}
```

The name of the theme is `test`, no matter what the file is named.</br>
So enter the command : `settheme test`.</br>
This is the result :

![Preview Test Theme](https://github.com/user-attachments/assets/21eb8e58-4e36-4d9e-b057-de107a4b2727)
![Preview Test Theme](https://github.com/user-attachments/assets/eaea69b7-0f9e-4f0f-8d0b-7c92ffe8c4f1)

---

Expand Down
57 changes: 48 additions & 9 deletions Shell/Themes/ThemeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
};
}

/// <summary>
/// Colors each character in the path for the Light theme:
/// '/' is colored red, other characters are colored silver.
/// </summary>
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();
}

/// <summary>
/// Loads a custom theme from the <c>~/.nihilist_shell/themes/</c> directory,
Expand Down Expand Up @@ -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 };
}
}
}
}
Expand Down
Loading