Comments (3)
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.
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.
Thanks for the reply @tomghuang . I understand that arg_rem
can 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)
- Provide an option to use getopt_long_only
- Missing some information about the differences between v2 and v3 HOT 1
- When to release the new version? HOT 2
- Implicit declaration of getenv_s() HOT 4
- https issues on https://argtable.org/ - https://www.argtable.org/ fine HOT 1
- Add doc/examples to explain how to implement sub-commands
- Enhance CMake scripts to take advantage of vcpkg's manifest mechanism HOT 2
- clang vs gcc attributes HOT 3
- Static analyser: NULL pointer passing. HOT 3
- Use CodeQL to scan security vulnerabilities
- Table entries with empty glossary strings may displayed. HOT 2
- What is the recommended way to get all the args that have not been matched HOT 2
- index out of bound HOT 1
- arg_print_formatted_ds does not reset column count when reaching newline HOT 2
- Minus symbol stripped from negative numbers HOT 2
- Missing include install path in CMake config export HOT 2
- CMake not including header on static build HOT 1
- `-Wpedantic` should be used conditonally on GCC version HOT 7
- Add project to meson WrapDB HOT 6
- Expose arg_basename function as part of the API HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argtable3.