Giter VIP home page Giter VIP logo

Comments (3)

tomghuang avatar tomghuang commented on July 3, 2024 1

Hi @gbinux , thank you for your suggestion. I'm planning the public interface for the next minor version (3.2.0), and I'll think about this suggestion.

The benefit of the current arg_rem mechanism is that, you can see exactly what the glossary will look like in the source code. Although it's tedious, it can let you control where to wrap your string. When you can see how the wrapped glossary strings look like, you can feel whether it is easy to browse the glossary or not, and you may change words and sentence structure to make them easier to read.

from argtable3.

tomghuang avatar tomghuang commented on July 3, 2024

Hi @gbinux , Argtable3 does have a function, arg_rem, to resolve this issue. For example:

struct arg_lit *update  = arg_litn("u", "update", 0, 1, "copy only when SOURCE files are");
struct arg_rem *update1 = arg_rem(NULL,                 "  newer than destination files");
struct arg_rem *update1 = arg_rem(NULL,                 "  or when destination files");
struct arg_rem *update2 = arg_rem(NULL,                 "  are missing");

The example above will generate the following glossary:

-u, --update                   copy only when SOURCE files are
                                 newer than destination files
                                 or when the destination files
                                 are missing

from argtable3.

bguo068 avatar bguo068 commented on July 3, 2024

Thanks for the reply @tomghuang . I understand that arg_remcan help manually wrap the text and it might take some efforts to do it for every option. I was thinking about a function that can automatically wap the long string according to a specified width. For example,

/*
 * indent1 for the first line
 * indent2 for the following lines
 * width for the maximum text width
 */

int
fprint_wrap(FILE *file, const char *str, int indent1, int indent2, int width)
{
    int str_len;
    char *buf, *p1, *p2, *end, tmp_char;
    int indent, lineno;

    /* make a copy */
    str_len = strlen(str);
    buf = malloc(sizeof(*buf) * (str_len + 1));
    memcpy(buf, str, str_len + 1);

    p1 = p2 = buf;
    end = buf + str_len;
    lineno = -1;
    while (p1 < end) {
        lineno++;
        indent = lineno > 0 ? indent2 : indent1;
        while (p2 < end && p2 < p1 + width - indent && *p2 != '\n') {
            p2++;
        }
        if (*p2 == '\n') {
            *p2 = '\0';
            fprintf(stdout, "%*s %s\n", -indent, "", p1);
            p2++;
            p1 = p2;
        } else if (p2 == end) {
            fprintf(stdout, "%*s %s\n", -indent, "", p1);
            p1 = end;
        } else {
            while (*p2 != ' ' && p2 > p1) {
                p2--;
            }
            if (*p2 == ' ') {
                *p2 = '\0';
                fprintf(stdout, "%*s %s\n", -indent, "", p1);
                p2++;
                p1 = p2;
            } else if (p2 == p1) {
                p2 = p1 + width;
                tmp_char = *p2;
                *p2 = '\0';
                fprintf(stdout, "%*s %s\n", -indent, "", p1);
                *p2 = tmp_char;
                p1 = p2;
            }
        }
    }

    free(buf);
    return 0;
}

from argtable3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.