Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

GRAILS-10753 Console Colors in Windows - optional fix #433

Closed
wants to merge 1 commit into from

5 participants

@tombujok

Outputs the ANSI reset sequence and flushes the stream before the System.exit() invocations to make sure that the console has been reset to its default state.
The potential problem could occur when the out stream has not been fully flushed and the System.exit() invocation finished.
Last characters of the out stream contain the ANSI reset sequence - if they are not flushed the console keeps the formatting of the previous message.

@tombujok tombujok GRAILS-10753 Console Colors in Windows - optional fix
Outputs the ANSI reset sequence and flushes the stream before the System.exit() invocations to make sure that the console has been reset to its default state.
199b38f
@lhotari lhotari closed this
@lhotari lhotari reopened this
@lhotari
Collaborator

Thanks for the pull request. Could you rebase the commit on the current head of 2.3.x branch?

@ikakara

FYI - this also happens in grails 3.0.2 and 2.5.0 ... I would be nice to have this fix in both 2.5x and 3x branches.

Thanks!

@ikakara

@tombujok - do you have time to rebase this?

@lhotari - if the fix is based for 2.5.0, will you add it to the 3.x branch? if tombujok, doesn't have time I can take a crack at rebasing his fix.

@graemerocher graemerocher added this to the grails-3.0.3 milestone
@ikakara

@lhotari - I went ahead and took @tombujok changes and applied them into the 2.5.x branch: #9025 - I would love for these changes to go into the 2.5.1 release. Let me know if I should merge them into the 3.x branch as well.

Allen

@graemerocher

#9026 was Merged into 2.5.x branch

@tombujok

Sorry, I did not have time to look into it again - thanks for merging!

@ikakara

Sure! I didn't merge this into the 3.x branch - does the 2.5 branch automagically get merged into the 3.x branch?

@jeffbrown
Owner

@ikakara The commit at 944636f is on the 2.5.x, 3.0.x and master branch.

@ikakara

@jeffbrown - thanks for clarifying. I need to figure out how github merging/etc works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 7, 2013
  1. @tombujok

    GRAILS-10753 Console Colors in Windows - optional fix

    tombujok authored
    Outputs the ANSI reset sequence and flushes the stream before the System.exit() invocations to make sure that the console has been reset to its default state.
This page is out of date. Refresh to see the latest.
View
14 grails-bootstrap/src/main/groovy/grails/build/logging/GrailsConsole.java
@@ -337,7 +337,7 @@ public InputStream getInput() {
private void assertAllowInput() {
assertAllowInput(null);
}
-
+
private void assertAllowInput(String prompt) {
if (reader == null) {
String msg = "User input is not enabled, cannot obtain input stream";
@@ -867,7 +867,7 @@ public void error(String label, String message) {
cursorMove = 0;
try {
if (isAnsiEnabled()) {
- Ansi ansi = outputErrorLabel(userInputActive ? moveDownToSkipPrompt() : ansi(), label).a(message);
+ Ansi ansi = outputErrorLabel(userInputActive ? moveDownToSkipPrompt() : ansi(), label).a(message);
if (message.endsWith(LINE_SEPARATOR)) {
out.print(ansi);
@@ -896,6 +896,16 @@ private void verifySystemOut() {
}
}
+ /**
+ * Makes sure that the console has been reset to the default state and that the out stream has been flushed.
+ */
+ public void cleanup() {
+ if (isAnsiEnabled()) {
+ out.print(ansi().reset().toString());
+ }
+ flush();
+ }
+
public void flush() {
out.flush();
}
View
21 grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/GrailsScriptRunner.java
@@ -142,7 +142,7 @@ public static void main(String[] args) {
}
} catch (ParseException e) {
console.error("Error processing command line arguments: " + e.getMessage());
- System.exit(1);
+ exitWithStatus(1);
return;
}
@@ -176,7 +176,7 @@ public static void main(String[] args) {
if (commandLine.hasOption(CommandLine.VERSION_ARGUMENT)) {
console.log("Grails version: " + build.getGrailsVersion());
- System.exit(0);
+ exitWithStatus(0);
}
if (commandLine.hasOption(CommandLine.HELP_ARGUMENT)) {
@@ -185,7 +185,7 @@ public static void main(String[] args) {
} else {
console.log("The '-help' option is deprecated; use 'grails help'");
}
- System.exit(0);
+ exitWithStatus(0);
}
boolean resolveDeps = commandLine.hasOption(CommandLine.REFRESH_DEPENDENCIES_ARGUMENT);
@@ -225,8 +225,7 @@ public static void main(String[] args) {
try {
int exitCode = scriptRunner.executeCommand(commandLine, script.name, script.env);
- GrailsConsole.getInstance().flush();
- System.exit(exitCode);
+ exitWithStatus(exitCode);
}
catch (ScriptNotFoundException ex) {
console.error("Script not found: " + ex.getScriptName());
@@ -272,8 +271,12 @@ private static void exitWithError(String error, Throwable t) {
else {
grailsConsole.error(error, t);
}
- grailsConsole.flush();
- System.exit(1);
+ exitWithStatus(1);
+ }
+
+ private static void exitWithStatus(int status) {
+ GrailsConsole.getInstance().cleanup();
+ System.exit(status);
}
private static ScriptAndArgs processArgumentsAndReturnScriptName(CommandLine commandLine) {
@@ -364,7 +367,7 @@ private int executeCommand(CommandLine commandLine, String scriptName, String en
}
catch (Exception e) {
console.error("There was an error loading the BuildConfig: " + e.getMessage(), e);
- System.exit(1);
+ exitWithStatus(1);
}
finally {
System.setProperty("disable.grails.plugin.transform", "false");
@@ -744,7 +747,7 @@ private String askUserForBestMatch(String scriptName, List<String> topMatches) {
String selection = console.userInput("Please make a selection or enter Q to quit: ");
if ("Q".equalsIgnoreCase(selection)) {
- System.exit(0);
+ exitWithStatus(0);
}
try {
View
2  grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/api/BaseSettingsApi.java
@@ -381,7 +381,7 @@ public void exit(int code) {
if (System.getProperty("grails.cli.testing") != null || System.getProperty("grails.disable.exit") != null) {
throw new ScriptExitException(code);
}
- GrailsConsole.getInstance().flush();
+ GrailsConsole.getInstance().cleanup();
System.exit(code);
}
View
10 ...-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/fork/ForkedGrailsProcess.groovy
@@ -116,7 +116,7 @@ abstract class ForkedGrailsProcess {
final contextFile = readLine(sockIn)
if (contextFile) {
if ("exit" == contextFile) {
- System.exit(0)
+ exitWithStatus(0)
}
else {
def loadedContext = readExecutionContext(contextFile)
@@ -148,7 +148,11 @@ abstract class ForkedGrailsProcess {
// ignore
}
}
+ }
+ private static exitWithStatus(int status) {
+ GrailsConsole.instance.cleanup()
+ System.exit(status)
}
boolean isDaemonRunning() {
@@ -242,7 +246,7 @@ abstract class ForkedGrailsProcess {
def lockDir = new File(executionContext.projectWorkDir, "process-lock")
if (lockDir.mkdir()) {
- System.exit 0
+ exitWithStatus(0)
} else {
// someone is already connected; let the process finish
}
@@ -440,7 +444,7 @@ abstract class ForkedGrailsProcess {
GrailsConsole.instance.error("Forked Grails VM exited with error")
if(!InteractiveMode.active) {
- System.exit(1)
+ exitWithStatus(1)
}
}
}
View
3  ...p/src/main/groovy/org/codehaus/groovy/grails/cli/fork/compile/ForkedGrailsCompiler.groovy
@@ -48,7 +48,8 @@ class ForkedGrailsCompiler extends ForkedGrailsProjectClassExecutor {
new ForkedGrailsCompiler().run()
System.exit(0)
} catch (Throwable e) {
- GrailsConsole.getInstance().error("Error running forked compilation: " + e.getMessage(), e)
+ GrailsConsole.instance.error("Error running forked compilation: " + e.getMessage(), e)
+ GrailsConsole.instance.cleanup()
System.exit(1)
}
}
View
3  ...src/main/groovy/org/codehaus/groovy/grails/cli/fork/testing/ForkedGrailsTestRunner.groovy
@@ -75,7 +75,8 @@ class ForkedGrailsTestRunner extends ForkedGrailsProjectClassExecutor {
try {
System.exit( new ForkedGrailsTestRunner().run() )
} catch (Throwable e) {
- GrailsConsole.getInstance().error("Error running forked test-app: " + e.getMessage(), e)
+ GrailsConsole.instance.error("Error running forked test-app: " + e.getMessage(), e)
+ GrailsConsole.instance.cleanup()
System.exit(1)
}
}
View
1  ...otstrap/src/main/groovy/org/codehaus/groovy/grails/cli/interactive/InteractiveMode.groovy
@@ -230,6 +230,7 @@ class InteractiveMode {
protected void goodbye() {
updateStatus "Goodbye"
+ GrailsConsole.instance.cleanup()
System.exit(0)
}
View
3  ...bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/support/ClasspathConfigurer.java
@@ -108,7 +108,7 @@ public URLClassLoader configuredClassLoader() {
if (!dependenciesExternallyConfigured && buildDependencies.isEmpty()) {
GrailsConsole.getInstance().error("Required Grails build dependencies were not found. This is normally due to internet connectivity issues (such as a misconfigured proxy) or missing repositories in grails-app/conf/BuildConfig.groovy. Please verify your configuration to continue.");
cleanResolveCache(settings);
-
+ GrailsConsole.getInstance().cleanup();
System.exit(1);
}
addDependenciesToURLs(excludes, urls, buildDependencies);
@@ -160,6 +160,7 @@ private void handleResolveError(BuildSettings settings, DependencyReport buildRe
grailsConsole.error(buildResolveReport.getResolveError().getMessage());
grailsConsole.addStatus("Run 'grails dependency-report' for further information.");
if (exitOnResolveError) {
+ grailsConsole.cleanup();
System.exit(1);
}
}
Something went wrong with that request. Please try again.