Skip to content

Commit 2efcbf4

Browse files
committed
Make -stdin the default (Fixes #10), add -no-stdin argument, add --help argument
1 parent 9b61653 commit 2efcbf4

File tree

5 files changed

+83
-30
lines changed

5 files changed

+83
-30
lines changed

README.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ Options:
3030
-linespacing <n> Pad between lines
3131

3232
Flags:
33-
-stdin Read text from stdin
33+
-stdin Deprecated / No-op
34+
-no-stdin Disable text content update via stdin
3435
-windowed Do not force window to fullscreen
3536
-independent-lines Scale lines independently
3637
-debugboxes Draw debug boxes
3738
-disable-text Do not draw text
3839
-disable-doublebuffer What it says on the tin
40+
-h | -help | --help Display usage information
3941
-v[v[v[v]]] Increase verbosity
4042

4143
Where <colorspec> is either an X Color name (blue, red,
@@ -45,13 +47,14 @@ and <alignspec> is one of n|ne|e|se|s|sw|w|nw
4547

4648
Options must be given before a text argument starts.
4749
Command line option parsing can be stopped with --,
48-
eg.: ./xecho -bc blue -fc yellow -- -stdin is cool!
50+
eg.: ./xecho -bc blue -fc yellow -- -help shows usage information
4951

5052
Text passed via the command line is scanned once for
5153
control character encodings (\n and \\), which
5254
are replaced by their ASCII codepoints.
5355

54-
Control characters are handled as follows
56+
By default, xecho reads text from stdin and appends it to the window
57+
content. Control characters on stdin are handled as follows
5558
\n Starts new line
5659
\f Clears display
5760
\r Clears current line
@@ -60,7 +63,7 @@ Control characters are handled as follows
6063
Usage examples:
6164

6265
while :; do printf "\f%s" "`date`" \
63-
&& sleep 1; done | ./xecho -stdin
66+
&& sleep 1; done | ./xecho
6467

6568
Displays the current date updated by every second.
6669
The output of `date` is handled by printf to avoid

arguments.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@ int args_parse(CFG* config, int argc, char** argv){
6060
else if(!strcmp(argv[i], "-windowed")){
6161
config->windowed = true;
6262
}
63+
//this parameter is now a noop and deprecated, but still recognized for compatability reasons
6364
else if(!strcmp(argv[i], "-stdin")){
6465
config->handle_stdin = true;
6566
}
67+
else if(!strcmp(argv[i], "-no-stdin")){
68+
config->handle_stdin = false;
69+
}
6670
else if(!strcmp(argv[i], "-debugboxes")){
6771
config->debug_boxes = true;
6872
}
73+
else if(!strcmp(argv[i], "-help") || !strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")){
74+
config->print_usage = true;
75+
}
6976
else if(!strcmp(argv[i], "-fc")){
7077
if(++i < argc && !(config->text_color)){
7178
if(!arg_copy(&(config->text_color), argv[i])){
@@ -246,6 +253,10 @@ bool args_sane(CFG* config){
246253
fprintf(stderr, "Font name: %s\n", config->font_name);
247254
}
248255

256+
if(config->print_usage){
257+
return false;
258+
}
259+
249260
return true;
250261
}
251262

xecho.1

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
.TH XECHO 1 "September 2015" "v1.0"
1+
.TH XECHO 1 "August 2016" "v1.1"
22

33
.SH NAME
44
xecho \- Render text to simple X Windows
55

66
.SH SYNOPSIS
7-
.BI "xecho [-font " fontspec "] [-title " title "] [-bc " colorspec "] [-fc " colorspec "] "
7+
.BI "xecho [-h | -help | --help] [-font " fontspec "] [-title " title "] [-bc " colorspec "] [-fc " colorspec "] "
88
.BI "[-dc " fontspec "] [-size " size "] [-maxsize " size "] [-align " alignspec "] "
9-
.BI "[-padding " n "] [-linespacing " n "] [-stdin] [-independent-lines] [-debugboxes] "
9+
.BI "[-padding " n "] [-linespacing " n "] [-no-stdin] [-windowed] [-independent-lines] [-debugboxes] "
1010
.BI "[-disable-text] [-disable-doublebuffer] [-v[v[v[v]]]] " text
1111

1212
.SH DESCRIPTION
13-
.BR xecho " takes text from the command line or optionally (with " -stdin ") from the standard"
13+
.BR xecho " takes text from the command line or from the standard"
1414
input and displays it at the largest possible font size in an X11 window.
1515

1616
.SH OPTIONS
@@ -94,25 +94,22 @@ $ xecho -linespacing 50 "There are 50 pixels\enBetween these lines"
9494
.SH FLAGS
9595

9696
.TP
97-
.B -stdin
98-
Read display text from stdin. This mode allows piping external programs to xecho in order
99-
to periodically update the displayed text. The following control characters are interpreted
100-
by this mode
101-
.RS
102-
.BR "\en" " Start new line"
103-
.RE
104-
.RS
105-
.BR "\ef" " Clear display"
106-
.RE
107-
.RS
108-
.BR "\er" " Clear current line"
109-
.RE
110-
.RS
111-
.BR "\eb" " Backspace"
112-
.RE
97+
.B -h | -help | --help
98+
Print usage information.
99+
100+
.TP
101+
.B -stdin
102+
Deprecated / No-op. Reading date from stdin has since become the standard and
103+
this argument is only provided for compatability reasons.
104+
105+
.TP
106+
.B -no-stdin
107+
Disable text content updates from stdin (see
108+
.B STDIN UPDATE PROTOCOL
109+
below for more information)
113110
.RS
114111
.B Example:
115-
$ while :; do printf "\ef%s" "$(date)" && sleep 1; done | xecho -stdin
112+
$ xecho -no-stdin This text can not be updated
116113
.RE
117114

118115
.TP
@@ -128,28 +125,64 @@ $ xecho -independent-lines "This line will be big\enThis line will be comparativ
128125
Draw debug boxes to indicate text bounding boxes.
129126
.RS
130127
.B Example:
131-
$ xecho -debugboxes foo
128+
$ xecho -debugboxes foo
132129
.RE
133130

134131
.TP
135132
.B -disable-text
136133
Do not print text at all. Might be useful for playing tetris.
137134
.RS
138135
.B Example:
139-
$ xecho -disable-text There goes nothing
136+
$ xecho -disable-text There goes nothing
140137
.RE
141138

142139
.TP
143140
.B -disable-doublebuffer
144141
Disable double buffering via the XDBE extension.
142+
.RS
143+
.B Example:
144+
$ xecho -disable-doublebuffer Resizing this window might flicker
145+
.RE
145146

146147
.TP
147148
.B -windowed
148149
Do not try to force full screen display.
150+
.RS
151+
.B Example:
152+
$ xecho -windowed This window can be resized
153+
.RE
149154

150155
.TP
151156
.B -v[v[v[v]]]
152157
Increase log output verbosity.
158+
.RS
159+
.B Example:
160+
$ xecho -vvvv Tell me more!
161+
.RE
162+
163+
.SH STDIN UPDATE PROTOCOL
164+
By default, xecho reads text from stdin and appends it to the window content.
165+
Some control characters are assigned special functions to allow for advanced usage.
166+
.RS
167+
.BR "\en" " Start new line"
168+
.RE
169+
.RS
170+
.BR "\ef" " Clear display"
171+
.RE
172+
.RS
173+
.BR "\er" " Clear current line"
174+
.RE
175+
.RS
176+
.BR "\eb" " Backspace"
177+
.RE
178+
.RS
179+
.B Example:
180+
$ while :; do printf "\ef%s" "$(date)" && sleep 1; done | xecho
181+
.RE
182+
The stdin update facility can be disabled with the
183+
.B -no-stdin
184+
argument.
185+
153186

154187
.SH BUGS
155188
Font size calculation might be slow on old systems.

xecho.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ int usage(char* fn){
44
printf("xecho - Render text to X\n\n");
55
printf("Usage: %s <arguments> <text>\n", fn);
66
printf("Recognized options:\n");
7-
printf("\t--\t\t\t\tStop argument parsing,\n\t\t\t\t\ttreat all following arguments as text\n\n");
7+
printf("\t--\t\t\t\tStop argument parsing,\n\t\t\t\t\ttreat all following arguments as content text\n\n");
88
printf("\t-font <fontspec>\t\tSelect font by FontConfig name\n\n");
99
printf("\t-fc <colorspec>\t\t\tSet text color by name or HTML code\n\n");
1010
printf("\t-bc <colorspec>\t\t\tSet background color by name or code\n\n");
@@ -16,13 +16,17 @@ int usage(char* fn){
1616
printf("\t-padding <n>\t\t\tPad text by n pixels\n\n");
1717
printf("\t-linespacing <n>\t\tPad lines by n pixels\n\n");
1818
printf("Recognized flags:\n");
19-
printf("\t-stdin\t\t\t\tUpdate text from stdin,\n\t\t\t\t\t\\f (Form feed) clears text,\n\t\t\t\t\t\\r (Carriage return) clears current line\n\n");
19+
printf("\t-no-stdin\t\t\tDisable content updates from stdin\n\n");
2020
printf("\t-windowed\t\t\tDo not try to force a fullscreen window\n\n");
2121
printf("\t-independent-lines\t\tResize every line individually\n\n");
2222
printf("\t-debugboxes\t\t\tDraw debug boxes\n\n");
2323
printf("\t-disable-text\t\t\tDo not render text at all.\n\t\t\t\t\tMight be useful for playing tetris.\n\n");
2424
printf("\t-disable-doublebuffer\t\tDo not use XDBE\n\n");
25+
printf("\t-h | -help | --help\t\tPrint this usage information\n\n");
2526
printf("\t-v[v[v]]\t\t\tIncrease output verbosity\n\n");
27+
printf("stdin content update protocol:\n");
28+
printf("\t\\f (Form feed) clears text,\n");
29+
printf("\t\\r (Carriage return) clears current line\n\n");
2630
return 1;
2731
}
2832

@@ -43,11 +47,12 @@ int main(int argc, char** argv){
4347
.max_size = 0,
4448
.alignment = ALIGN_CENTER,
4549
.independent_resize = false,
46-
.handle_stdin = false,
50+
.handle_stdin = true,
4751
.debug_boxes = false,
4852
.disable_text = false,
4953
.double_buffer = true,
5054
.windowed = false,
55+
.print_usage = false,
5156
.force_size = 0,
5257
.text_color = NULL,
5358
.bg_color = NULL,

xecho.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef struct /*_CFG_ARGS*/ {
3535
bool disable_text;
3636
bool double_buffer;
3737
bool windowed;
38+
bool print_usage;
3839
double force_size;
3940
char* text_color;
4041
char* bg_color;

0 commit comments

Comments
 (0)