xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 3c31aa013425aeb37d59bffcf609a4d5a3ad2d78

Improve body of statusbar.c:status_bar_message()
* Rename `len` to `max_width` and use in place of `getmaxx(stdscr)`.
* Rename `status_bar_lines` to `msg_lines`.
* Rename `lines` to `output_lines`.
* Rename `out_msg` to `output_msg`.
* Move declarations closer to their uses.
Author: xaizek
Author date (UTC): 2025-05-24 13:10
Committer name: xaizek
Committer date (UTC): 2025-05-24 13:10
Parent(s): 29deae3da357e7616c6f5716b35400bc4edf414f
Signing key: 99DC5E4DB05F6BE2
Tree: d421e0cf83ce62a294d22c9483e6c2ab1058e074
File Lines added Lines deleted
src/ui/statusbar.c 25 31
File src/ui/statusbar.c changed (mode: 100644) (index a1cc3e7af..c22082dc8)
... ... status_bar_message(const char msg[], int error, int is_history)
205 205
206 206 static int err; static int err;
207 207
208 int len;
209 int lines;
210 int status_bar_lines;
211 const char *out_msg;
212 char truncated_msg[2048];
213
214 208 if(msg != NULL) if(msg != NULL)
215 209 { {
216 210 if(replace_string(&last_message, msg)) if(replace_string(&last_message, msg))
 
... ... status_bar_message(const char msg[], int error, int is_history)
242 236 return; return;
243 237 } }
244 238
245 len = getmaxx(stdscr);
246 status_bar_lines = count_lines(msg, len);
239 int max_width = getmaxx(stdscr);
240 int msg_lines = count_lines(msg, max_width);
247 241
248 lines = status_bar_lines;
249 if(status_bar_lines > 1 || utf8_strsw(msg) > (size_t)getmaxx(status_bar))
242 int output_lines = msg_lines;
243 if(msg_lines > 1 || utf8_strsw(msg) > (size_t)getmaxx(status_bar))
250 244 { {
251 245 /* Need one more line to display PRESS_ENTER_MSG. */ /* Need one more line to display PRESS_ENTER_MSG. */
252 ++lines;
246 ++output_lines;
253 247 } }
254 248
255 out_msg = msg;
249 const char *output_msg = msg;
250 char truncated_msg[2048];
256 251
257 if(lines > 1)
252 if(output_lines > 1)
258 253 { {
259 if(cfg.trunc_normal_sb_msgs && !err && !is_history && status_bar_lines == 1)
254 if(cfg.trunc_normal_sb_msgs && !err && !is_history && msg_lines == 1)
260 255 { {
261 truncate_with_ellipsis(msg, getmaxx(stdscr) - FIELDS_WIDTH(),
262 truncated_msg);
263 out_msg = truncated_msg;
264 lines = 1;
256 truncate_with_ellipsis(msg, max_width - FIELDS_WIDTH(), truncated_msg);
257 output_msg = truncated_msg;
258 output_lines = 1;
265 259 } }
266 260 else else
267 261 { {
268 const int extra = DIV_ROUND_UP(ARRAY_LEN(PRESS_ENTER_MSG) - 1, len) - 1;
269 lines += extra;
262 int extra = DIV_ROUND_UP(ARRAY_LEN(PRESS_ENTER_MSG) - 1, max_width) - 1;
263 output_lines += extra;
270 264 } }
271 265 } }
272 266
273 if(lines > getmaxy(stdscr))
267 if(output_lines > getmaxy(stdscr))
274 268 { {
275 269 modmore_enter(msg); modmore_enter(msg);
276 270 return; return;
277 271 } }
278 272
279 (void)ui_stat_reposition(lines, 0);
280 mvwin(status_bar, getmaxy(stdscr) - lines, 0);
281 if(lines == 1)
273 (void)ui_stat_reposition(output_lines, 0);
274 mvwin(status_bar, getmaxy(stdscr) - output_lines, 0);
275 if(output_lines == 1)
282 276 { {
283 wresize(status_bar, lines, getmaxx(stdscr) - FIELDS_WIDTH());
277 wresize(status_bar, output_lines, max_width - FIELDS_WIDTH());
284 278 } }
285 279 else else
286 280 { {
287 wresize(status_bar, lines, getmaxx(stdscr));
281 wresize(status_bar, output_lines, max_width);
288 282 } }
289 283 checked_wmove(status_bar, 0, 0); checked_wmove(status_bar, 0, 0);
290 284
 
... ... status_bar_message(const char msg[], int error, int is_history)
301 295 } }
302 296 werase(status_bar); werase(status_bar);
303 297
304 wprint(status_bar, out_msg);
305 multiline_status_bar = lines > 1;
298 wprint(status_bar, output_msg);
299 multiline_status_bar = output_lines > 1;
306 300 if(multiline_status_bar) if(multiline_status_bar)
307 301 { {
308 302 checked_wmove(status_bar, checked_wmove(status_bar,
309 lines - DIV_ROUND_UP(ARRAY_LEN(PRESS_ENTER_MSG), len), 0);
303 output_lines - DIV_ROUND_UP(ARRAY_LEN(PRESS_ENTER_MSG), max_width), 0);
310 304 wclrtoeol(status_bar); wclrtoeol(status_bar);
311 if(lines < status_bar_lines)
312 wprintw(status_bar, "%d of %d lines. ", lines, status_bar_lines);
305 if(output_lines < msg_lines)
306 wprintw(status_bar, "%d of %d lines. ", output_lines, msg_lines);
313 307 wprintw(status_bar, "%s", PRESS_ENTER_MSG); wprintw(status_bar, "%s", PRESS_ENTER_MSG);
314 308 } }
315 309
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master