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+ }
0 commit comments