]> git.lyx.org Git - features.git/commitdiff
Fix output to terminal when LyX is launched from a GUI on *nix
authorEnrico Forestieri <forenr@lyx.org>
Fri, 16 Jul 2010 14:30:46 +0000 (14:30 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 16 Jul 2010 14:30:46 +0000 (14:30 +0000)
aka
Surrender to Windowsisms
aka
Resistance is futile, you will be assimilated

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34918 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/Systemcall.cpp
src/support/SystemcallPrivate.h
src/support/os.h
src/support/os_cygwin.cpp
src/support/os_unix.cpp
src/support/os_win32.cpp

index 5fec0b8f039fa630d7b6e50dd298fb64d67b81a1..dda23d66bce1d83369ca2d168a30bfbfda04fbf4 100644 (file)
@@ -246,24 +246,14 @@ SystemcallPrivate::SystemcallPrivate(const std::string& of) :
                                 out_index_(0),
                                 err_index_(0),
                                 out_file_(of), 
-                                use_stdout_(false),
-                                use_stderr_(false),
                                 process_events_(false)
 {
        if (!out_file_.empty()) {
-               // Don't output to terminal if stdout is redirected
-               use_stdout_ = false;
                // Check whether we have to simply throw away the output.
                if (out_file_ != os::nulldev())
                        process_->setStandardOutputFile(toqstr(out_file_));
-       } else {
-               // Output to terminal if stdout exists and is not redirected
-               use_stdout_ = os::is_terminal(os::STDOUT);
        }
 
-       // When there is a stderr use it
-       use_stderr_ = os::is_terminal(os::STDERR);
-
        connect(process_, SIGNAL(readyReadStandardOutput()), SLOT(stdOut()));
        connect(process_, SIGNAL(readyReadStandardError()), SLOT(stdErr()));
        connect(process_, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
@@ -335,20 +325,16 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
 
 SystemcallPrivate::~SystemcallPrivate()
 {
-       flush();
-
        if (out_index_) {
                out_data_[out_index_] = '\0';
                out_index_ = 0;
-               if (use_stdout_)
-                       cout << out_data_;
+               cout << out_data_;
        }
        cout.flush();
        if (err_index_) {
                err_data_[err_index_] = '\0';
                err_index_ = 0;
-               if (use_stderr_)
-                       cerr << err_data_;
+               cerr << err_data_;
        }
        cerr.flush();
 
@@ -356,26 +342,6 @@ SystemcallPrivate::~SystemcallPrivate()
 }
 
 
-void SystemcallPrivate::flush()
-{
-       if (process_) {
-               // If the output has been redirected, we write it all at once.
-               // Even if we are not running in a terminal, the output could go
-               // to some log file, for example ~/.xsession-errors on *nix.
-               
-               QString data = QString::fromLocal8Bit(process_->readAllStandardOutput().data());
-               ProgressInterface::instance()->appendMessage(data);
-               if (!use_stdout_ && out_file_.empty())
-                       cout << fromqstr(data);
-               
-               data = QString::fromLocal8Bit(process_->readAllStandardError().data());
-               ProgressInterface::instance()->appendError(data);
-               if (!use_stderr_)
-                       cerr << fromqstr(data);
-       }
-}
-
-
 void SystemcallPrivate::stdOut()
 {
        if (process_) {
@@ -383,12 +349,11 @@ void SystemcallPrivate::stdOut()
                process_->setReadChannel(QProcess::StandardOutput);
                while (process_->getChar(&c)) {
                        out_data_[out_index_++] = c;
-                       if (c == '\n' || out_index_ + 1 == max_buffer_size_) {
+                       if (c == '\n' || out_index_ + 1 == buffer_size_) {
                                out_data_[out_index_] = '\0';
                                out_index_ = 0;
                                ProgressInterface::instance()->appendMessage(QString::fromLocal8Bit(out_data_));
-                               if (use_stdout_)
-                                       cout << out_data_;
+                               cout << out_data_;
                        }
                }
        }
@@ -402,12 +367,11 @@ void SystemcallPrivate::stdErr()
                process_->setReadChannel(QProcess::StandardError);
                while (process_->getChar(&c)) {
                        err_data_[err_index_++] = c;
-                       if (c == '\n' || err_index_ + 1 == max_buffer_size_) {
+                       if (c == '\n' || err_index_ + 1 == buffer_size_) {
                                err_data_[err_index_] = '\0';
                                err_index_ = 0;
                                ProgressInterface::instance()->appendError(QString::fromLocal8Bit(err_data_));
-                               if (use_stderr_)
-                                       cerr << err_data_;
+                               cerr << err_data_;
                        }
                }
        }
index c446358647ea50a9f033d0562db6e32529fbc50c..c8e3aa734c500c97be01555e419305922caba6ec 100644 (file)
@@ -51,8 +51,6 @@ public:
        QString errorMessage() const;
        QString exitStatusMessage() const;
 
-       void flush();
-
        QProcess* releaseProcess();
        
        static void killProcess(QProcess * p);
@@ -78,14 +76,11 @@ private:
        std::string out_file_;
 
        /// Size of buffers.
-       static size_t const max_buffer_size_ = 200;
+       static size_t const buffer_size_ = 200;
        /// Standard output buffer.
-       char out_data_[max_buffer_size_];
+       char out_data_[buffer_size_];
        /// Standard error buffer.
-       char err_data_[max_buffer_size_];
-
-       bool use_stderr_;
-       bool use_stdout_;
+       char err_data_[buffer_size_];
 
        QString cmd_;
        bool process_events_;
index 36209a264710780d8973d7abab22399d378afce2..08ad8206c9a3d33df92d41fd48c0e686054209fb 100644 (file)
@@ -55,9 +55,6 @@ void remove_internal_args(int i, int num);
 /// Returns the name of the NULL device (/dev/null, null).
 std::string const & nulldev();
 
-/// Tells whether \p channel is connected to a terminal or not. 
-bool is_terminal(io_channel channel);
-
 /// Returns "/" on *nix, "C:/", etc on Windows.
 std::string current_root();
 
index 31416c0f711190a8cc18c50d91a2b478035aee95..ad97c38bc2a1fd38cb15c860c46b119b6be30111 100644 (file)
@@ -375,12 +375,6 @@ string const & nulldev()
 }
 
 
-bool is_terminal(io_channel channel)
-{
-       return isatty(channel);
-}
-
-
 shell_type shell()
 {
        return UNIX;
index 139743b43a542534035b3306eb887e832d4c3731..337f728d5c5b42ca871cf463c23a9bce95fa0dfa 100644 (file)
@@ -206,12 +206,6 @@ string const & nulldev()
 }
 
 
-bool is_terminal(io_channel channel)
-{
-       return isatty(channel);
-}
-
-
 shell_type shell()
 {
        return UNIX;
index d0bf73ffb33a5e9b530304be122bdf0d6111fe07..dd5f0e594d71cd9fa18fa1adc04dd0710c2d209e 100644 (file)
@@ -417,26 +417,6 @@ string const & nulldev()
 }
 
 
-bool is_terminal(io_channel channel)
-{
-       switch (channel) {
-       case STDIN:
-               if (GetStdHandle(STD_INPUT_HANDLE) == NULL)
-                       return false;
-               break;
-       case STDOUT:
-               if (GetStdHandle(STD_OUTPUT_HANDLE) == NULL)
-                       return false;
-               break;
-       case STDERR:
-               if (GetStdHandle(STD_ERROR_HANDLE) == NULL)
-                       return false;
-               break;
-       }
-       return true;
-}
-
-
 shell_type shell()
 {
        return CMD_EXE;