Ejemplo n.º 1
0
	//read messages from buffer and write them to the screen
	void write(wxCommandEvent &)
	{
		if (messages.size() > 0)
		{
			messages.lockGet();
			size_t size = messages.size();
			std::vector<char> local_messages(size);
			messages.popN(&local_messages.front(), size);
			messages.unlockGet();
			newLog = false;

			u32 cursor = 0;
			u32 removed = 0;
			while (cursor < local_messages.size())
			{
				Log::LogMessage msg = Log::LogMessage::deserialize(local_messages.data() + cursor, &removed);
				cursor += removed;
				if (removed <= 0)
				{
					break;
				}
				wxTextCtrl *llogcon = (msg.mType == Log::TTY) ? m_tty : m_log;
				if (llogcon)
				{
					switch (msg.mServerity)
					{
					case Log::LogSeverityNotice:
						llogcon->SetDefaultStyle(m_color_white);
						break;
					case Log::LogSeverityWarning:
						llogcon->SetDefaultStyle(m_color_yellow);
						break;
					case Log::LogSeverityError:
						llogcon->SetDefaultStyle(m_color_red);
						break;
					case Log::LogSeveritySuccess:
						llogcon->SetDefaultStyle(m_color_green);
						break;
					default:
						break;
					}
					llogcon->AppendText(fmt::FromUTF8(msg.mText));
				}
			}
			if (m_log->GetLastPosition() > GUI_BUFFER_MAX_SIZE)
			{
				m_log->Remove(0, m_log->GetLastPosition() - (GUI_BUFFER_MAX_SIZE/2));
			}
		}
	}
Ejemplo n.º 2
0
  void DisplayProcess::Execute(const wxString& command)
  {
    if (!tctrl)
    {
      return;
    }

    wxProcess *process = new wxProcess(wxPROCESS_REDIRECT);
    //long pid =
      wxExecute(command, wxEXEC_ASYNC, process);
    process->Redirect();

    if (process)
    {
      wxString log;
      wxInputStream *msg = process->GetInputStream();

      wxTextInputStream tStream(*msg);
      while (!msg->Eof())
      {
        log = tStream.ReadLine();
        tctrl->AppendText(log + wxT("\n"));
        tctrl->ShowPosition(tctrl->GetLastPosition());
      }
      tctrl->AppendText(wxT("Finished!\n"));
    }
    else {
      tctrl->AppendText(wxT("FAIL: Command" + command + " could not be run!\n"));
    }
  }