if (length <= p_cli->p_ctx->vt100_ctx.cons.terminal_wid - terminal_offset) This line doesn't recognize when the terminal_offset is greater than the terminal_wid. To check this the comparison should be reversed to if !(length >= p_cli->p_ctx->vt100_ctx.cons.terminal_wid - terminal_offset)
nrf_cli_getopt_option_t help[1] = {{"optname..........20","short............20", "helptext.........20"}};
nrf_cli_help_print(p_cli, help, 1);
nrf_cli_getopt_option_t help1[1] = {{"optname..............40..............40","short..10", "helptext........30.........30"}};
nrf_cli_help_print(p_cli, help1, 1);
nrf_cli_getopt_option_t help2[1] = {{"optname..........20","short........50...............50...............50", "helptext...........20"}};
nrf_cli_help_print(p_cli, help3, 1);
nrf_cli_getopt_option_t help3[1] = {{"optname10","short...............64.............64...........64...........64", "helptext.........20"}};
nrf_cli_help_print(p_cli, help3, 1);
nrf_cli_getopt_option_t help4[1] = {{"optname10","short...............66..............66............66...........66", "helptext.........20"}};
nrf_cli_help_print(p_cli, help5, 1);
nrf_cli_getopt_option_t help5[1] = {{"optname10","short...............65..............65............65..........65", "helptext.........20"}};
nrf_cli_help_print(p_cli, help5, 1);
console output:
With short input everything is okay: 00> Options: 00> -h, --help :Show command help. 00> short............20, optname..........20:helptext.........20 With long input shorter options, helptext correctly wraps: 00> Options: 00> -h, --help :Show command help. 00> short..10, optname..............40..............40:helptext........30....... 00> ..30 With options approaching line width limit(80), help text and "Show command help." wrapping starts to break: 00> Options: 00> -h, --help :Show 00> comma 00> nd 00> help. 00> short........50...............50...............50, optname..........20:helpt 00> ext.. 00> ..... 00> ....2 00> 0 With options at 74 chars line width limit(80), help text and "Show command help." wrapping is at its worst: 00> Options: 00> -h, --help :S 00> h 00> o 00> w 00> c 00> o 00> m 00> m 00> a 00> n 00> d 00> h 00> e 00> l 00> p 00> . 00> short...............64.............64...........64...........64, optname10:h 00> e 00> l 00> p 00> t 00> e 00> x 00> t 00> . 00> . 00> . 00> . 00> . 00> . 00> . 00> . 00> . 00> 2 00> 0 With options at 76 chars the length check fails and the line does not wrap, formatting looks fine but is wider than 80 chars: 00> Options: 00> -h, --help :Show command help. 00> short...............66..............66............66...........66, optname10:helptext.........20 With options length at exactly 75 chars wrapping is stuck in an infinite loop until watchdog causes a reboot: 00> Options: 00> -h, --help : 00> 00> 00> 00> 00> 00> 00> 00> 00> 00>
Has a workaround for this wrapping already been implemented or will we need to implement ourselves?