Skip to content

Commit c433e74

Browse files
committed
Feature: Add ASCII table command.
1 parent dccc249 commit c433e74

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Code authored by Dean Edis (DeanTheCoder).
2+
// Anyone is free to copy, modify, use, compile, or distribute this software,
3+
// either in source code form or as a compiled binary, for any non-commercial
4+
// purpose.
5+
//
6+
// If you modify the code, please retain this copyright header,
7+
// and consider contributing back to the repository or letting us know
8+
// about your modifications. Your contributions are valued!
9+
//
10+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
using G33kShell.Desktop.Terminal.Attributes;
14+
15+
namespace G33kShell.Desktop.Terminal.Commands;
16+
17+
[CommandDescription("Displays a full ASCII table (0–255) using box drawing characters.", "Example: ascii")]
18+
public class AsciiCommand : CommandBase
19+
{
20+
private static readonly char[] Cp437 =
21+
{
22+
'·','☺','☻','♥','♦','♣','♠','•','◘','○','◙','♂','♀','♪','♫','☼',
23+
'►','◄','↕','‼','¶','§','▬','↨','↑','↓','→','←','∟','↔','▲','▼',
24+
' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',
25+
'0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
26+
'@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
27+
'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_',
28+
'`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
29+
'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','⌂',
30+
'Ç','ü','é','â','ä','à','å','ç','ê','ë','è','ï','î','ì','Ä','Å',
31+
'É','æ','Æ','ô','ö','ò','û','ù','ÿ','Ö','Ü','¢','£','¥','₧','ƒ',
32+
'á','í','ó','ú','ñ','Ñ','ª','º','¿','⌐','¬','½','¼','¡','«','»',
33+
'░','▒','▓','│','┤','Á','Â','À','©','╣','║','╗','╝','¢','¥','┐',
34+
'└','┴','┬','├','─','┼','ã','Ã','╚','╔','╩','╦','╠','═','╬','¤',
35+
'ð','Ð','Ê','Ë','È','ı','Í','Î','Ï','┘','┌','█','▄','¦','Ì','▀',
36+
'Ó','ß','Ô','Ò','õ','Õ','µ','þ','Þ','Ú','Û','Ù','ý','Ý','¯','´',
37+
'≡','±','‗','¾','¶','§','÷','¸','°','¨','·','¹','³','²','■',' '
38+
};
39+
40+
protected override Task<bool> Run(ITerminalState state)
41+
{
42+
const int cols = 16;
43+
const int rows = 16;
44+
45+
WriteLine("┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐");
46+
for (var row = 0; row < rows; row++)
47+
{
48+
var line = new StringBuilder("│");
49+
for (var col = 0; col < cols; col++)
50+
{
51+
var code = row * cols + col;
52+
var c = Cp437[code];
53+
var display = char.IsControl(c) ? "·" : c.ToString();
54+
line.Append($"{code,3:D3}:{display}│");
55+
}
56+
WriteLine(line.ToString());
57+
if (row < rows - 1)
58+
WriteLine("├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤");
59+
}
60+
WriteLine("└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘");
61+
62+
return Task.FromResult(true);
63+
}
64+
}

G33kShell.Desktop/Terminal/Commands/MyCommandType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
using G33kShell.Desktop.Terminal.Attributes;
1313
using NClap.Metadata;
14+
1415
// ReSharper disable UnusedMember.Global
1516

1617
namespace G33kShell.Desktop.Terminal.Commands;
@@ -80,6 +81,10 @@ public enum MyCommandType
8081
PushD,
8182

8283
// System & Utility
84+
[Command(typeof(AsciiCommand), LongName = "ascii", Description = "Displays an ASCII table.")]
85+
[CommandCategory(CommandType.System)]
86+
Ascii,
87+
8388
[Command(typeof(ClearCommand), LongName = "clear", ShortName = "cls", Description = "Clear the terminal.")]
8489
[CommandCategory(CommandType.System)]
8590
Clear,

G33kShell.sln.DotSettings.user

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AChar_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fcfe540186e1777b77d9ce13918594674cdf294c66b9582775ad6c29ed383fa_003FChar_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
66
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACommandAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ff1d061b2474c4316b57be5157b9e2b7c3cc00_003Fdd_003F38df74e1_003FCommandAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
77
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F326268ddb927895dce924c78646b4d4ce2b05971ed1d8c9be99051ad1d2_003FDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
8+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADirectoryInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fe4ec446cfe0489bc3ef68a45c6766d183e999ebdc657e94fb1ad059de2bb9_003FDirectoryInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
89
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADouble_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F97735572759ed38d9ce0373eff8d5c81728b76ebad7201de74c8191af042e_003FDouble_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
910
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADriveType_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F787e459dfcbf4e599345a06d67315ac312c00_003F89_003F60d2c37c_003FDriveType_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
11+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEncoding_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F711a33e84967ee4499dfa06b495a209bd6ceb727a3eb6f201060e84161_003FEncoding_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1012
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0d7bcd21e5fc4d22acf66909cc56501684928_003F3c_003F054457f0_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1113
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnvironment_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fd5e26b7cbc3c8ffaa5eb6b56961c2ddefd21293d38d4a648eeb54d2d127492de_003FEnvironment_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1214
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFIGletFont_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0545674b691e481a8b2ad05064279b055a00_003F69_003F9878386c_003FFIGletFont_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

0 commit comments

Comments
 (0)