-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate the width of each displayed character #185
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test we can add for this change? Or is the testing setup we have now non-applicable for a change such as this?
pick.c
Outdated
@@ -667,19 +667,23 @@ tty_restore(void) | |||
} | |||
|
|||
void | |||
print_line(const char *string, size_t length, int so, ssize_t ulso, ssize_t uleo) | |||
print_line(const char *str, size_t len, int so, ssize_t ulso, ssize_t uleo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I, for one, am of the view to write out as many acronyms as possible. But since we have ssize_t
unt so weiter already, I'd say this falls in line with that style better.
Unfortunately no. Since this change only concerns the displayed
Agree, just renamed the arguments. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @mptre, I really appreciate it!
I added some questions inline in the diff.
I did find a regression but haven't had time to figure out exactly why it's happening. Steps to reproduce:
echo "🤔" | ./pick
- The standout spills over to the next line by one column. (see first screenshot below)
- Type a non-printable character (for example arrow keys)
- All lines (query and choice) are pushed down by one line (see second screenshot below)
I'm currently running bash 4.4.5 on macOS 10.12.4 with LC_CTYPE=UTF-8
.
configure.ac
Outdated
case "${host_os}" in | ||
linux*) build_linux=yes ;; | ||
esac | ||
AM_CONDITIONAL([LINUX], [test "$build_linux" = "yes"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is $build_linux
used solely to define LINUX
so that it can be picked up in Makefile.am
or is it used elsewhere?
configure.ac
Outdated
AC_CANONICAL_HOST | ||
build_linux=no | ||
case "${host_os}" in | ||
linux*) build_linux=yes ;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't used AC_CANONICAL_HOST
before and didn't find any documentation detailing the formatting of host_os
. Is linux*
a reliable pattern for catching all Linux-based OSs?
Makefile.am
Outdated
@@ -2,6 +2,10 @@ AUTOMAKE_OPTIONS=foreign | |||
|
|||
AM_CFLAGS=-pedantic -Wall -Werror -Wextra | |||
|
|||
if LINUX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could defining _XOPEN_SOURCE
on non-linux platforms cause problems? If not, what do you think of always defining it? That way we could avoid the complexities of testing for the host os.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replying to all comments above here. Unfortunately no, defining it on
*BSD makes BSD-specific functions like pledge
and reallocarray
unavailable.
Maybe @mike-burns could shed some insight on how-to solve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for the links! I'm happy to try this and correct course if we run into issues with some distro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why, from a quick skim of the repo, pledge
disappears when defining _XOPEN_SOURCE
. But I do see this in glibc: https://github.com/bminor/glibc/blob/963394a22b38c4ec92b6875a6c06d3b15d5c0d21/include/features.h#L186-L208
So maybe: skip the OS check (which should be a glibc check ... somehow?) and instead do:
AM_CPPFLAGS+=-D_GNU_SOURCE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works, thanks!
pick.c
Outdated
/* If uleo is greater than columns the underline attribute will spill | ||
* over on the next line unless all attributes are exited. */ | ||
/* | ||
* If uleo is greater than columns the underline attribute will spill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment say exit_underline
instead of uleo
that the parameter names have been changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, fixed!
* mbtowc(3) returns 0 is not handled here. | ||
*/ | ||
if ((nbytes = mbtowc(&wc, &str[i], MB_CUR_MAX)) == -1) { | ||
mbtowc(NULL, NULL, MB_CUR_MAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for resetting internal state of mbtowc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
Can't reproduce on OpenBSD but I will try it on macOS this evening. |
Thanks @mptre. Let me know if I can help you in any way! |
In an attempt to fix a bug caused by lines including Unicode characters that occupy more than one column. While at it, fix another bug related to the column counter when a line contains more than one escape sequence.
Required by posix_openpt(3) and wcwidth(3) on Linux.
Turns out the passing that specific emoji to OK to merge? |
Interesting. Searching for fixes, I found a lot of tickets and issues discussing this problem and a lot of homegrown solutions special casing certain characters. I'm of the opinion that pick(1) should solve these problems. Looks good to merge. |
Can you create a separate issue and share your findings there?
Done! Thanks for the feedback. Time to release? |
Sure thing! |
In an attempt to fix #184 caused by lines including Unicode characters
that occupy more than one column.
While at it, fix another bug related to the column counter when a line
contains more than one escape sequence.
Reviews and testing would be much appreciated I haven't discovered any
regression nor performance decrease running this diff so far.
/cc @calleerlandsson @mike-burns @teoljungberg.