From 1896deb10eda67d8e8cb5188fe0f747fa16fdfeb Mon Sep 17 00:00:00 2001 From: Eran Tiktin Date: Sat, 10 Oct 2015 06:39:02 +0300 Subject: [PATCH 1/2] Fix console.* calls on Windows - Calls for console.* on browser process are printed with no need for --enable-logging - The output is without the logging prefix - The cursor in the terminal is always after the last output - The first output starts on a new line and not at the prompt - console.* from renderer are not printed to cmd - Added a missing '\n' in the default_app help output --- atom/app/atom_main_delegate.cc | 4 ++++ atom/browser/default_app/main.js | 2 +- atom/browser/lib/init.coffee | 2 +- atom/common/api/atom_bindings.cc | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index fe3c0e09ae..6ba1b89837 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -5,6 +5,7 @@ #include "atom/app/atom_main_delegate.h" #include +#include #include "atom/app/atom_content_client.h" #include "atom/browser/atom_browser_client.h" @@ -29,6 +30,9 @@ AtomMainDelegate::~AtomMainDelegate() { bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { logging::LoggingSettings settings; #if defined(OS_WIN) + // On Windows the terminal returns immediately, so we add a new line to + // prevent output in the same line as the prompt. + std::wcout << std::endl; #if defined(DEBUG) // Print logging to debug.log on Windows settings.logging_dest = logging::LOG_TO_ALL; diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index e2c29f2d7e..9cb468182d 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -263,7 +263,7 @@ if (option.file && !option.webdriver) { helpMessage += "A path to an Electron application may be specified. The path must be to \n"; helpMessage += "an index.js file or to a folder containing a package.json or index.js file.\n\n"; helpMessage += "Options:\n"; - helpMessage += " -r, --require Module to preload (option can be repeated)"; + helpMessage += " -r, --require Module to preload (option can be repeated)\n"; helpMessage += " -h, --help Print this usage message.\n"; helpMessage += " -v, --version Print the version."; console.log(helpMessage); diff --git a/atom/browser/lib/init.coffee b/atom/browser/lib/init.coffee index b394c0fecc..2b6b1bb3c2 100644 --- a/atom/browser/lib/init.coffee +++ b/atom/browser/lib/init.coffee @@ -22,7 +22,7 @@ if process.platform is 'win32' # Redirect node's console to use our own implementations, since node can not # handle console output when running as GUI program. print = (args...) -> - process.log util.format(args...) + process.log util.format(args...) + "\n" console.log = console.error = console.warn = print process.stdout.write = process.stderr.write = print diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index d6fb355e09..1a44d1af0a 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -6,6 +6,7 @@ #include #include +#include #include "atom/common/atom_version.h" #include "atom/common/chrome_version.h" @@ -40,7 +41,7 @@ void FatalErrorCallback(const char* location, const char* message) { } void Log(const base::string16& message) { - logging::LogMessage("CONSOLE", 0, 0).stream() << message; + std::wcout << message; } } // namespace From c71efc8ca54b1f7f4de799eca8c0e49bb558c2e7 Mon Sep 17 00:00:00 2001 From: Eran Tiktin Date: Sat, 10 Oct 2015 08:13:27 +0300 Subject: [PATCH 2/2] Fix `process.std*.write` - Support printing Buffer - Don't add '\n' at the end the chunk --- atom/browser/lib/init.coffee | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/atom/browser/lib/init.coffee b/atom/browser/lib/init.coffee index 2b6b1bb3c2..9f92d700c7 100644 --- a/atom/browser/lib/init.coffee +++ b/atom/browser/lib/init.coffee @@ -21,10 +21,15 @@ globalPaths.push path.resolve(__dirname, '..', 'api', 'lib') if process.platform is 'win32' # Redirect node's console to use our own implementations, since node can not # handle console output when running as GUI program. - print = (args...) -> + consoleLog = (args...) -> process.log util.format(args...) + "\n" - console.log = console.error = console.warn = print - process.stdout.write = process.stderr.write = print + streamWrite = (chunk, encoding, callback) -> + chunk = chunk.toString(encoding) if Buffer.isBuffer chunk + process.log chunk + callback() if callback + true + console.log = console.error = console.warn = consoleLog + process.stdout.write = process.stderr.write = streamWrite # Always returns EOF for stdin stream. Readable = require('stream').Readable