tc: implement color output
Subsystems (2)
PATCH 1/1 tc: implement color output
Implement the -color option; in this case -co is ambiguous since it was already used for -conf.
For now this just means putting device name in color.
Signed-off-by Stephen Hemminger <[email protected]>
--- man/man8/tc.8 | 9 +++++++-- tc/tc.c | 15 +++++++++++---- tc/tc_filter.c | 3 +-- tc/tc_qdisc.c | 3 +-- tc/tc_util.c | 11 +++++++++++ tc/tc_util.h | 1 + 6 files changed, 32 insertions(+), 10 deletions(-)
man/man8/tc.8 +7 -2
@@ -94,10 +94,11 @@ tc \- show / manipulate traffic control settings \fB\-s\fR[\fItatistics\fR] | \fB\-d\fR[\fIetails\fR] | \fB\-r\fR[\fIaw\fR] | -\fB\-p\fR[\fIretty\fR] | \fB\-i\fR[\fIec\fR] | \fB\-g\fR[\fIraph\fR] | -\fB\-j\fR[\fIjson\fR] } +\fB\-j\fR[\fIjson\fR] | +\fB\-p\fR[\fIretty\fR] | +\fB\-col\fR[\fIor\fR] } .SH DESCRIPTION .B Tc
@@ -685,6 +686,10 @@ option was specified. Classes can be filtered only by .BR "dev" option. +.TP +.BR "\ -color" +Use color output. + .TP .BR "\-j", " \-json" Display results in JSON format.
tc/tc.c +11 -4
@@ -41,6 +41,7 @@ int use_iec;int force;bool use_names;int json; +int color;static char *conf_file;
@@ -186,10 +187,11 @@ noexist:static void usage (void ) {fprintf (stderr,"Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n" -" tc [-force] -batch filename\n" -"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n" -" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n" -" -nm | -nam[es] | { -cf | -conf } path } | -j[son]\n" ); +" tc [-force] -batch filename\n" +"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n" +" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -b[atch] [filename] | -n[etns] name |\n" +" -nm | -nam[es] | { -cf | -conf } path } |\n" +" -j[son] -p[retty] -c[olor]\n" ); }static int do_cmd (int argc,char **argv,void *buf,size_t buflen)
@@ -476,6 +478,8 @@ int main(int argc, char **argv) matches(argv[1], "-conf") == 0) {NEXT_ARG (); conf_file = argv[1 ]; + } else if (matches(argv[1], "-color") == 0) { + ++color; } else if (matches(argv[1], "-timestamp") == 0) { timestamp++; }else if (matches (argv[1 ],"-tshort" ) ==0 ) {
@@ -490,6 +494,9 @@ int main(int argc, char **argv) argc--; argv++; } +if (color & !json) +enable_color (); +if (batch_file)return batch (batch_file);
tc/tc_filter.c +1 -2
@@ -303,8 +303,7 @@ int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) t->tcm_block_index); }else {if (!filter_ifindex || filter_ifindex != t->tcm_ifindex) -print_string (PRINT_ANY ,"dev" ,"dev %s " , -ll_index_to_name (t->tcm_ifindex)); +print_devname (PRINT_ANY , t->tcm_ifindex);if (!filter_parent || filter_parent != t->tcm_parent) {if (t->tcm_parent ==TC_H_ROOT )
tc/tc_qdisc.c +1 -2
@@ -270,8 +270,7 @@ int print_qdisc(const struct sockaddr_nl *who,print_string (PRINT_FP ,NULL ," " ,NULL );if (filter_ifindex ==0 ) -print_string (PRINT_ANY ,"dev" ,"dev %s " , -ll_index_to_name (t->tcm_ifindex)); +print_devname (PRINT_ANY , t->tcm_ifindex);if (t->tcm_parent ==TC_H_ROOT )print_bool (PRINT_ANY ,"root" ,"root " , true);
tc/tc_util.c +11 -0
@@ -444,6 +444,17 @@ int get_size_and_cell(unsigned int *size, int *cell_log, char *str)return 0 ; } +void print_devname (enum output_type type,int ifindex) +{ +const char *ifname =ll_index_to_name (ifindex); + +if (!is_json_context ()) +printf ("dev " ); + +print_color_string (type,COLOR_IFNAME , +"dev" ,"%s " , ifname); +} +void print_size (char *buf,int len,__u32 sz) {double tmp = sz;
tc/tc_util.h +1 -0
@@ -89,6 +89,7 @@ void print_size(char *buf, int len, __u32 size);void print_qdisc_handle (char *buf,int len,__u32 h);void print_time (char *buf,int len,__u32 time);void print_linklayer (char *buf,int len,unsigned int linklayer); +void print_devname (enum output_type type,int ifindex);char *sprint_rate (__u64 rate,char *buf);char *sprint_size (__u32 size,char *buf);
Signature · 1 line
2.16.1
David Ahern
AppliedQuoted 5 lines · Stephen Hemminger
Implement the -color option; in this case -co is ambiguous since it was already used for -conf.
For now this just means putting device name in color.Signed-off-by Stephen Hemminger <[email protected]>
Quoted 9 lines
--- man/man8/tc.8 | 9 +++++++-- tc/tc.c | 15 +++++++++++---- tc/tc_filter.c | 3 +-- tc/tc_qdisc.c | 3 +-- tc/tc_util.c | 11 +++++++++++ tc/tc_util.h | 1 + 6 files changed, 32 insertions(+), 10 deletions(-)
applied to iproute2-next