Ajout progress bar
This commit is contained in:
parent
27267f0422
commit
edff961ad3
1
NGCC/.gitignore
vendored
Normal file
1
NGCC/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/bin/
|
@ -1,52 +1,42 @@
|
||||
|
||||
import commands.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import commands.Read;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
public class Exec {
|
||||
@Command(
|
||||
name = "Exec",
|
||||
version = "Version 1.0",
|
||||
sortOptions = false,
|
||||
usageHelpWidth = 60,
|
||||
header = "\n ---- Nicely Generated and Corrected Copies ---- \n\n" +
|
||||
" _______ _________________ ________ \n" +
|
||||
" \\ \\ / _____/\\_ ___ \\\\_ ___ \\ \n" +
|
||||
" / | \\/ \\ ___/ \\ \\// \\ \\/ \n" +
|
||||
" / | \\ \\_ \\ \\ \\___\\ \\___ \n" +
|
||||
" \\____|__ /\\______ /\\______ /\\______ / \n" +
|
||||
" \\/ \\/ \\/ \\/ \n" +
|
||||
" \n" ,
|
||||
footer = "\n\n ---- Provided by IUT Info Nice S3T-G4 ---- \n",
|
||||
description = "description"
|
||||
)
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
public class Exec implements Callable <Void> {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
CommandLine cmd = new CommandLine (new Exec())
|
||||
.addSubcommand("-r", new Read(System.out))
|
||||
.addSubcommand("help", new HelpCommand());
|
||||
|
||||
if (args[0].contentEquals("-b") || args[0].contentEquals("--build")) {
|
||||
CommandLine cmd = new CommandLine(new Build());
|
||||
cmd.execute(args);
|
||||
|
||||
} else if (args[0].contentEquals("-r") || args[0].contentEquals("--read")) {
|
||||
CommandLine cmd = new CommandLine(new Read());
|
||||
cmd.execute(args);
|
||||
|
||||
} else if (args[0].contentEquals("-g") || args[0].contentEquals("--generate")) {
|
||||
CommandLine cmd = new CommandLine(new Generate());
|
||||
cmd.execute(args);
|
||||
|
||||
} else if (args[0].contentEquals("-p") || args[0].contentEquals("--produce")) {
|
||||
CommandLine cmd = new CommandLine(new Produce());
|
||||
cmd.execute(args);
|
||||
|
||||
} else if (args[0].contentEquals("-a") || args[0].contentEquals("--analyse")) {
|
||||
CommandLine cmd = new CommandLine(new Analyse());
|
||||
cmd.execute(args);
|
||||
|
||||
} else if (args[0].contentEquals("-e") || args[0].contentEquals("--evaluate")) {
|
||||
CommandLine cmd = new CommandLine(new Evaluate());
|
||||
cmd.execute(args);
|
||||
|
||||
} else if (args[0].contentEquals("help") || args[0].contentEquals("--help")) {
|
||||
CommandLine cmd = new CommandLine(new Help());
|
||||
cmd.execute(args);
|
||||
|
||||
} else {
|
||||
System.err.println("NGCC: "+args[0] + " : command not found");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
CommandLine cmd = new CommandLine(new Help());
|
||||
System.out.println(cmd.execute(args));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import picocli.CommandLine.*;
|
||||
|
||||
|
||||
@Command(
|
||||
name = "help",
|
||||
name = "Help command",
|
||||
version = "Version 1.0",
|
||||
sortOptions = false,
|
||||
usageHelpWidth = 60,
|
||||
|
@ -1,16 +1,22 @@
|
||||
package commands;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.*;
|
||||
import progressbar.ProgressBar;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
//import picocli.CommandLine;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@Command(
|
||||
name = "read",
|
||||
name = "-r",
|
||||
version = "Version 1.0",
|
||||
sortOptions = false,
|
||||
usageHelpWidth = 60,
|
||||
header = " -- Nicely Generated and Corrected Copies -- \n",
|
||||
header = "Read command",
|
||||
footer = "\n Provided by IUT Info Nice S3T-G4",
|
||||
description = "description"
|
||||
)
|
||||
@ -18,9 +24,6 @@ import picocli.CommandLine.*;
|
||||
|
||||
public class Read implements Callable <Void> {
|
||||
|
||||
@Option(names= {"-r","--read"}, arity = "0", order = 1, description = "read mode")
|
||||
boolean read;
|
||||
|
||||
@Option(names= {"-u"}, arity = "1", order = 2, description = "update mode")
|
||||
int step;
|
||||
|
||||
@ -37,6 +40,11 @@ public class Read implements Callable <Void> {
|
||||
String source_path;
|
||||
|
||||
|
||||
public Read(PrintStream out) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isCsv(String file) {
|
||||
return file.endsWith(".csv");
|
||||
|
||||
@ -44,23 +52,30 @@ public class Read implements Callable <Void> {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
if(read) {
|
||||
System.out.println("Read mode activated ...");
|
||||
System.out.println("Update : "+step);
|
||||
System.out.println("Verbose : "+vb_level);
|
||||
System.out.println("Directory : "+directory_name);
|
||||
|
||||
if (isCsv(result_name)) {
|
||||
System.out.println("Result : "+result_name);
|
||||
}
|
||||
else {
|
||||
System.out.println("The specified for the result file is invalid");
|
||||
|
||||
ProgressBar bar = new ProgressBar();
|
||||
|
||||
System.out.println("\nReading pdf ...\n");
|
||||
|
||||
bar.update(0, 1000);
|
||||
for(int i=0;i<1000;i++) {
|
||||
// do something!
|
||||
for(int j=0;j<10000000;j++)
|
||||
for(int p=0;p<10000000;p++);
|
||||
// update the progress bar
|
||||
bar.update(i, 1000);
|
||||
}
|
||||
|
||||
System.out.println("Source : "+source_path);
|
||||
}
|
||||
System.out.println("\nCopies correction succeed !\n");
|
||||
|
||||
|
||||
System.out.println("\nUpdate : "+step +"\n"+
|
||||
"Verbose : "+vb_level +"\n"+
|
||||
"Directory : "+directory_name +"\n"+
|
||||
"Result : "+result_name +"\n"+
|
||||
"Source : "+source_path +"\n");
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
44
NGCC/src/progressbar/ProgressBar.java
Normal file
44
NGCC/src/progressbar/ProgressBar.java
Normal file
@ -0,0 +1,44 @@
|
||||
package progressbar;
|
||||
|
||||
public class ProgressBar {
|
||||
private StringBuilder progress;
|
||||
|
||||
/**
|
||||
* initialize progress bar properties.
|
||||
*/
|
||||
public ProgressBar() {
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* called whenever the progress bar needs to be updated.
|
||||
* that is whenever progress was made.
|
||||
*
|
||||
* @param done an int representing the work done so far
|
||||
* @param total an int representing the total work
|
||||
*/
|
||||
public void update(int done, int total) {
|
||||
char[] workchars = {'|', '/', '-', '\\'};
|
||||
String format = "\r%3d%% %s %c";
|
||||
|
||||
int percent = (++done * 100) / total;
|
||||
int extrachars = (percent / 2) - this.progress.length();
|
||||
|
||||
while (extrachars-- > 0) {
|
||||
progress.append('=');
|
||||
}
|
||||
|
||||
System.out.printf(format, percent, progress,
|
||||
workchars[done % workchars.length]);
|
||||
|
||||
if (done == total) {
|
||||
System.out.flush();
|
||||
System.out.println();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.progress = new StringBuilder(60);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user