mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
general refactoring: imports and conversions
This commit is contained in:
parent
22d0677e9c
commit
8c9a5c3e47
1 changed files with 14 additions and 10 deletions
24
asino.d
24
asino.d
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue