|
5 | 5 | use tockloader_lib::attributes::app_attributes::AppAttributes; |
6 | 6 | use tockloader_lib::attributes::system_attributes::SystemAttributes; |
7 | 7 |
|
8 | | -// TODO(george-cosma): Fix this |
9 | | -#[allow(clippy::uninlined_format_args)] |
| 8 | +// ANSI escape codes for colors |
| 9 | +const RESET: &str = "\x1b[0m"; |
| 10 | +const BOLD_MAGENTA: &str = "\x1b[1;35m"; |
| 11 | +const BOLD_RED: &str = "\x1b[1;31m"; |
| 12 | +const BOLD_GREEN: &str = "\x1b[1;32m"; |
| 13 | +const BOLD_YELLOW: &str = "\x1b[1;33m"; |
| 14 | + |
10 | 15 | pub async fn print_list(app_details: &[AppAttributes]) { |
11 | 16 | for (i, details) in app_details.iter().enumerate() { |
12 | | - println!("\n\x1b[0m\x1b[1;35m ┏━━━━━━━━━━━━━━━━┓"); |
13 | | - println!( |
14 | | - "\x1b[0m\x1b[1;31m ┃ \x1b[0m\x1b[1;32m App_{:<9?} \x1b[0m\x1b[1;31m┃", |
15 | | - i |
16 | | - ); |
17 | | - println!("\x1b[0m\x1b[1;33m ┗━━━━━━━━━━━━━━━━┛"); |
| 17 | + println!("\n{RESET}{BOLD_MAGENTA} ┏━━━━━━━━━━━━━━━━┓"); |
| 18 | + println!("{RESET}{BOLD_RED} ┃ {RESET}{BOLD_GREEN} App_{i} {RESET}{BOLD_RED}┃",); |
| 19 | + println!("{RESET}{BOLD_YELLOW} ┗━━━━━━━━━━━━━━━━┛"); |
18 | 20 | println!( |
19 | | - "\n \x1b[1;32m Name: {}", |
20 | | - details.tbf_header.get_package_name().unwrap() |
| 21 | + "\n {BOLD_GREEN} Name: {RESET}{}", |
| 22 | + details.tbf_header.get_package_name().unwrap(), |
21 | 23 | ); |
22 | 24 |
|
23 | 25 | println!( |
24 | | - " \x1b[1;32m Version: {}", |
25 | | - details.tbf_header.get_binary_version() |
| 26 | + " {BOLD_GREEN} Version: {RESET}{}", |
| 27 | + details.tbf_header.get_binary_version(), |
26 | 28 | ); |
27 | 29 |
|
28 | 30 | println!( |
29 | | - " \x1b[1;32m Enabled: {}", |
30 | | - details.tbf_header.enabled() |
| 31 | + " {BOLD_GREEN} Enabled: {RESET}{}", |
| 32 | + details.tbf_header.enabled(), |
31 | 33 | ); |
32 | 34 |
|
33 | 35 | println!( |
34 | | - " \x1b[1;32m Sticky: {}", |
35 | | - details.tbf_header.sticky() |
| 36 | + " {BOLD_GREEN} Sticky: {RESET}{}", |
| 37 | + details.tbf_header.sticky(), |
36 | 38 | ); |
37 | 39 |
|
38 | 40 | println!( |
39 | | - " \x1b[1;32m Total_Size: {}\n\n", |
40 | | - details.tbf_header.total_size() |
| 41 | + " {BOLD_GREEN} Total_Size: {RESET}{}\n\n", |
| 42 | + details.tbf_header.total_size(), |
41 | 43 | ); |
42 | 44 | } |
43 | 45 | } |
44 | 46 |
|
45 | | -// TODO(george-cosma): Fix this |
46 | | -#[allow(clippy::uninlined_format_args)] |
47 | 47 | pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut SystemAttributes) { |
48 | 48 | for (i, details) in app_details.iter().enumerate() { |
49 | | - println!("\n\x1b[0m\x1b[1;35m ┏━━━━━━━━━━━━━━━━┓"); |
50 | | - println!( |
51 | | - "\x1b[0m\x1b[1;31m ┃ \x1b[0m\x1b[1;32m App_{:<9?} \x1b[0m\x1b[1;31m┃", |
52 | | - i |
53 | | - ); |
54 | | - println!("\x1b[0m\x1b[1;33m ┗━━━━━━━━━━━━━━━━┛"); |
| 49 | + println!("\n{RESET}{BOLD_MAGENTA} ┏━━━━━━━━━━━━━━━━┓"); |
| 50 | + println!("{RESET}{BOLD_RED} ┃ {RESET}{BOLD_GREEN} App_{i} {RESET}{BOLD_RED}┃"); |
| 51 | + println!("{RESET}{BOLD_YELLOW} ┗━━━━━━━━━━━━━━━━┛"); |
| 52 | + |
55 | 53 | println!( |
56 | | - "\n \x1b[1;32m Name: {}", |
57 | | - details.tbf_header.get_package_name().unwrap() |
| 54 | + "\n {BOLD_GREEN} Name: {RESET}{}", |
| 55 | + details.tbf_header.get_package_name().unwrap(), |
58 | 56 | ); |
59 | 57 |
|
60 | 58 | println!( |
61 | | - " \x1b[1;32m Version: {}", |
62 | | - details.tbf_header.get_binary_version() |
| 59 | + " {BOLD_GREEN} Version: {RESET}{}", |
| 60 | + details.tbf_header.get_binary_version(), |
63 | 61 | ); |
64 | 62 |
|
65 | 63 | println!( |
66 | | - " \x1b[1;32m Enabled: {}", |
67 | | - details.tbf_header.enabled() |
| 64 | + " {BOLD_GREEN} Enabled: {RESET}{}", |
| 65 | + details.tbf_header.enabled(), |
68 | 66 | ); |
69 | 67 |
|
70 | 68 | println!( |
71 | | - " \x1b[1;32m Stricky: {}", |
72 | | - details.tbf_header.sticky() |
| 69 | + " {BOLD_GREEN} Sticky: {RESET}{}", |
| 70 | + details.tbf_header.sticky(), |
73 | 71 | ); |
74 | 72 |
|
75 | 73 | println!( |
76 | | - " \x1b[1;32m Total_Size: {}", |
77 | | - details.tbf_header.total_size() |
| 74 | + " {BOLD_GREEN} Total_Size: {RESET}{}", |
| 75 | + details.tbf_header.total_size(), |
78 | 76 | ); |
79 | 77 |
|
80 | 78 | println!( |
81 | | - " \x1b[1;32m Address in Flash: {}", |
82 | | - system_details.appaddr.unwrap() |
| 79 | + " {BOLD_GREEN} Address in Flash: {RESET}{}", |
| 80 | + system_details.appaddr.unwrap(), |
83 | 81 | ); |
84 | 82 |
|
85 | 83 | println!( |
86 | | - " \x1b[1;32m TBF version: {}", |
87 | | - details.tbf_header.get_binary_version() |
| 84 | + " {BOLD_GREEN} TBF version: {RESET}{}", |
| 85 | + details.tbf_header.get_binary_version(), |
88 | 86 | ); |
89 | 87 |
|
90 | 88 | println!( |
91 | | - " \x1b[1;32m header_size: {}", |
92 | | - details.tbf_header.header_size() |
| 89 | + " {BOLD_GREEN} header_size: {RESET}{}", |
| 90 | + details.tbf_header.header_size(), |
93 | 91 | ); |
94 | 92 |
|
95 | 93 | println!( |
96 | | - " \x1b[1;32m total_size: {}", |
97 | | - details.tbf_header.total_size() |
| 94 | + " {BOLD_GREEN} total_size: {RESET}{}", |
| 95 | + details.tbf_header.total_size(), |
98 | 96 | ); |
99 | 97 |
|
100 | 98 | println!( |
101 | | - " \x1b[1;32m checksum: {}", |
102 | | - details.tbf_header.checksum() |
| 99 | + " {BOLD_GREEN} checksum: {RESET}{}", |
| 100 | + details.tbf_header.checksum(), |
103 | 101 | ); |
104 | 102 |
|
105 | | - println!(" \x1b[1;32m flags:"); |
| 103 | + println!(" {BOLD_GREEN} flags:{RESET}"); |
106 | 104 | println!( |
107 | | - " \x1b[1;32m enabled: {}", |
108 | | - details.tbf_header.enabled() |
| 105 | + " {BOLD_GREEN} enabled: {RESET}{}", |
| 106 | + details.tbf_header.enabled(), |
109 | 107 | ); |
110 | 108 |
|
111 | 109 | println!( |
112 | | - " \x1b[1;32m sticky: {}", |
113 | | - details.tbf_header.sticky() |
| 110 | + " {BOLD_GREEN} sticky: {RESET}{}", |
| 111 | + details.tbf_header.sticky(), |
114 | 112 | ); |
115 | 113 |
|
116 | | - println!(" \x1b[1;32m TVL: Main (1)",); |
117 | | - |
| 114 | + println!(" {BOLD_GREEN} TVL: Main (1){RESET}"); |
118 | 115 | println!( |
119 | | - " \x1b[1;32m init_fn_offset: {}", |
120 | | - details.tbf_header.get_init_function_offset() |
| 116 | + " {BOLD_GREEN} init_fn_offset: {RESET}{}", |
| 117 | + details.tbf_header.get_init_function_offset(), |
121 | 118 | ); |
122 | 119 |
|
123 | 120 | println!( |
124 | | - " \x1b[1;32m protected_size: {}", |
125 | | - details.tbf_header.get_protected_size() |
| 121 | + " {BOLD_GREEN} protected_size: {RESET}{}", |
| 122 | + details.tbf_header.get_protected_size(), |
126 | 123 | ); |
127 | 124 |
|
128 | 125 | println!( |
129 | | - " \x1b[1;32m minimum_ram_size: {}", |
130 | | - details.tbf_header.get_minimum_app_ram_size() |
| 126 | + " {BOLD_GREEN} minimum_ram_size: {RESET}{}", |
| 127 | + details.tbf_header.get_minimum_app_ram_size(), |
131 | 128 | ); |
132 | 129 |
|
133 | | - println!(" \x1b[1;32m TVL: Program (9)",); |
134 | | - |
| 130 | + println!(" {BOLD_GREEN} TVL: Program (9){RESET}"); |
135 | 131 | println!( |
136 | | - " \x1b[1;32m init_fn_offset: {}", |
137 | | - details.tbf_header.get_init_function_offset() |
| 132 | + " {BOLD_GREEN} init_fn_offset: {RESET}{}", |
| 133 | + details.tbf_header.get_init_function_offset(), |
138 | 134 | ); |
139 | 135 |
|
140 | 136 | println!( |
141 | | - " \x1b[1;32m protected_size: {}", |
142 | | - details.tbf_header.get_protected_size() |
| 137 | + " {BOLD_GREEN} protected_size: {RESET}{}", |
| 138 | + details.tbf_header.get_protected_size(), |
143 | 139 | ); |
144 | 140 |
|
145 | 141 | println!( |
146 | | - " \x1b[1;32m minimum_ram_size: {}", |
147 | | - details.tbf_header.get_minimum_app_ram_size() |
| 142 | + " {BOLD_GREEN} minimum_ram_size: {RESET}{}", |
| 143 | + details.tbf_header.get_minimum_app_ram_size(), |
148 | 144 | ); |
149 | 145 |
|
150 | 146 | println!( |
151 | | - " \x1b[1;32m binary_end_offset: {}", |
152 | | - details.tbf_header.get_binary_end() |
| 147 | + " {BOLD_GREEN} binary_end_offset: {RESET}{}", |
| 148 | + details.tbf_header.get_binary_end(), |
153 | 149 | ); |
154 | 150 |
|
155 | 151 | println!( |
156 | | - " \x1b[1;32m app_version: {}", |
157 | | - details.tbf_header.get_binary_version() |
| 152 | + " {BOLD_GREEN} app_version: {RESET}{}", |
| 153 | + details.tbf_header.get_binary_version(), |
158 | 154 | ); |
159 | 155 |
|
160 | | - println!(" \x1b[1;32m TVL: Package Name (3)",); |
161 | | - |
| 156 | + println!(" {BOLD_GREEN} TVL: Package Name (3){RESET}"); |
162 | 157 | println!( |
163 | | - " \x1b[1;32m package_name: {}", |
164 | | - details.tbf_header.get_package_name().unwrap() |
| 158 | + " {BOLD_GREEN} package_name: {RESET}{}", |
| 159 | + details.tbf_header.get_package_name().unwrap(), |
165 | 160 | ); |
166 | 161 |
|
167 | | - println!(" \x1b[1;32m TVL: Kernel Version (8)",); |
168 | | - |
| 162 | + println!(" {BOLD_GREEN} TVL: Kernel Version (8){RESET}"); |
169 | 163 | println!( |
170 | | - " \x1b[1;32m kernel_major: {}", |
171 | | - details.tbf_header.get_kernel_version().unwrap().0 |
| 164 | + " {BOLD_GREEN} kernel_major: {RESET}{}", |
| 165 | + details.tbf_header.get_kernel_version().unwrap().0, |
172 | 166 | ); |
173 | 167 |
|
174 | 168 | println!( |
175 | | - " \x1b[1;32m kernel_minor: {}", |
| 169 | + " {BOLD_GREEN} kernel_minor: {RESET}{}", |
176 | 170 | details.tbf_header.get_kernel_version().unwrap().1, |
177 | 171 | ); |
178 | 172 |
|
179 | | - println!("\n \x1b[1;32m Footer"); |
| 173 | + println!("\n {BOLD_GREEN} Footer{RESET}"); |
180 | 174 |
|
181 | 175 | let mut total_footer_size: u32 = 0; |
182 | 176 |
|
183 | | - // Usage of +4 is a result of the structure of the Tock Binary Format (https://book.tockos.org/doc/tock_binary_format) |
184 | | - // Because we need the real size of the footer including the type and length. |
| 177 | + // Usage of +4 is a result of the structure of the Tock Binary Format (https://book.tockos.org/doc/tock_binary_format) |
| 178 | + // Because we need the real size of the footer including the type and length. |
185 | 179 | for footer_details in details.tbf_footers.iter() { |
186 | 180 | total_footer_size += footer_details.size + 4; |
187 | 181 | } |
188 | 182 |
|
189 | | - println!( |
190 | | - " \x1b[1;32m footer_size: {}", |
191 | | - total_footer_size |
192 | | - ); |
| 183 | + println!(" {BOLD_GREEN} footer_size: {RESET}{total_footer_size}"); |
193 | 184 |
|
194 | | - for (i, footer_details) in details.tbf_footers.iter().enumerate() { |
195 | | - println!(" \x1b[1;32m Footer [{i}] TVL: Credentials"); |
| 185 | + for (j, footer_details) in details.tbf_footers.iter().enumerate() { |
| 186 | + println!(" {BOLD_GREEN} Footer [{j}] TVL: Credentials{RESET}"); |
196 | 187 |
|
197 | 188 | println!( |
198 | | - " \x1b[1;32m Type: {}", |
199 | | - footer_details.credentials.get_type() |
| 189 | + " {BOLD_GREEN} Type: {RESET}{}", |
| 190 | + footer_details.credentials.get_type(), |
200 | 191 | ); |
201 | 192 |
|
202 | | - // Usage of -4 is a result of the structure of the Tock Binary Format (https://book.tockos.org/doc/tock_binary_format) |
203 | | - // Because we only need the size of the credentials without the type and length bytes. |
| 193 | + // Usage of -4 is a result of the structure of the Tock Binary Format (https://book.tockos.org/doc/tock_binary_format) |
| 194 | + // Because we only need the size of the credentials without the type and length bytes. |
204 | 195 | println!( |
205 | | - " \x1b[1;32m Length: {}", |
206 | | - footer_details.size - 4 |
| 196 | + " {BOLD_GREEN} Length: {RESET}{}", |
| 197 | + footer_details.size - 4, |
207 | 198 | ); |
208 | 199 | } |
209 | 200 | } |
210 | 201 |
|
211 | | - println!("\n\n\x1b[1;32m Kernel Attributes"); |
| 202 | + println!("\n\n{BOLD_GREEN} Kernel Attributes{RESET}"); |
212 | 203 | println!( |
213 | | - "\x1b[1;32m Sentinel: {:<10}", |
214 | | - system_details.sentinel.clone().unwrap() |
| 204 | + "{BOLD_GREEN} Sentinel: {:<10}{RESET}", |
| 205 | + system_details.sentinel.clone().unwrap(), |
215 | 206 | ); |
216 | 207 | println!( |
217 | | - "\x1b[1;32m Version: {:<10}", |
218 | | - system_details.kernel_version.unwrap() |
| 208 | + "{BOLD_GREEN} Version: {:<10}{RESET}", |
| 209 | + system_details.kernel_version.unwrap(), |
219 | 210 | ); |
220 | | - println!("\x1b[1;32m KATLV: APP Memory"); |
| 211 | + println!("{BOLD_GREEN} KATLV: APP Memory{RESET}"); |
221 | 212 | println!( |
222 | | - "\x1b[1;32m app_memory_start: {:<10}", |
223 | | - system_details.app_mem_start.unwrap() |
| 213 | + "{BOLD_GREEN} app_memory_start: {:<10}{RESET}", |
| 214 | + system_details.app_mem_start.unwrap(), |
224 | 215 | ); |
225 | 216 | println!( |
226 | | - "\x1b[1;32m app_memory_len: {:<10}", |
227 | | - system_details.app_mem_len.unwrap() |
| 217 | + "{BOLD_GREEN} app_memory_len: {:<10}{RESET}", |
| 218 | + system_details.app_mem_len.unwrap(), |
228 | 219 | ); |
229 | | - println!("\x1b[1;32m KATLV: Kernel Binary"); |
| 220 | + println!("{BOLD_GREEN} KATLV: Kernel Binary{RESET}"); |
230 | 221 | println!( |
231 | | - "\x1b[1;32m kernel_binary_start: {:<10}", |
232 | | - system_details.kernel_bin_start.unwrap() |
| 222 | + "{BOLD_GREEN} kernel_binary_start: {:<10}{RESET}", |
| 223 | + system_details.kernel_bin_start.unwrap(), |
233 | 224 | ); |
234 | 225 | println!( |
235 | | - "\x1b[1;32m kernel_binary_len: {:<10}\n\n", |
236 | | - system_details.kernel_bin_len.unwrap() |
| 226 | + "{BOLD_GREEN} kernel_binary_len: {:<10}{RESET}\n\n", |
| 227 | + system_details.kernel_bin_len.unwrap(), |
237 | 228 | ); |
238 | 229 | } |
0 commit comments