Skip to content

Commit

Permalink
Make -stdin the default (Fixes #10), add -no-stdin argument, add --he…
Browse files Browse the repository at this point in the history
…lp argument
  • Loading branch information
cbdevnet committed Aug 16, 2016
1 parent 9b61653 commit 2efcbf4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 30 deletions.
11 changes: 7 additions & 4 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ Options:
-linespacing <n> Pad between lines

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

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

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

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

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

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

Displays the current date updated by every second.
The output of `date` is handled by printf to avoid
Expand Down
11 changes: 11 additions & 0 deletions arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ int args_parse(CFG* config, int argc, char** argv){
else if(!strcmp(argv[i], "-windowed")){
config->windowed = true;
}
//this parameter is now a noop and deprecated, but still recognized for compatability reasons
else if(!strcmp(argv[i], "-stdin")){
config->handle_stdin = true;
}
else if(!strcmp(argv[i], "-no-stdin")){
config->handle_stdin = false;
}
else if(!strcmp(argv[i], "-debugboxes")){
config->debug_boxes = true;
}
else if(!strcmp(argv[i], "-help") || !strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")){
config->print_usage = true;
}
else if(!strcmp(argv[i], "-fc")){
if(++i < argc && !(config->text_color)){
if(!arg_copy(&(config->text_color), argv[i])){
Expand Down Expand Up @@ -246,6 +253,10 @@ bool args_sane(CFG* config){
fprintf(stderr, "Font name: %s\n", config->font_name);
}

if(config->print_usage){
return false;
}

return true;
}

Expand Down
79 changes: 56 additions & 23 deletions xecho.1
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.TH XECHO 1 "September 2015" "v1.0"
.TH XECHO 1 "August 2016" "v1.1"

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

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

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

.SH OPTIONS
Expand Down Expand Up @@ -94,25 +94,22 @@ $ xecho -linespacing 50 "There are 50 pixels\enBetween these lines"
.SH FLAGS

.TP
.B -stdin
Read display text from stdin. This mode allows piping external programs to xecho in order
to periodically update the displayed text. The following control characters are interpreted
by this mode
.RS
.BR "\en" " Start new line"
.RE
.RS
.BR "\ef" " Clear display"
.RE
.RS
.BR "\er" " Clear current line"
.RE
.RS
.BR "\eb" " Backspace"
.RE
.B -h | -help | --help
Print usage information.

.TP
.B -stdin
Deprecated / No-op. Reading date from stdin has since become the standard and
this argument is only provided for compatability reasons.

.TP
.B -no-stdin
Disable text content updates from stdin (see
.B STDIN UPDATE PROTOCOL
below for more information)
.RS
.B Example:
$ while :; do printf "\ef%s" "$(date)" && sleep 1; done | xecho -stdin
$ xecho -no-stdin This text can not be updated
.RE

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

.TP
.B -disable-text
Do not print text at all. Might be useful for playing tetris.
.RS
.B Example:
$ xecho -disable-text There goes nothing
$ xecho -disable-text There goes nothing
.RE

.TP
.B -disable-doublebuffer
Disable double buffering via the XDBE extension.
.RS
.B Example:
$ xecho -disable-doublebuffer Resizing this window might flicker
.RE

.TP
.B -windowed
Do not try to force full screen display.
.RS
.B Example:
$ xecho -windowed This window can be resized
.RE

.TP
.B -v[v[v[v]]]
Increase log output verbosity.
.RS
.B Example:
$ xecho -vvvv Tell me more!
.RE

.SH STDIN UPDATE PROTOCOL
By default, xecho reads text from stdin and appends it to the window content.
Some control characters are assigned special functions to allow for advanced usage.
.RS
.BR "\en" " Start new line"
.RE
.RS
.BR "\ef" " Clear display"
.RE
.RS
.BR "\er" " Clear current line"
.RE
.RS
.BR "\eb" " Backspace"
.RE
.RS
.B Example:
$ while :; do printf "\ef%s" "$(date)" && sleep 1; done | xecho
.RE
The stdin update facility can be disabled with the
.B -no-stdin
argument.


.SH BUGS
Font size calculation might be slow on old systems.
Expand Down
11 changes: 8 additions & 3 deletions xecho.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ int usage(char* fn){
printf("xecho - Render text to X\n\n");
printf("Usage: %s <arguments> <text>\n", fn);
printf("Recognized options:\n");
printf("\t--\t\t\t\tStop argument parsing,\n\t\t\t\t\ttreat all following arguments as text\n\n");
printf("\t--\t\t\t\tStop argument parsing,\n\t\t\t\t\ttreat all following arguments as content text\n\n");
printf("\t-font <fontspec>\t\tSelect font by FontConfig name\n\n");
printf("\t-fc <colorspec>\t\t\tSet text color by name or HTML code\n\n");
printf("\t-bc <colorspec>\t\t\tSet background color by name or code\n\n");
Expand All @@ -16,13 +16,17 @@ int usage(char* fn){
printf("\t-padding <n>\t\t\tPad text by n pixels\n\n");
printf("\t-linespacing <n>\t\tPad lines by n pixels\n\n");
printf("Recognized flags:\n");
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");
printf("\t-no-stdin\t\t\tDisable content updates from stdin\n\n");
printf("\t-windowed\t\t\tDo not try to force a fullscreen window\n\n");
printf("\t-independent-lines\t\tResize every line individually\n\n");
printf("\t-debugboxes\t\t\tDraw debug boxes\n\n");
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");
printf("\t-disable-doublebuffer\t\tDo not use XDBE\n\n");
printf("\t-h | -help | --help\t\tPrint this usage information\n\n");
printf("\t-v[v[v]]\t\t\tIncrease output verbosity\n\n");
printf("stdin content update protocol:\n");
printf("\t\\f (Form feed) clears text,\n");
printf("\t\\r (Carriage return) clears current line\n\n");
return 1;
}

Expand All @@ -43,11 +47,12 @@ int main(int argc, char** argv){
.max_size = 0,
.alignment = ALIGN_CENTER,
.independent_resize = false,
.handle_stdin = false,
.handle_stdin = true,
.debug_boxes = false,
.disable_text = false,
.double_buffer = true,
.windowed = false,
.print_usage = false,
.force_size = 0,
.text_color = NULL,
.bg_color = NULL,
Expand Down
1 change: 1 addition & 0 deletions xecho.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct /*_CFG_ARGS*/ {
bool disable_text;
bool double_buffer;
bool windowed;
bool print_usage;
double force_size;
char* text_color;
char* bg_color;
Expand Down

0 comments on commit 2efcbf4

Please sign in to comment.