aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2021-04-01 13:29:39 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2021-04-01 13:29:39 -0400
commit6bee64ac64f28833f06efcebe832838d59ca3423 (patch)
treecead7e3a8e95c605988f68ff7ababb09e8dac306
parenta4665aa3c580b7bb078dc537bf414419b9d65b73 (diff)
downloadjdtalk-6bee64ac64f28833f06efcebe832838d59ca3423.tar.gz
Add talkf formatter function
-rw-r--r--README.md23
-rw-r--r--lib/jdtalk/core.d25
-rw-r--r--source/app.d15
3 files changed, 57 insertions, 6 deletions
diff --git a/README.md b/README.md
index 9043083..582aaa8 100644
--- a/README.md
+++ b/README.md
@@ -31,10 +31,33 @@ $ ./jdtalk
## Usage
```bash
+-f --format Produce words with formatted string
-c --limit (default: 0)
-p --pattern Limit output to a root word
-e --exact Exact matches only (default: false)
+-s --salad Produce N random words
+ --rcase Randomize case (default: false)
+ --hcase Change every other case (default: false)
+ --leet 1337ify output (default: false)
-d --dataroot Path to dictionaries
-h --help This help information.
```
+# Formatters
+
+For use with `--format`
+
+* `%a` - Adjective
+* `%d` - Adverb
+* `%n` - Noun
+* `%v` - Verb
+
+## Example
+
+```bash
+$ jdtalk --fmt "%a%a%n%d%v"
+hexadecimal satiric reconnoitrer ultimately beef
+[...]
+```
+
+This is not a print function, however. `--format "Are you a nice %a %n? Go %v in the mirror."` will produce `hairy mouse runs`, not `Are you a nice hairy mouse? Go run in the mirror."`.
diff --git a/lib/jdtalk/core.d b/lib/jdtalk/core.d
index c0fc376..aafe64a 100644
--- a/lib/jdtalk/core.d
+++ b/lib/jdtalk/core.d
@@ -186,3 +186,28 @@ string talkSalad(ref dict_t dict, int words) {
}
return salad.join(" ");
}
+
+string talkf(ref dict_t dict, string fmt) {
+ string[] output;
+ for (int i = 0; i < fmt.length; i++) {
+ if (fmt[i] == '%' && (i + 1) < fmt.length) {
+ switch (fmt[i + 1]) {
+ case 'a':
+ output ~= word(dict.adjective);
+ break;
+ case 'n':
+ output ~= word(dict.noun);
+ break;
+ case 'd':
+ output ~= word(dict.adverb);
+ break;
+ case 'v':
+ output ~= word(dict.verb);
+ break;
+ default:
+ continue;
+ }
+ }
+ }
+ return output.join(" ");
+}
diff --git a/source/app.d b/source/app.d
index a094fcd..e816d8b 100644
--- a/source/app.d
+++ b/source/app.d
@@ -14,17 +14,17 @@ import std.process : environment;
import jdtalk.core;
-
int main(string[] args)
{
import std.getopt;
- long i = 0,
- limit = 0;
+ long i = 0;
+ long limit = 0;
int salad = 0;
bool exactMatch = false;
bool rCase = false;
bool hCase = false;
bool haxor = false;
+ string custom_format = null;
string pattern = null;
string dataRoot = absolutePath(getcwd());
@@ -34,6 +34,7 @@ int main(string[] args)
auto opt = getopt(
args,
+ "format|f", "Produce words with formatted string", &custom_format,
"limit|c", format("(default: %d)", limit), &limit,
"pattern|p", "Limit output to a root word", &pattern,
"exact|e", format("Exact matches only (default: %s)", exactMatch ? "true" : "false"), &exactMatch,
@@ -45,8 +46,7 @@ int main(string[] args)
);
if (opt.helpWanted) {
- defaultGetoptPrinter("jdtalk",
- opt.options);
+ defaultGetoptPrinter("jdtalk", opt.options);
return 0;
}
@@ -68,8 +68,11 @@ int main(string[] args)
if (salad) {
output = talkSalad(dict, salad);
}
+ else if (custom_format) {
+ output = talkf(dict, custom_format);
+ }
else {
- output = talk(dict);
+ output = talkf(dict, "%a %n %d %v");
}
if (pattern !is null) {