本文整理汇总了Java中com.github.tomaslanger.chalk.Chalk类的典型用法代码示例。如果您正苦于以下问题:Java Chalk类的具体用法?Java Chalk怎么用?Java Chalk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Chalk类属于com.github.tomaslanger.chalk包,在下文中一共展示了Chalk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertCommandLine
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
protected void assertCommandLine(int exitCode, Assertion assertion, boolean includeConf,
String... tokens) throws Exception {
String[] commandLine = commandLine(includeConf, tokens);
printCWD();
System.out.println(">>> " + Constants.command()
+ StringUtils.arrayToDelimitedString(commandLine, " "));
System.out.println("");
systemOutRule.clearLog();
exit.expectSystemExitWithStatus(exitCode);
exit.checkAssertionAfterwards(assertion);
try {
Main.main(commandLine);
}
catch (Throwable t) {
Chalk.setColorEnabled(true);
throw t;
}
}
示例2: checkAssertion
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
@Override
public void checkAssertion() throws Exception {
String sysout = systemOutRule.getLogWithNormalizedLineSeparator();
String stderr = systemErrRule.getLogWithNormalizedLineSeparator();
if (!sysout.contains(requiredContent) && !stderr.contains(requiredContent)) {
// re-enable color to see an error message flying by
System.setProperty("jansi.strip", "false");
Chalk.setColorEnabled(true);
System.out.println(Style
.red("Received on sysout: <\n" + sysout + "\n> and on stderr: <\n" + stderr
+ "\n> neither of which contain: <\n" + requiredContent + "\n>"));
System.setProperty("jansi.strip", "true");
Chalk.setColorEnabled(false);
}
assertTrue(sysout.contains(requiredContent) || stderr.contains(requiredContent));
}
示例3: statusChalked
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
private Chalk statusChalked(final Chalk toChalk) {
if (null != statusColor) {
toChalk.apply(statusColor);
}
if (null != statusBgColor) {
toChalk.apply(statusBgColor);
}
if (!statusModifiers.isEmpty()) {
for (final Ansi.Modifier modifier : statusModifiers) {
toChalk.apply(modifier);
}
}
return toChalk;
}
示例4: chalked
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
private Chalk chalked(final Chalk toChalk) {
if (null != color) {
toChalk.apply(color);
}
if (null != bgColor) {
toChalk.apply(bgColor);
}
if (!modifiers.isEmpty()) {
for (final Ansi.Modifier modifier : modifiers) {
toChalk.apply(modifier);
}
}
return toChalk;
}
示例5: gray
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
/**
* Careful: gray doesn't work on Windows!
*/
public static String gray(String msg, Object... tokens) {
if (Chalk.isColorEnabled() && !SystemUtils.IS_OS_WINDOWS) {
return Chalk.on(format(msg, tokens)).gray().toString();
}
return format(msg, tokens);
}
示例6: setupRules
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
@Before
public void setupRules() {
Chalk.setColorEnabled(false);
systemOutRule.clearLog();
System.out.println("");
System.out.println(">>> " + getClass().getSimpleName() + "." + name.getMethodName());
CommandContext.delete(ArtifactSource.class);
CommandContext.delete(Rugs.class);
CommandContext.delete(TypeScriptCompiler.class);
setRelativeCWD("src/test/resources/common-editors");
}
示例7: run
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
@Override
public void run(final RollingRebootWithHealthCheckCommand command) {
logger.warn(Chalk.on(
"If this command fails: the minimum instance size may need to be increased and an EC2 instance" +
" may need to be set to 'in-service' state on the auto scaling group").yellow().toString());
final StackName stackName = command.getStackName();
final String stackId = configStore.getStackId(stackName);
final Map<String, String> stackOutputs = cloudFormationService.getStackOutputs(stackId);
final Map<String, String> stackParameters = cloudFormationService.getStackParameters(stackId);
final int minInstances = Integer.parseInt(stackParameters.get(MIN_INSTANCES_STACK_PARAMETER_KEY));
final String autoScalingGroupId = stackOutputs.get(CloudFormationService.AUTO_SCALING_GROUP_LOGICAL_ID_OUTPUT_KEY);
logger.debug("Found auto scaling group id for stack: {}", stackId);
final Filter isRunningFilter = new Filter(INSTANCE_STATE_FILTER_NAME).withValues(INSTANCE_STATE_RUNNING_FILTER_VALUE);
final List<Instance> instances = ec2Service.getInstancesByTag(EC2_ASG_GROUP_NAME_TAG_KEY, autoScalingGroupId, isRunningFilter);
logger.debug("Found {} instances by tag: '{}:{}'", instances.size(), EC2_ASG_GROUP_NAME_TAG_KEY, autoScalingGroupId);
logger.info("Temporarily decreasing min instances for ASG: {}", autoScalingGroupId);
autoScalingService.updateMinInstancesForAutoScalingGroup(autoScalingGroupId, minInstances - 1);
instances.forEach(instance -> {
rebootInstance(stackName, autoScalingGroupId, instance);
});
logger.info("Increasing min instances for ASG: {}", autoScalingGroupId);
autoScalingService.updateMinInstancesForAutoScalingGroup(autoScalingGroupId, minInstances);
}
示例8: rebootInstance
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
/**
* Reboot an instance and make sure it comes back healthy
*/
private void rebootInstance(StackName stackName, String autoScalingGroupId, Instance instance) {
final String healthCheckUrlTmpl = HEALTH_CHECK_MAP.get(stackName.getName());
final String healthCheckUrl = String.format(healthCheckUrlTmpl, instance.getPublicDnsName());
logger.info("Checking that instance health check is reachable...");
waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_BEFORE_REBOOT);
final String instanceId = instance.getInstanceId();
logger.info("Setting instance state to standby: {}", instanceId);
autoScalingService.setInstanceStateToStandby(autoScalingGroupId, instanceId);
logger.info("Rebooting instance: {}", instanceId);
ec2Service.rebootEc2Instance(instanceId);
// wait for health check fail to confirm box reboot
logger.info("Waiting for health check failure to confirm reboot...");
waitForHealthCheckStatusCode(healthCheckUrl, HEALTH_CHECK_FAILED_CODE, EXPECTED_NUM_FAILURES_AFTER_REBOOT);
// wait for health check pass to confirm instance is healthy after reboot
logger.warn(Chalk.on(
"If a proxy is required to talk to the EC2 instance, then make sure it is set up." +
" Otherwise this command will never succeed.").yellow().toString());
logger.info("Waiting for health check to pass again to confirm instance is healthy...");
waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_AFTER_REBOOT);
logger.info("Setting instance state to in-service: {}", instanceId);
autoScalingService.setInstanceStateToInService(autoScalingGroupId, instanceId);
}
示例9: waitForHealthCheckStatusCode
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
/**
* Poll the health check 'n' times, looking for the given response
* @param healthCheckUrl - The health check URL
* @param numConsecutiveResponsesExpected - The number of times to poll health check
*/
private void waitForHealthCheckStatusCode(final String healthCheckUrl,
final long expectedStatusCode,
final int numConsecutiveResponsesExpected) {
int responseCode;
int consecutiveResponses = 0;
while (consecutiveResponses < numConsecutiveResponsesExpected) {
responseCode = executeHealthCheck(healthCheckUrl);
if (responseCode == expectedStatusCode) {
consecutiveResponses++;
} else if (consecutiveResponses > 0) {
final String message = Chalk.on("Instance health check did not repeat response code ({}), {} times").red().bold().toString();
logger.debug(message, expectedStatusCode, numConsecutiveResponsesExpected);
consecutiveResponses = 0;
}
try {
TimeUnit.SECONDS.sleep(NUM_SECS_BETWEEN_HEALTH_CHECKS);
} catch (InterruptedException ie) {
logger.error(Chalk.on("Timeout between health checks has been interrupted").red().bold().toString());
return;
}
}
}
示例10: executeHealthCheck
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
/**
* Execute the given health check
* @param healthCheckUrl - Name of that EC2 instance belongs to
* @return - Response code of the health check
*/
private int executeHealthCheck(final String healthCheckUrl) {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.hostnameVerifier(new NoopHostnameVerifier())
.proxy(proxy)
.connectTimeout(DEFAULT_HTTP_TIMEOUT, DEFAULT_HTTP_TIMEOUT_UNIT)
.writeTimeout(DEFAULT_HTTP_TIMEOUT, DEFAULT_HTTP_TIMEOUT_UNIT)
.readTimeout(DEFAULT_HTTP_TIMEOUT, DEFAULT_HTTP_TIMEOUT_UNIT)
.build();
final Request requestBuilder = new Request.Builder()
.url(healthCheckUrl)
.get()
.build();
final Call healthCheckCall = okHttpClient.newCall(requestBuilder);
try(final Response response = healthCheckCall.execute()) {
logger.debug("Health check returned status: {}, URL: {}", response.code(), healthCheckUrl);
return response.code();
} catch (IOException ioe) {
final String message = Chalk.on("Health check failed, Cause: \"{}\", URL: {}").red().toString();
logger.debug(message, ioe.getMessage(), healthCheckUrl);
}
return HEALTH_CHECK_FAILED_CODE;
}
示例11: getStatusColor
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
private String getStatusColor(String status) {
if (status.endsWith("PROGRESS")) {
return Chalk.on(status).yellow().toString();
} else if (status.endsWith("COMPLETE")) {
return Chalk.on(status).green().bold().toString();
} else if (status.endsWith("FAILED")) {
return Chalk.on(status).red().bold().toString();
}
return status;
}
示例12: printCommands
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
private void printCommands() {
System.out.println("Commands, use cerberus [-h, --help] [command name] for more info:");
commander.getCommands().keySet().stream().sorted().forEach(command -> {
String msg = String.format(" %s, %s",
Chalk.on(command).green().bold().toString(),
commander.getCommandDescription(command));
System.out.println(msg);
});
}
示例13: ProgressBarMasterDetail
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
protected ProgressBarMasterDetail(final Builder builder) {
super(builder);
this.isBatch = builder.isBatch() || !Chalk.isCommandEnabled();
ProgressBar.Builder masterBuilder = builder.getMasterPbBuilder();
if (isBatch) {
masterBuilder.setBatch();
}
this.master = masterBuilder.build();
this.childBulder = builder.getChildPbBuilder();
}
示例14: replicateBowerSummary
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
private void replicateBowerSummary() {
System.out.println();
System.out.println("***************************************************");
System.out.println("** Example for java script lovers - Grunt **");
System.out.println("***************************************************");
System.out.println();
System.out.println("[[email protected]]$ grunt build");
System.out.println("Running \"clean:dist\" (clean) task");
System.out.println(Chalk.on("Warning: Cannot delete files outside the current working directory. Use --force to continue.").yellow());
System.out.println();
System.out.println(Chalk.on("Aborted due to warnings.").red());
System.out.println();
System.out.println();
System.out.println(Chalk.on("Execution Time (2015-12-21 09:08:31 UTC)").white());
String begin1 = "loading tasks " + Chalk.on("20ms ").blue();
ProgressBar pb = new ProgressBar.Builder().setCharCount(20).setBeginString(begin1).setStatusColor(Ansi.Color.BLUE).setBgColor(Ansi.BgColor.BLUE).disablePercents().setStatusLocation(StatusLoc.SAME_LINE).build();
pb.begin();
pb.setProgress(100, "20%");
pb.end();
String begin2 = "clean:dist " + Chalk.on("70ms ").blue();
pb = new ProgressBar.Builder().setCharCount(77).setBeginString(begin2).setStatusColor(Ansi.Color.BLUE).setBgColor(Ansi.BgColor.BLUE).disablePercents().setStatusLocation(StatusLoc.SAME_LINE).build();
pb.begin();
pb.setProgress(100, "77%");
pb.end();
System.out.println(Chalk.on("Total 101ms").magenta());
}
示例15: executeDifferentMax
import com.github.tomaslanger.chalk.Chalk; //导入依赖的package包/类
private static void executeDifferentMax(final ProgressBar pb) {
pb.begin();
try {
for (int progress = 0; progress < pb.getMax(); progress += 1) {
pb.setProgress(progress, "Progress " + Chalk.on("at").yellow() + " " + progress);
Thread.sleep(20);
}
pb.setProgress(pb.getMax(), "Progress " + Chalk.on("at").yellow() + " " + pb.getMax());
} catch (InterruptedException e) {
System.err.println("Interrupted");
} finally {
pb.end();
}
}