Skip to content

Commit 23ca6fd

Browse files
authored
Added NO_COLOR=1 support to disable colored terminal output (#237)
1 parent 73cf3cb commit 23ca6fd

38 files changed

Lines changed: 1304 additions & 1054 deletions

docs/CLIHELP.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ On _non_ RaspiOS-based RetroPie-Installments put the file from
2323

2424
In either case: Open a new bash and press ++tab++ key twice to see it in action.
2525

26+
### Disable Terminal Colors
27+
28+
By default Skyscraper will use ANSI terminal colors. However, colors will be not
29+
be used in the output when you run Skyscraper via a serial console or you apply
30+
file redirection e.g., `Skyscraper ... > out.log`. In any case you can manually
31+
enforce no color output by setting the environment variable `NO_COLOR` to a
32+
non-zero value (a value of zero will show colors). For example:
33+
34+
```bash
35+
NO_COLOR=1 Skyscraper ...
36+
```
37+
38+
The [no-color.org](https://no-color.org) website has additional information.
39+
2640
## Short Options
2741

2842
The most prevalent short options you will use are most likely [`-s`](#-s-module)

skyscraper.pro

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -85,114 +85,117 @@ CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
8585

8686
include(win32/skyscraper.pro)
8787

88-
HEADERS += src/skyscraper.h \
89-
src/netmanager.h \
90-
src/netcomm.h \
91-
src/xmlreader.h \
92-
src/settings.h \
88+
HEADERS += \
89+
src/abstractfrontend.h \
90+
src/abstractscraper.h \
91+
src/arcadedb.h \
92+
src/attractmode.h \
93+
src/batocera.h \
94+
src/cache.h \
9395
src/cli.h \
9496
src/compositor.h \
9597
src/config.h \
96-
src/strtools.h \
97-
src/imgtools.h \
98-
src/esgamelist.h \
99-
src/scraperworker.h \
100-
src/cache.h \
101-
src/localscraper.h \
102-
src/importscraper.h \
103-
src/gameentry.h \
104-
src/abstractscraper.h \
105-
src/abstractfrontend.h \
98+
src/crc32.h \
10699
src/emulationstation.h \
107100
src/esde.h \
108-
src/batocera.h \
109-
src/attractmode.h \
110-
src/pegasus.h \
111-
src/openretro.h \
112-
src/thegamesdb.h \
113-
src/zxinfodk.h \
114-
src/screenscraper.h \
115-
src/crc32.h \
116-
src/mobygames.h \
117-
src/gamebase.h \
118-
src/igdb.h \
119-
src/arcadedb.h \
120-
src/platform.h \
121-
src/layer.h \
122-
src/fxshadow.h \
101+
src/esgamelist.h \
102+
src/fxbalance.h \
123103
src/fxblur.h \
124-
src/fxmask.h \
125-
src/fxframe.h \
126-
src/fxrounded.h \
127-
src/fxstroke.h \
128104
src/fxbrightness.h \
105+
src/fxcolorize.h \
129106
src/fxcontrast.h \
130-
src/fxbalance.h \
131-
src/fxopacity.h \
107+
src/fxframe.h \
132108
src/fxgamebox.h \
133109
src/fxhue.h \
134-
src/fxsaturation.h \
135-
src/fxcolorize.h \
110+
src/fxmask.h \
111+
src/fxopacity.h \
136112
src/fxrotate.h \
113+
src/fxrounded.h \
114+
src/fxsaturation.h \
137115
src/fxscanlines.h \
116+
src/fxshadow.h \
117+
src/fxstroke.h \
118+
src/gamebase.h \
119+
src/gameentry.h \
120+
src/igdb.h \
121+
src/imgtools.h \
122+
src/importscraper.h \
123+
src/layer.h \
124+
src/localscraper.h \
125+
src/mobygames.h \
138126
src/nametools.h \
127+
src/netcomm.h \
128+
src/netmanager.h \
129+
src/nocolor.h \
130+
src/openretro.h \
139131
src/pathtools.h \
140-
src/queue.h
132+
src/pegasus.h \
133+
src/platform.h \
134+
src/queue.h \
135+
src/scraperworker.h \
136+
src/screenscraper.h \
137+
src/settings.h \
138+
src/skyscraper.h \
139+
src/strtools.h \
140+
src/thegamesdb.h \
141+
src/xmlreader.h \
142+
src/zxinfodk.h
141143

142144
SOURCES += src/main.cpp \
143-
src/skyscraper.cpp \
144-
src/netmanager.cpp \
145-
src/netcomm.cpp \
146-
src/xmlreader.cpp \
147-
src/settings.cpp \
145+
src/abstractfrontend.cpp \
146+
src/abstractscraper.cpp \
147+
src/arcadedb.cpp \
148+
src/attractmode.cpp \
149+
src/batocera.cpp \
150+
src/cache.cpp \
148151
src/cli.cpp \
149152
src/compositor.cpp \
150153
src/config.cpp \
151-
src/strtools.cpp \
152-
src/imgtools.cpp \
153-
src/esgamelist.cpp \
154-
src/scraperworker.cpp \
155-
src/cache.cpp \
156-
src/localscraper.cpp \
157-
src/importscraper.cpp \
158-
src/gameentry.cpp \
159-
src/abstractscraper.cpp \
160-
src/abstractfrontend.cpp \
154+
src/crc32.cpp \
161155
src/emulationstation.cpp \
162156
src/esde.cpp \
163-
src/batocera.cpp \
164-
src/attractmode.cpp \
165-
src/pegasus.cpp \
166-
src/openretro.cpp \
167-
src/thegamesdb.cpp \
168-
src/zxinfodk.cpp \
169-
src/screenscraper.cpp \
170-
src/crc32.cpp \
171-
src/mobygames.cpp \
172-
src/gamebase.cpp \
173-
src/igdb.cpp \
174-
src/arcadedb.cpp \
175-
src/platform.cpp \
176-
src/layer.cpp \
177-
src/fxshadow.cpp \
157+
src/esgamelist.cpp \
158+
src/fxbalance.cpp \
178159
src/fxblur.cpp \
179-
src/fxmask.cpp \
180-
src/fxframe.cpp \
181-
src/fxrounded.cpp \
182-
src/fxstroke.cpp \
183160
src/fxbrightness.cpp \
161+
src/fxcolorize.cpp \
184162
src/fxcontrast.cpp \
185-
src/fxbalance.cpp \
186-
src/fxopacity.cpp \
163+
src/fxframe.cpp \
187164
src/fxgamebox.cpp \
188165
src/fxhue.cpp \
189-
src/fxsaturation.cpp \
190-
src/fxcolorize.cpp \
166+
src/fxmask.cpp \
167+
src/fxopacity.cpp \
191168
src/fxrotate.cpp \
169+
src/fxrounded.cpp \
170+
src/fxsaturation.cpp \
192171
src/fxscanlines.cpp \
172+
src/fxshadow.cpp \
173+
src/fxstroke.cpp \
174+
src/gamebase.cpp \
175+
src/gameentry.cpp \
176+
src/igdb.cpp \
177+
src/imgtools.cpp \
178+
src/importscraper.cpp \
179+
src/layer.cpp \
180+
src/localscraper.cpp \
181+
src/mobygames.cpp \
193182
src/nametools.cpp \
183+
src/netcomm.cpp \
184+
src/netmanager.cpp \
185+
src/nocolor.cpp \
186+
src/openretro.cpp \
194187
src/pathtools.cpp \
195-
src/queue.cpp
188+
src/pegasus.cpp \
189+
src/platform.cpp \
190+
src/queue.cpp \
191+
src/scraperworker.cpp \
192+
src/screenscraper.cpp \
193+
src/settings.cpp \
194+
src/skyscraper.cpp \
195+
src/strtools.cpp \
196+
src/thegamesdb.cpp \
197+
src/xmlreader.cpp \
198+
src/zxinfodk.cpp
196199

197200
SUBDIRS += \
198201
win32/skyscraper.pro

src/abstractfrontend.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ AbstractFrontend::~AbstractFrontend() {}
4040
void AbstractFrontend::setConfig(Settings *config) { this->config = config; }
4141

4242
void AbstractFrontend::sortEntries(QList<GameEntry> &gameEntries) {
43-
printf("Sorting entries...");
43+
ncprintf("Sorting entries...");
4444
int dots = 0;
4545
std::sort(gameEntries.begin(), gameEntries.end(),
4646
[&dots](const GameEntry a, const GameEntry b) -> bool {
4747
if (dots % 1000 == 0) {
48-
printf(".");
48+
ncprintf(".");
4949
fflush(stdout);
5050
}
5151
dots++;
@@ -60,7 +60,7 @@ void AbstractFrontend::sortEntries(QList<GameEntry> &gameEntries) {
6060

6161
return firstTitle < secondTitle;
6262
});
63-
printf(" \033[1;32mDone!\033[0m\n");
63+
ncprintf(" \033[1;32mDone!\033[0m\n");
6464
}
6565

6666
QString AbstractFrontend::getTargetFilePath(const GameEntry::Types t,

src/abstractscraper.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ void AbstractScraper::getGameData(GameEntry &game) {
8787
netComm->request(game.url);
8888
q.exec();
8989
data = netComm->getData();
90-
// printf("URL IS: '%s'\n", game.url.toStdString().c_str());
91-
// printf("DATA IS:\n'%s'\n", data.data());
90+
// ncprintf("URL IS: '%s'\n", game.url.toStdString().c_str());
91+
// ncprintf("DATA IS:\n'%s'\n", data.data());
9292
populateGameEntry(game);
9393
}
9494

@@ -743,13 +743,14 @@ QVariantMap AbstractScraper::readJson(const QString &filename) {
743743
}
744744
}
745745
if (!canRead) {
746-
printf("\033[1;31mFile '%s' not found or not readable. Please "
747-
"fix.\nNot scraping...\n\033[0m",
748-
filename.toUtf8().constData());
746+
ncprintf("\033[1;31mFile '%s' not found or not readable. Please "
747+
"fix.\nNot scraping...\n\033[0m",
748+
filename.toUtf8().constData());
749749
} else if (jsonObj.isEmpty()) {
750-
printf("\033[1;31mFile '%s' has invalid JSON format. Please fix.\nNot "
751-
"scraping...\n\033[0m",
752-
filename.toUtf8().constData());
750+
ncprintf(
751+
"\033[1;31mFile '%s' has invalid JSON format. Please fix.\nNot "
752+
"scraping...\n\033[0m",
753+
filename.toUtf8().constData());
753754
}
754755
return m;
755756
}

src/attractmode.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void AttractMode::skipExisting(QList<GameEntry> &gameEntries,
8282
QSharedPointer<Queue> queue) {
8383
gameEntries = oldEntries;
8484

85-
printf("Resolving missing entries...");
85+
ncprintf("Resolving missing entries...");
8686
int dots = 0;
8787
for (auto const &ge : gameEntries) {
8888
dots++;
8989
if (dots % 100 == 0) {
90-
printf(".");
90+
ncprintf(".");
9191
fflush(stdout);
9292
}
9393
for (auto qi = queue->begin(), end = queue->end(); qi != end; ++qi) {
@@ -99,7 +99,7 @@ void AttractMode::skipExisting(QList<GameEntry> &gameEntries,
9999
}
100100
}
101101
}
102-
printf(" \033[1;32mDone!\033[0m\n");
102+
ncprintf(" \033[1;32mDone!\033[0m\n");
103103
}
104104

105105
void AttractMode::preserveFromOld(GameEntry &entry) {
@@ -161,7 +161,7 @@ void AttractMode::assembleList(QString &finalOutput,
161161

162162
for (auto &entry : gameEntries) {
163163
if (++dots % dotMod == 0) {
164-
printf(".");
164+
ncprintf(".");
165165
fflush(stdout);
166166
}
167167

@@ -209,8 +209,9 @@ void AttractMode::assembleList(QString &finalOutput,
209209

210210
void AttractMode::checkReqs() {
211211
if (config->frontendExtra.isEmpty()) {
212-
printf("Frontend 'attractmode' requires emulator set with '-e'. Check "
213-
"'--help' for more information.\n");
212+
ncprintf(
213+
"Frontend 'attractmode' requires emulator set with '-e'. Check "
214+
"'--help' for more information.\n");
214215
emit die(
215216
1, "incomplete configuration",
216217
"Frontend 'attractmode' requires '-e' or 'emulator=' to be set");
@@ -230,7 +231,7 @@ void AttractMode::checkReqs() {
230231
}
231232
}
232233

233-
printf("Looking for emulator cfg file:\n");
234+
ncprintf("Looking for emulator cfg file:\n");
234235

235236
// For RetroPie this is linked directly to
236237
// /opt/retropie/configs/all/attractmode/emulators/
@@ -241,7 +242,7 @@ void AttractMode::checkReqs() {
241242
return;
242243
}
243244

244-
printf("Cannot locate emulator cfg file, exiting...\n");
245+
ncprintf("Cannot locate emulator cfg file, exiting...\n");
245246
emit die(1,
246247
QString("can neither access '%1' nor '%2")
247248
.arg(config->frontendExtra)
@@ -251,14 +252,14 @@ void AttractMode::checkReqs() {
251252

252253
bool AttractMode::checkEmulatorFile(QString fileName) {
253254
QFileInfo info(fileName);
254-
printf("Trying '%s'... ", info.absoluteFilePath().toStdString().c_str());
255+
ncprintf("Trying '%s'... ", info.absoluteFilePath().toStdString().c_str());
255256

256257
if (info.exists() && info.isFile()) {
257258
config->frontendExtra = info.absoluteFilePath();
258-
printf("\033[1;32mFound!\033[0m\n\n");
259+
ncprintf("\033[1;32mFound!\033[0m\n\n");
259260
return true;
260261
} else {
261-
printf("Not found!\n");
262+
ncprintf("Not found!\n");
262263
return false;
263264
}
264265
}

0 commit comments

Comments
 (0)