Skip to content

Commit

Permalink
Add extra Windows/DOS translations
Browse files Browse the repository at this point in the history
  • Loading branch information
githubcatw committed Aug 24, 2021
1 parent a50837c commit cc8eeeb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
8 changes: 7 additions & 1 deletion GeekSay.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
using System;
using System.Linq;

namespace GeekSay.Cli {
class Program {
static void Main(string[] args) {
if (args.Length > 0) Console.WriteLine(Geek.Say(args));
if (args.Length > 0) {
if (args[0] == "--dos")
Console.WriteLine(Geek.Say(args.Skip(1).ToArray(), true));
else
Console.WriteLine(Geek.Say(args));
}
else Console.WriteLine(Geek.SaySomething());
}
}
Expand Down
14 changes: 10 additions & 4 deletions GeekSay/Geek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ public static class Geek {
/// Convert something from layman text to geek text.
/// </summary>
/// <param name="text">The text to convert.</param>
public static string Say(string text) => Say(text.Split(' '));
/// <param name="dos">Whether to enable extra Windows/DOS related translations.</param>
public static string Say(string text, bool dos = false) => Say(text.Split(' '), dos);

/// <summary>
/// Convert something from layman text to geek text.
/// </summary>
/// <param name="text">The text to convert.</param>
public static string Say(string[] text) {
var geekized = text.Select(e => SayWord(e)).ToArray();
/// <param name="dos">Whether to enable extra Windows/DOS related translations.</param>
public static string Say(string[] text, bool dos = false) {
var geekized = text.Select(e => SayWord(e, dos)).ToArray();
return string.Join(" ",geekized);
}

/// <summary>
/// Convert a word from layman text to geek text.
/// </summary>
/// <param name="word">The word to convert.</param>
public static string SayWord(string word) {
/// <param name="dos">Whether to enable extra Windows/DOS related translations.</param>
public static string SayWord(string word, bool dos = false) {
int wordNum;
if (int.TryParse(word, out wordNum)) {
return Convert.ToString(wordNum, 2);
Expand All @@ -35,6 +38,9 @@ public static string SayWord(string word) {
if (GeekWords.conversions.ContainsKey(lowerWord)) {
word = word.Replace(word, GeekWords.conversions[lowerWord]);
}
else if (dos && GeekWords.winwords.ContainsKey(lowerWord)) {
word = word.Replace(word, GeekWords.winwords[lowerWord]);
}
return word;
}
}
Expand Down
9 changes: 9 additions & 0 deletions GeekSay/GeekWords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public static class GeekWords {
{"nothing", "void"}
};

/// <summary>
/// Extra translations for Windows/DOS things.
/// </summary>
public static readonly Dictionary<string, string> winwords = new Dictionary<string, string>() {
{"prompt","$P$G"},
{"nowhere","NUL"},
{"library","dll"}
};

/// <summary>
/// Geeky quotes in layman text.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It's available on NuGet as [GeekSay](https://www.nuget.org/packages/GeekSay).

### CLI

Without arguments it generates a random quote.
Without arguments it generates a random quote. If the first argument is `--dos`, DOS/Windows related translations are enabled.

```
$p$g>geeksay-cli to be or not to be, that is the question
Expand All @@ -20,13 +20,20 @@ to be || ! to be, that is the ?
$p$g>geeksay-cli please make me a sandwich
sudo make self a sandwich
$p$g>geeksay-cli --dos I am going to the library
I am going to the dll
$p$g>geeksay-cli
Random translation: send -> push
```

### Library

The second argument for `Say()` and `SaySomething()` enable DOS/Windows related translations.

```c#
Geek.Say("there is no place like home"); // there is no place like 127.0.0.1
Geek.Say("that packet was sent to nowhere", true); // that packet was sent to NUL
Geek.SaySomething(); // Random translation: smile -> :)
Geek.SayWord("white"); // #fff
```

0 comments on commit cc8eeeb

Please sign in to comment.