general refactoring: imports and conversions

This commit is contained in:
Francesco Mecca 2019-06-13 10:04:38 +02:00
parent 22d0677e9c
commit 8c9a5c3e47

24
asino.d
View file

@ -6,13 +6,14 @@
*/ */
module asino; module asino;
import std.stdio;
import std.random; import std.random;
import std.getopt; import std.getopt;
import std.file;
import std.conv; import std.stdio : writeln, writefln, stdin;
import std.array; import std.file : read;
import std.algorithm; import std.typecons : Yes, No;
import std.array : join, array;
import std.algorithm : splitter;
extern(C) extern(C)
{ {
@ -49,15 +50,18 @@ main (string[] args)
writeln(versionSt); writeln(versionSt);
} }
string[] toProcess = void; string[] lines = void;
writeln(isaTTY());
if(isaTTY()){ if(isaTTY()){
// read stdin, ignore cli args // read stdin, ignore cli args
toProcess = to!(string[])(File("/dev/stdin").byLineCopy.array()); auto p = stdin.byLineCopy(No.keepTerminator).array();
writeln(p[2]);
lines = p;
} else { } else {
toProcess = args[1 .. $]; // remove program name lines = args[1 .. $]; // remove program name
} }
auto res = toProcess.divide(div).shuffle(engine); auto res = lines.divide(div).shuffle(engine);
foreach (i, arg; res) { foreach (i, arg; res) {
if (!num) writeln(arg); if (!num) writeln(arg);
@ -68,7 +72,7 @@ main (string[] args)
string[] divide(string[] args, string div) string[] divide(string[] args, string div)
{ {
if (div == "") return args; if (div == "") return args;
else return to!(string[])(args.join.splitter(div).array); else return args.join.splitter(div).array;
} }
string[] shuffle(string[] args, string t) string[] shuffle(string[] args, string t)