Skip to content

getopts should use grapheme clusters for text alignment  #5516

Closed
@Kimundi

Description

@Kimundi
Member

It should at minimum align to number of codepoints (characters), (and now that PR #8710 has landed, it should be doing that minimum), but the only correct thing would be to align to grapheme clusters.

test case

extern mod extra;
use extra::getopts::groups;

fn main() {
    let optgroups = ~[
        groups::optflag("a", "apple",        "apple description"),
        groups::optflag("b", "banana\u00AB", "banana description"),
        groups::optflag("c", "br\xfbl\xe9e", "br\xfbl\xe9e quite long description"),
        groups::optflag("k", "kiwi\u20AC",   "kiwi description"),
        groups::optflag("o", "orange\u2039", "orange description"),
        groups::optflag("r",
                        "raspberry-but-making-this-option-way-too-long",
                        "raspberry description is also quite long indeed longer than every other piece of text we might encounter here and thus will be automatically broken up"),
    ];
    println(usage("Usage: fruits", optgroups));
}

current output:

% rustc /tmp/issue5516.rs && /tmp/issue5516 --help
warning: no debug symbols in executable (-arch x86_64)
Usage: fruits

Options:
    -a --apple          apple description
    -b --banana«        banana description
    -c --brûlée         brûlée quite long descripti
    -k --kiwi€          kiwi description
    -o --orange‹        orange description
    -r --raspberry-but-making-this-option-way-too-long 
                        raspberry description is also quite long indeed longer
                        than every other piece of text we might encounter here
                        and thus will be automatically broken up


Note that in addition to things failing to line up, it is also cutting off the end of the text for the brûlée case. That issue should also be fixed.

Activity

catamorphism

catamorphism commented on May 23, 2013

@catamorphism
Contributor

Nominating for milestone 5, production-ready

graydon

graydon commented on May 23, 2013

@graydon
Contributor

just a bug, removing milestone/nomination.

pnkfelix

pnkfelix commented on Aug 23, 2013

@pnkfelix
Member

Visiting for triage, email from 2013-08-19

The grapheme-oriented solution is blocked on #7043.

But we can at least put in the codepoint-oriented solution for the time being.

added a commit that references this issue on Aug 25, 2013

auto merge of #8710 : pnkfelix/rust/fsk-issue5516-codepoint-fix, r=al…

pnkfelix

pnkfelix commented on Nov 22, 2013

@pnkfelix
Member

(updating description to reflect PR #8710.)

emberian

emberian commented on Jul 29, 2014

@emberian
Member

With the advent of libunicode this would presumably be a lot easier!

emberian

emberian commented on Jul 29, 2014

@emberian
Member

It's also possible that we want to get rid of getops and replace it with docopt.

changed the title [-]extra::getopts should use grapheme clusters for text alignment [/-] [+]getopts should use grapheme clusters for text alignment [/+] on Jul 29, 2014
bluss

bluss commented on Jul 29, 2014

@bluss
Member

Note that graphemes don't tell you the display width of text. There is a rudimentary codepoint-oriented width function in libunicode though.

steveklabnik

steveklabnik commented on Jan 21, 2015

@steveklabnik
Member

This issue has been moved to the getopts repo: rust-lang/getopts#7

5 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @graydon@steveklabnik@pnkfelix@catamorphism@emberian

        Issue actions

          getopts should use grapheme clusters for text alignment · Issue #5516 · rust-lang/rust