Highly rangefied dl command (from https://github.com/ueshita/dl-cmd)
/+ | |
The MIT License (MIT) | |
Copyright (c) 2015 ueshita, e10s | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
+/ | |
void main() | |
{ | |
import core.thread : Thread; | |
import core.time : msecs; | |
import std.algorithm.comparison : predSwitch; | |
import std.algorithm.iteration : each, joiner, map, splitter; | |
import std.conv : to; | |
import std.functional : unaryFun; | |
import std.range : chain, drop, enumerate, iota, repeat, tee, zip; | |
import std.range.primitives : front; | |
import std.stdio : stdout, write; | |
import std.typecons : No, tuple; | |
import consoled : clearScreen, setCursorPos, size; | |
[() => setCursorPos(0, 0)] | |
.tee!(_ => | |
` | |
_ _ | |
(_) (_) | |
/______ \ | |
\\(O(O \/ | |
| | | | | |
| |_| | | |
/______/ | |
` | |
.repeat | |
.zip( | |
[ | |
[" < >", " (_) (_)"], | |
[" (_) >", " (_)"], | |
[" < >", " (_) (_)"], | |
[" < (_)", " (_)"] | |
].map!(a => a.joiner("\n")) | |
) | |
.map!(t => chain(t.expand).to!string) | |
.unaryFun!(data => | |
0 | |
.iota(size.x + 20 + 1) | |
.map!(i => tuple(i / 6 % 4, size.x + 10 - i)) | |
.tee!(_ => clearScreen(), No.pipeOnPop) | |
.tee!(_ => Thread.sleep(20.msecs)) | |
.tee!(_ => stdout.flush()) | |
.each!(t => | |
((frame, offset) => | |
data | |
.drop(frame) | |
.front | |
.splitter("\n") | |
.enumerate!int | |
.map!(t => tuple(t.expand, cast(int)t[1].length)) | |
.each!(t => ( | |
(idx, line, len, writer) => | |
offset.predSwitch!"a>b"( | |
size.x - len, | |
offset < size.x && | |
writer(offset, idx + 2, line[0 .. size.x - offset]), | |
-1, | |
writer(offset, idx + 2, line), | |
-len, | |
writer(0, idx + 2, line[-offset .. $]), | |
false | |
) | |
)(t.expand, (int x, int y, string s) => | |
[true] | |
.tee!(_ => setCursorPos(x, y), No.pipeOnPop) | |
.tee!(_ => write(s), No.pipeOnPop) | |
.front) | |
) | |
)(t.expand) | |
) | |
) | |
, No.pipeOnPop) | |
.front()(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment