Adds a check for docker environment.
This commit is contained in:
parent
8a4d4109fa
commit
fca7091590
2 changed files with 66 additions and 73 deletions
|
@ -1,89 +1,81 @@
|
||||||
package dev.zontreck.ariaslib.terminal;
|
package dev.zontreck.ariaslib.terminal;
|
||||||
|
|
||||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||||
|
import dev.zontreck.ariaslib.util.EnvironmentUtils;
|
||||||
import dev.zontreck.ariaslib.util.Progress;
|
import dev.zontreck.ariaslib.util.Progress;
|
||||||
|
|
||||||
import java.io.Console;
|
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public abstract class Task extends TimerTask implements Runnable
|
public abstract class Task extends TimerTask implements Runnable {
|
||||||
{
|
|
||||||
public final String TASK_NAME;
|
public final String TASK_NAME;
|
||||||
private TaskCompletionToken token = new TaskCompletionToken();
|
private TaskCompletionToken token = new TaskCompletionToken ( );
|
||||||
|
|
||||||
public static final String CHECK = "✓";
|
public static final String CHECK = "✓";
|
||||||
public static final String FAIL = "X";
|
public static final String FAIL = "X";
|
||||||
// Else use the progress spinner from the Progress class
|
// Else use the progress spinner from the Progress class
|
||||||
private boolean isSilent=false;
|
private boolean isSilent = false;
|
||||||
|
|
||||||
public Task(String name)
|
public Task ( String name ) {
|
||||||
{
|
TASK_NAME = name;
|
||||||
TASK_NAME=name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is meant to be used to create silent tasks that do not output to the console. (Example usage: DelayedExecutionService)
|
* This constructor is meant to be used to create silent tasks that do not output to the console. (Example usage: DelayedExecutionService)
|
||||||
* @param name Task name
|
*
|
||||||
|
* @param name Task name
|
||||||
* @param silent Whether to print to the terminal
|
* @param silent Whether to print to the terminal
|
||||||
*/
|
*/
|
||||||
public Task(String name, boolean silent)
|
public Task ( String name , boolean silent ) {
|
||||||
{
|
this ( name );
|
||||||
this(name);
|
isSilent = silent;
|
||||||
isSilent=silent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isComplete(){
|
public boolean isComplete ( ) {
|
||||||
return token.get();
|
return token.get ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTask()
|
public void startTask ( ) {
|
||||||
{
|
DelayedExecutorService.scheduleTask ( this , 1 );
|
||||||
DelayedExecutorService.scheduleTask(this, 1);
|
if ( ! isSilent && ! EnvironmentUtils.isRunningInsideDocker ( ) )
|
||||||
if(!isSilent)
|
DelayedExecutorService.instantExec ( new SpinnerTask ( token , this ) );
|
||||||
DelayedExecutorService.instantExec(new SpinnerTask(token,this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTask()
|
public void stopTask ( ) {
|
||||||
{
|
if ( token.get ( ) && ! isSilent ) {
|
||||||
if(token.get() && !isSilent)
|
System.out.printf ( "\r" + TASK_NAME + "\t\t[" + token.status + "]\n" );
|
||||||
{
|
|
||||||
System.out.printf("\r"+TASK_NAME+"\t\t["+token.status+"]\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setSuccess()
|
|
||||||
{
|
public void setSuccess ( ) {
|
||||||
token.completed(CHECK);
|
token.completed ( CHECK );
|
||||||
}
|
}
|
||||||
public void setFail()
|
|
||||||
{
|
public void setFail ( ) {
|
||||||
token.completed(FAIL);
|
token.completed ( FAIL );
|
||||||
}
|
}
|
||||||
public class SpinnerTask extends Task
|
|
||||||
{
|
public class SpinnerTask extends Task {
|
||||||
public final Task task;
|
public final Task task;
|
||||||
public final TaskCompletionToken token;
|
public final TaskCompletionToken token;
|
||||||
private final Progress spinner = new Progress(100);
|
private final Progress spinner = new Progress ( 100 );
|
||||||
public SpinnerTask (TaskCompletionToken token, Task parent)
|
|
||||||
{
|
public SpinnerTask ( TaskCompletionToken token , Task parent ) {
|
||||||
super("spinner",true);
|
super ( "spinner" , true );
|
||||||
this.token=token;
|
this.token = token;
|
||||||
this.task=parent;
|
this.task = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run ( ) {
|
||||||
{
|
while ( ! task.isComplete ( ) ) {
|
||||||
while(!task.isComplete())
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(50L);
|
Thread.sleep ( 50L );
|
||||||
|
|
||||||
if(!task.isSilent && !task.isComplete())
|
if ( ! task.isSilent && ! task.isComplete ( ) && ! EnvironmentUtils.isRunningInsideDocker ( ) )
|
||||||
System.out.printf("\r"+task.TASK_NAME+"\t\t"+spinner.getSpinnerTick()+"\r");
|
System.out.printf ( "\r" + task.TASK_NAME + "\t\t" + spinner.getSpinnerTick ( ) + "\r" );
|
||||||
}catch(Exception e)
|
} catch ( Exception e ) {
|
||||||
{
|
e.printStackTrace ( );
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
package dev.zontreck.ariaslib.terminal;
|
package dev.zontreck.ariaslib.terminal;
|
||||||
|
|
||||||
import java.io.Console;
|
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||||
|
import dev.zontreck.ariaslib.util.EnvironmentUtils;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
|
||||||
|
|
||||||
public class Terminal {
|
public class Terminal {
|
||||||
private static final AtomicInteger ID = new AtomicInteger(0);
|
private static final AtomicInteger ID = new AtomicInteger ( 0 );
|
||||||
private static final AtomicBoolean running= new AtomicBoolean(true);
|
private static final AtomicBoolean running = new AtomicBoolean ( true );
|
||||||
public static String PREFIX = "";
|
public static String PREFIX = "";
|
||||||
/**
|
|
||||||
* This starts a terminal instance
|
/**
|
||||||
* @return The terminal ID
|
* This starts a terminal instance
|
||||||
*/
|
*
|
||||||
public static int startTerminal()
|
* @return The terminal ID
|
||||||
{
|
*/
|
||||||
running.set(true);
|
public static int startTerminal ( ) {
|
||||||
DelayedExecutorService.getInstance().schedule(new ConsolePrompt(), 1);
|
if ( EnvironmentUtils.isRunningInsideDocker ( ) )
|
||||||
|
return 0;
|
||||||
|
running.set ( true );
|
||||||
|
DelayedExecutorService.getInstance ( ).schedule ( new ConsolePrompt ( ) , 1 );
|
||||||
|
|
||||||
|
|
||||||
return ID.getAndIncrement();
|
return ID.getAndIncrement ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRunning()
|
public static boolean isRunning ( ) {
|
||||||
{
|
return running.get ( );
|
||||||
return running.get();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRunning(boolean running)
|
public static void setRunning ( boolean running ) {
|
||||||
{
|
Terminal.running.set ( running );
|
||||||
Terminal.running.set(running);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue