Skip to content

Commit c06fb74

Browse files
authored
Add files via upload
Added GUI
1 parent 42817a9 commit c06fb74

4 files changed

Lines changed: 252 additions & 85 deletions

File tree

com/devkev/devscript/raw/ApplicationInput.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public int read() throws IOException {
2525
}
2626
index++;
2727
if(index < data.length() && !data.isEmpty()) {
28-
System.out.println("Fetching data... " + data.getBytes()[index-1]);
2928
return data.getBytes()[index-1];
3029
} else {
3130
inputReqested = false;

com/devkev/devscript/raw/ConsoleMain.java

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,80 @@
1414
* -f or --file [path] - Reads the file and executes the code from it.<br>
1515
* If no argument was passed, the default Editor GUI will open.*/
1616
public class ConsoleMain {
17+
18+
/*Argument schema: -f <string> -e <string> --nogui </>
19+
* When nogui is not given, the gui program will start with the given script from the command line
20+
* */
21+
1722
public static void main(String[] args) throws IOException {
18-
Process p = new Process(true);
19-
p.addSystemOutput();
20-
p.setInput(System.in);
21-
22-
if(args.length == 0) {
23-
if(ConsoleMain.class.getResourceAsStream("/Editor.txt") == null) {
24-
System.err.println("Editor file is missing at: " + URLDecoder.decode(ConsoleMain.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"));
25-
return;
26-
}
27-
BufferedReader reader = new BufferedReader(new InputStreamReader(ConsoleMain.class.getResourceAsStream("/Editor.txt")));
28-
String code = "";
29-
String line = reader.readLine();
30-
while(line != null) {
31-
code += line;
32-
line = reader.readLine();
23+
boolean initGUI = true;
24+
String scriptToExecute = null;
25+
String filePath = null;
26+
//ALL arguments need to be checked
27+
28+
for(int i = 0; i < args.length; i++) {
29+
if((args[i].equals("-e") || args[i].equals("--execute")) && scriptToExecute == null) {
30+
if(i + 1 < args.length) {
31+
if(!isArgument(args[i+1])) {
32+
scriptToExecute = args[i+1];
33+
i++; //Skip the next iteration
34+
continue;
35+
}
36+
}
37+
throw new IllegalArgumentException("Expecting string after " + args[i] + " [script_to_execute]");
38+
} else if((args[i].equals("-f") || args[i].equals("--file")) && filePath == null) {
39+
if(i + 1 < args.length) {
40+
if(!isArgument(args[i+1])) {
41+
filePath = args[i+1];
42+
i++;
43+
continue;
44+
}
45+
}
46+
throw new IllegalArgumentException("Expecting string after " + args[i] + " [path_to_file]");
47+
} else if(args[i].equals("--nogui")) {
48+
initGUI = false;
49+
continue;
3350
}
34-
reader.close();
35-
p.execute(code, false);
36-
return;
51+
System.out.println("Valid arguments are:\n-f | --file\tOpens the file in the editor (If --nogui is set, the file is executed)\n-e | --execute\tOpens the script with the editor (If --nogui is set, the script is executed)\n | --nogui\tOpens the command line editor");
52+
throw new IllegalArgumentException("Unknown argument " + args[i] );
3753
}
3854

39-
if(args[0].equals("-e") || args[0].equals("--execute")) {
40-
if(args.length < 2) {
41-
System.err.println("Argument " + args[0] + " expects an executable script, e.g.: -e \"println \"Hello World;\"\"");
42-
System.exit(-1);
55+
if(initGUI) {
56+
Window w = new Window();
57+
if(filePath != null) {
58+
w.openDocument(new File(filePath));
59+
} else if(scriptToExecute != null) {
60+
w.setScript(scriptToExecute);
4361
}
44-
p.execute(args[1], true);
45-
} else if(args[0].equals("-f") || args[0].equals("--file")) {
46-
if(args.length < 2) {
47-
System.err.println("Argument " + args[0] + " expects a path to a text file containing the script");
48-
System.exit(-1);
62+
} else {
63+
Process p = new Process(true);
64+
p.addSystemOutput();
65+
p.setInput(System.in);
66+
67+
if(filePath != null) {
68+
p.execute(new File(args[1]), true);
69+
} else if(scriptToExecute != null) {
70+
p.execute(args[1], true);
71+
} else {
72+
if(ConsoleMain.class.getResourceAsStream("/Editor.txt") == null) {
73+
System.err.println("Editor file is missing at: " + URLDecoder.decode(ConsoleMain.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"));
74+
return;
75+
}
76+
BufferedReader reader = new BufferedReader(new InputStreamReader(ConsoleMain.class.getResourceAsStream("/Editor.txt")));
77+
String code = "";
78+
String line = reader.readLine();
79+
while(line != null) {
80+
code += line;
81+
line = reader.readLine();
82+
}
83+
reader.close();
84+
p.execute(code, false);
85+
return;
4986
}
50-
p.execute(new File(args[1]), true);
51-
} else if(args[0].equals("--gui") || args[0].equals("-g")) {
52-
new Window();
5387
}
5488
}
89+
90+
private static boolean isArgument(String arg) {
91+
return arg.equals("-f") || arg.equals("--file") || arg.equals("-e") || arg.equals("--execute") || arg.equals("--nogui");
92+
}
5593
}

com/devkev/devscript/raw/Process.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Process {
3333

3434
public long maxRuntime = 0; //Runtime in ms. If < 0, runtime is infinite
3535
private long start = 0;
36-
public final String version = "1.8.3";
36+
public final String version = "1.9.0";
3737

3838
/**The file, the script is executed from. May be null. Just useful for some Native commands*/
3939
public File file = null;
@@ -106,6 +106,7 @@ public Thread execute(String script, boolean newThread) {
106106

107107
script = script.replaceAll("\t", "");
108108
script = script.replaceAll("\r", "");
109+
script = script.replaceAll("\n", " ");
109110

110111
main = new Block(new StringBuilder(script), null);
111112
main.thread = null;

0 commit comments

Comments
 (0)