summaryrefslogtreecommitdiff
path: root/lthor.c
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2016-05-13 14:12:05 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2016-07-07 17:08:54 +0200
commit7fd51cfbcd2352daac76dd0af370881d7f29e219 (patch)
tree42a467b6e2496cf6b49980b842b8d24401b9a1ac /lthor.c
parentbec8c1780ee8f8f3b4498a8bfbbcef7e5146e891 (diff)
downloadlthor-7fd51cfbcd2352daac76dd0af370881d7f29e219.tar.gz
lthor-7fd51cfbcd2352daac76dd0af370881d7f29e219.tar.bz2
lthor-7fd51cfbcd2352daac76dd0af370881d7f29e219.zip
Improve colors handling in terminal
Instead of repeating magick strings in many places let's use a suitable defines for them to make the code more readable. Change-Id: I7b4935bd459e375be39d1dd223d20c71635670cc Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'lthor.c')
-rw-r--r--lthor.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/lthor.c b/lthor.c
index b4e6b3d..f17f78a 100644
--- a/lthor.c
+++ b/lthor.c
@@ -30,6 +30,11 @@
#define KB (1024)
#define MB (1024*KB)
+#define TERM_YELLOW "\x1b[0;33;1m"
+#define TERM_LIGHT_GREEN "\x1b[0;32;1m"
+#define TERM_RED "\x1b[0;31;1m"
+#define TERM_NORMAL "\x1b[0m"
+
struct helper {
struct thor_data_src *data;
enum thor_data_type type;
@@ -111,7 +116,7 @@ static int init_data_parts(const char *pitfile, char **tarfilelist,
}
while (*tarfilelist) {
- printf("\x1b[0;33;1m%s :\x1b[0m\n", *tarfilelist);
+ printf(TERM_YELLOW "%s :" TERM_NORMAL "\n" , *tarfilelist);
data_parts[entry].type = THOR_NORMAL_DATA;
data_parts[0].name = *tarfilelist;
ret = thor_get_data_src(*tarfilelist, THOR_FORMAT_TAR,
@@ -145,7 +150,8 @@ static void report_next_entry(thor_device_handle *th,
{
struct time_data *tdata = user_data;
- printf("[\x1b[0;32;1m%s\x1b[0m]\n", data->get_name(data));
+ printf("[" TERM_LIGHT_GREEN "%s" TERM_NORMAL"]\n",
+ data->get_name(data));
init_time_data(tdata);
}
@@ -234,17 +240,17 @@ static int do_download(thor_device_handle *th, struct helper *data_parts,
ret = thor_end_session(th);
if (ret)
- fprintf(stderr, "\x1b[0;33;1mmissing RQT_DL_EXIT response "
- "from broken bootloader\x1b[0m\n");
+ fprintf(stderr, TERM_YELLOW "missing RQT_DL_EXIT response "
+ "from broken bootloader" TERM_NORMAL"\n");
fprintf(stderr, "\nrequest target reboot : ");
ret = thor_reboot(th);
if (ret) {
- fprintf(stderr, "\x1b[0;31;1mfailed\x1b[0m\n");
+ fprintf(stderr, TERM_RED "failed" TERM_NORMAL"\n");
goto out;
} else {
- fprintf(stderr, "\x1b[0;32;1msuccess\x1b[0m\n");
+ fprintf(stderr, TERM_LIGHT_GREEN "success" TERM_NORMAL "\n");
}
out:
return ret;
@@ -287,7 +293,7 @@ static int process_download(struct thor_device_id *dev_id, const char *pitfile,
switch (data_parts[i].type) {
case THOR_PIT_DATA:
- printf("\x1b[0;33;1m%s : \x1b[0m%zuk\n",
+ printf(TERM_YELLOW "%s :" TERM_NORMAL "%zuk\n",
data_parts[i].name, size/KB);
break;
case THOR_NORMAL_DATA:
@@ -298,7 +304,7 @@ static int process_download(struct thor_device_id *dev_id, const char *pitfile,
}
printf("-------------------------\n");
- printf("\t\x1b[0;33;1mtotal\x1b[0m :\t%.2fMB\n\n",
+ printf("\t" TERM_YELLOW "total" TERM_NORMAL" :\t%.2fMB\n\n",
(double)total_size/MB);
ret = do_download(th, data_parts, entries, total_size);