forked from FunkinDroidTeam/lime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLIHelper.hx
93 lines (78 loc) · 1.37 KB
/
CLIHelper.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package lime.tools;
import haxe.io.Eof;
import hxp.*;
class CLIHelper
{
public static function ask(question:String, options:Array<String> = null):Answer
{
if (options == null)
{
options = ["y", "n", "a"];
}
while (true)
{
Log.print(Log.accentColor + question + "\x1b[0m \x1b[3;37m[" + options.join("/") + "]\x1b[0m ? ");
try
{
switch (readLine())
{
case "n":
return NO;
case "y":
return YES;
case "a":
return ALWAYS;
case _ => x if (options.indexOf(x) > -1):
return CUSTOM(x);
}
}
catch (e:Dynamic)
{
Sys.exit(0);
}
}
return null;
}
public static inline function getChar():Int
{
return Sys.getChar(false);
}
public static function param(name:String, passwd:Bool = false):String
{
Log.print(name + ": ");
if (passwd)
{
var s = new StringBuf();
var c;
while ((c = getChar()) != 13)
s.addChar(c);
Log.print("");
Log.println("");
return s.toString();
}
try
{
return readLine();
}
catch (e:Eof)
{
return "";
}
}
public static function progress(prefix:String, now:Int, total:Int):Void
{
var percent = Math.floor((now / total) * 100);
Log.print('\r$prefix $now/$total ($percent%)');
}
public static inline function readLine():String
{
return Sys.stdin().readLine();
}
}
enum Answer
{
YES;
NO;
ALWAYS;
CUSTOM(answer:String);
}