mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 17:59:25 +01:00
client: handle wide chars for table rows
Find out printing width of wide chars via wcwidth().
This commit is contained in:
parent
ba6a48018c
commit
d82869c346
@ -30,6 +30,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
@ -398,21 +399,37 @@ static unsigned int color_end(char *s)
|
|||||||
*/
|
*/
|
||||||
static char* next_line(char *s, unsigned int *max, char **color_out)
|
static char* next_line(char *s, unsigned int *max, char **color_out)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i = 0;
|
||||||
int last_space = -1;
|
int last_space = -1;
|
||||||
int last_color = -1;
|
int last_color = -1;
|
||||||
|
unsigned int s_len = strlen(s);
|
||||||
|
|
||||||
/* Find the last space before 'max', as well as any color */
|
/* Find the last space before 'max', as well as any color */
|
||||||
for (i = 0; i <= *max && s[i] != '\0'; i++) {
|
while (i <= *max && i != s_len) {
|
||||||
|
int sequence_len;
|
||||||
|
int sequence_columns;
|
||||||
|
wchar_t w;
|
||||||
|
|
||||||
|
if (s[i] == 0x1b) {
|
||||||
|
sequence_len = color_end(s + i);
|
||||||
|
/* color escape won't count for column width */
|
||||||
|
sequence_columns = 0;
|
||||||
|
last_color = i;
|
||||||
|
} else {
|
||||||
if (s[i] == ' ')
|
if (s[i] == ' ')
|
||||||
last_space = i;
|
last_space = i;
|
||||||
else if (s[i] == 0x1b) {
|
sequence_len = l_utf8_get_codepoint(&s[i], s_len - i,
|
||||||
/* color escape won't count for column width */
|
&w);
|
||||||
*max += color_end(s + i);
|
if (sequence_len < 0) {
|
||||||
last_color = i;
|
sequence_len = 1;
|
||||||
/* Add width for non-codepoint UTF-8 bytes */
|
sequence_columns = 1;
|
||||||
} else if (((uint8_t)s[i] >> 6) == 2)
|
} else
|
||||||
*max += 1;
|
sequence_columns = wcwidth(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compensate max bytes */
|
||||||
|
*max += sequence_len - sequence_columns;
|
||||||
|
i += sequence_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reached the end of the string within the column bounds */
|
/* Reached the end of the string within the column bounds */
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ell/ell.h>
|
#include <ell/ell.h>
|
||||||
|
|
||||||
@ -50,6 +51,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
bool all_done;
|
bool all_done;
|
||||||
|
|
||||||
|
setlocale(LC_CTYPE, "");
|
||||||
|
|
||||||
if (!l_main_init())
|
if (!l_main_init())
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user