Chomp last punctuations from descriptions for `-h`

The following parts will not be shown for `-h` option.  And not to
reach 80 columns.  Some terminal emulators (Windows command prompt at
least) wrap the cursor to the next line when reaching the rightmost
column, before exceeding.
This commit is contained in:
Nobuyoshi Nakada 2024-03-13 12:00:38 +09:00
Родитель a05dfbd405
Коммит c843afbf6f
2 изменённых файлов: 4 добавлений и 3 удалений

1
ruby.c
Просмотреть файл

@ -254,6 +254,7 @@ show_usage_part(const char *str, const unsigned int namelen,
const char *sb = highlight ? esc_bold : esc_none;
const char *se = highlight ? esc_reset : esc_none;
unsigned int desclen = (unsigned int)strcspn(desc, "\n");
if (!help && desclen > 0 && strchr(".;:", desc[desclen-1])) --desclen;
if (help && (namelen + 1 > w) && /* a padding space */
(int)(namelen + secondlen + indent_width) >= columns) {
printf(USAGE_INDENT "%s" "%.*s" "%s\n", sb, namelen, str, se);

Просмотреть файл

@ -46,7 +46,7 @@ class TestRubyOptions < Test::Unit::TestCase
def test_usage
assert_in_out_err(%w(-h)) do |r, e|
assert_operator(r.size, :<=, 25)
longer = r[1..-1].select {|x| x.size > 80}
longer = r[1..-1].select {|x| x.size >= 80}
assert_equal([], longer)
assert_equal([], e)
end