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,13 +1,12 @@
|
|||
package dev.zontreck.ariaslib.terminal;
|
||||
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.ariaslib.util.EnvironmentUtils;
|
||||
import dev.zontreck.ariaslib.util.Progress;
|
||||
|
||||
import java.io.Console;
|
||||
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;
|
||||
private TaskCompletionToken token = new TaskCompletionToken ( );
|
||||
|
||||
|
@ -16,18 +15,17 @@ public abstract class Task extends TimerTask implements Runnable
|
|||
// Else use the progress spinner from the Progress class
|
||||
private boolean isSilent = false;
|
||||
|
||||
public Task(String name)
|
||||
{
|
||||
public Task ( String 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)
|
||||
*
|
||||
* @param name Task name
|
||||
* @param silent Whether to print to the terminal
|
||||
*/
|
||||
public Task(String name, boolean silent)
|
||||
{
|
||||
public Task ( String name , boolean silent ) {
|
||||
this ( name );
|
||||
isSilent = silent;
|
||||
}
|
||||
|
@ -37,52 +35,46 @@ public abstract class Task extends TimerTask implements Runnable
|
|||
return token.get ( );
|
||||
}
|
||||
|
||||
public void startTask()
|
||||
{
|
||||
public void startTask ( ) {
|
||||
DelayedExecutorService.scheduleTask ( this , 1 );
|
||||
if(!isSilent)
|
||||
if ( ! isSilent && ! EnvironmentUtils.isRunningInsideDocker ( ) )
|
||||
DelayedExecutorService.instantExec ( new SpinnerTask ( token , this ) );
|
||||
}
|
||||
|
||||
public void stopTask()
|
||||
{
|
||||
if(token.get() && !isSilent)
|
||||
{
|
||||
public void stopTask ( ) {
|
||||
if ( token.get ( ) && ! isSilent ) {
|
||||
System.out.printf ( "\r" + TASK_NAME + "\t\t[" + token.status + "]\n" );
|
||||
}
|
||||
}
|
||||
public void setSuccess()
|
||||
{
|
||||
|
||||
public void setSuccess ( ) {
|
||||
token.completed ( CHECK );
|
||||
}
|
||||
public void setFail()
|
||||
{
|
||||
|
||||
public void setFail ( ) {
|
||||
token.completed ( FAIL );
|
||||
}
|
||||
public class SpinnerTask extends Task
|
||||
{
|
||||
|
||||
public class SpinnerTask extends Task {
|
||||
public final Task task;
|
||||
public final TaskCompletionToken token;
|
||||
private final Progress spinner = new Progress ( 100 );
|
||||
public SpinnerTask (TaskCompletionToken token, Task parent)
|
||||
{
|
||||
|
||||
public SpinnerTask ( TaskCompletionToken token , Task parent ) {
|
||||
super ( "spinner" , true );
|
||||
this.token = token;
|
||||
this.task = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while(!task.isComplete())
|
||||
{
|
||||
public void run ( ) {
|
||||
while ( ! task.isComplete ( ) ) {
|
||||
try {
|
||||
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" );
|
||||
}catch(Exception e)
|
||||
{
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace ( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
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.AtomicInteger;
|
||||
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
|
||||
public class Terminal {
|
||||
private static final AtomicInteger ID = new AtomicInteger ( 0 );
|
||||
private static final AtomicBoolean running = new AtomicBoolean ( true );
|
||||
public static String PREFIX = "";
|
||||
|
||||
/**
|
||||
* This starts a terminal instance
|
||||
*
|
||||
* @return The terminal ID
|
||||
*/
|
||||
public static int startTerminal()
|
||||
{
|
||||
public static int startTerminal ( ) {
|
||||
if ( EnvironmentUtils.isRunningInsideDocker ( ) )
|
||||
return 0;
|
||||
running.set ( true );
|
||||
DelayedExecutorService.getInstance ( ).schedule ( new ConsolePrompt ( ) , 1 );
|
||||
|
||||
|
@ -23,13 +26,11 @@ public class Terminal {
|
|||
return ID.getAndIncrement ( );
|
||||
}
|
||||
|
||||
public static boolean isRunning()
|
||||
{
|
||||
public static boolean isRunning ( ) {
|
||||
return running.get ( );
|
||||
}
|
||||
|
||||
public static void setRunning(boolean running)
|
||||
{
|
||||
public static void setRunning ( boolean running ) {
|
||||
Terminal.running.set ( running );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue