diff --git a/README.txt b/README.txt index 17f5152..e32ebce 100644 --- a/README.txt +++ b/README.txt @@ -30,12 +30,14 @@ Options: -linespacing 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 is either an X Color name (blue, red, @@ -45,13 +47,14 @@ and 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 @@ -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 diff --git a/arguments.c b/arguments.c index d817b7d..92148db 100644 --- a/arguments.c +++ b/arguments.c @@ -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])){ @@ -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; } diff --git a/xecho.1 b/xecho.1 index de4b28c..5cb0af6 100644 --- a/xecho.1 +++ b/xecho.1 @@ -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 @@ -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 @@ -128,7 +125,7 @@ $ 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 @@ -136,20 +133,56 @@ $ xecho -debugboxes foo 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. diff --git a/xecho.c b/xecho.c index 71959a6..08420bb 100644 --- a/xecho.c +++ b/xecho.c @@ -4,7 +4,7 @@ int usage(char* fn){ printf("xecho - Render text to X\n\n"); printf("Usage: %s \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 \t\tSelect font by FontConfig name\n\n"); printf("\t-fc \t\t\tSet text color by name or HTML code\n\n"); printf("\t-bc \t\t\tSet background color by name or code\n\n"); @@ -16,13 +16,17 @@ int usage(char* fn){ printf("\t-padding \t\t\tPad text by n pixels\n\n"); printf("\t-linespacing \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; } @@ -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, diff --git a/xecho.h b/xecho.h index 87cbe78..e0b1a36 100644 --- a/xecho.h +++ b/xecho.h @@ -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;