summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2016-05-13 14:12:05 +0200
committerSeung-Woo Kim <sw0312.kim@samsung.com>2016-07-25 14:39:49 +0900
commit40175b01581831beff844c7bebe3fe3b8bf51cc4 (patch)
tree3bd88d8d792a18a8aa3d65e8a80b9ae54f9ea4f7
parent143d0d56311fea24ee3165d503f5d545cd1fec99 (diff)
downloadlthor-40175b01581831beff844c7bebe3fe3b8bf51cc4.tar.gz
lthor-40175b01581831beff844c7bebe3fe3b8bf51cc4.tar.bz2
lthor-40175b01581831beff844c7bebe3fe3b8bf51cc4.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>
-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);