2
* This file if part of nzbget
4
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5
* Copyright (C) 2007-2010 Andrey Prygunkov <hugbug@users.sourceforge.net>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
* $Date: 2013-01-18 22:36:17 +0100 (Fri, 18 Jan 2013) $
43
#include "ColoredFrontend.h"
46
ColoredFrontend::ColoredFrontend()
49
m_bNeedGoBack = false;
51
m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
55
void ColoredFrontend::BeforePrint()
61
CONSOLE_SCREEN_BUFFER_INFO BufInfo;
62
GetConsoleScreenBufferInfo(m_hConsole, &BufInfo);
63
BufInfo.dwCursorPosition.Y--;
64
SetConsoleCursorPosition(m_hConsole, BufInfo.dwCursorPosition);
68
m_bNeedGoBack = false;
72
void ColoredFrontend::PrintStatus()
77
int iCurrentDownloadSpeed = m_bStandBy ? 0 : m_iCurrentDownloadSpeed;
79
if (iCurrentDownloadSpeed > 0 && !(m_bPauseDownload || m_bPauseDownload2))
81
long long remain_sec = (long long)(m_lRemainingSize / iCurrentDownloadSpeed);
82
int h = (int)(remain_sec / 3600);
83
int m = (int)((remain_sec % 3600) / 60);
84
int s = (int)(remain_sec % 60);
85
sprintf(timeString, " (~ %.2d:%.2d:%.2d)", h, m, s);
88
char szDownloadLimit[128];
89
if (m_iDownloadLimit > 0)
91
sprintf(szDownloadLimit, ", Limit %.0f KB/s", (float)m_iDownloadLimit / 1024.0);
95
szDownloadLimit[0] = 0;
98
char szPostStatus[128];
99
if (m_iPostJobCount > 0)
101
sprintf(szPostStatus, ", %i post-job%s", m_iPostJobCount, m_iPostJobCount > 1 ? "s" : "");
109
char* szControlSeq = "";
112
const char* szControlSeq = "\033[K";
115
snprintf(tmp, 1024, " %d threads, %.*f KB/s, %.2f MB remaining%s%s%s%s%s\n",
116
m_iThreadCount, (iCurrentDownloadSpeed >= 10*1024 ? 0 : 1), (float)iCurrentDownloadSpeed / 1024.0,
117
(float)(Util::Int64ToFloat(m_lRemainingSize) / 1024.0 / 1024.0), timeString, szPostStatus,
118
m_bPauseDownload || m_bPauseDownload2 ? (m_bStandBy ? ", Paused" : ", Pausing") : "",
119
szDownloadLimit, szControlSeq);
122
m_bNeedGoBack = true;
125
void ColoredFrontend::PrintMessage(Message * pMessage)
128
switch (pMessage->GetKind())
130
case Message::mkDebug:
131
SetConsoleTextAttribute(m_hConsole, 8);
134
case Message::mkError:
135
SetConsoleTextAttribute(m_hConsole, 4);
138
case Message::mkWarning:
139
SetConsoleTextAttribute(m_hConsole, 5);
142
case Message::mkInfo:
143
SetConsoleTextAttribute(m_hConsole, 2);
146
case Message::mkDetail:
147
SetConsoleTextAttribute(m_hConsole, 2);
151
SetConsoleTextAttribute(m_hConsole, 7);
152
char* msg = strdup(pMessage->GetText());
154
printf(" %s\n", msg);
157
const char* msg = pMessage->GetText();
158
switch (pMessage->GetKind())
160
case Message::mkDebug:
161
printf("[DEBUG] %s\033[K\n", msg);
163
case Message::mkError:
164
printf("\033[31m[ERROR]\033[39m %s\033[K\n", msg);
166
case Message::mkWarning:
167
printf("\033[35m[WARNING]\033[39m %s\033[K\n", msg);
169
case Message::mkInfo:
170
printf("\033[32m[INFO]\033[39m %s\033[K\n", msg);
172
case Message::mkDetail:
173
printf("\033[32m[DETAIL]\033[39m %s\033[K\n", msg);
179
void ColoredFrontend::PrintSkip()
184
printf(".....\033[K\n");
188
void ColoredFrontend::BeforeExit()