summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2016-08-03 08:41:21 -0600
committerAaron Ball <nullspoon@iohq.net>2016-08-03 08:59:14 -0600
commit4807d2e3c9fbfe76e27a4b6055b13a6392a9f6a5 (patch)
tree06a65fbea618b3769928329d0dbfd7bd92e2cdee /src
parentc1bd149921cded771e47bd5ffe6bc1782bbe9021 (diff)
downloadoper.io-4807d2e3c9fbfe76e27a4b6055b13a6392a9f6a5.tar.gz
oper.io-4807d2e3c9fbfe76e27a4b6055b13a6392a9f6a5.tar.xz
Linux Dev:Detecting output type
More work. Also updated style.css to support terminal styles for paragraphs as well as pre.
Diffstat (limited to 'src')
-rw-r--r--src/linux_development:detecting_output_type.ascii44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/linux_development:detecting_output_type.ascii b/src/linux_development:detecting_output_type.ascii
index a2954ec..792ee3d 100644
--- a/src/linux_development:detecting_output_type.ascii
+++ b/src/linux_development:detecting_output_type.ascii
@@ -19,19 +19,21 @@ For example, a script like this...
----
#!/usr/bin/env bash
-echo -e "[\e[32mINFO\e[0m] This is a useful info message."
-echo -e "[\e[33mWARN\e[0m] This is an ominous warning message."
-echo -e "[\e[31mERROR\e[0m] This is a scary error message."
+echo -e "[ \e[32mINFO\e[0m ] This is a useful info message."
+echo -e "[ \e[33mWARN\e[0m ] This is an ominous warning message."
+echo -e "[ \e[31mERROR\e[0m ] This is a scary error message."
----
Outputs something like this in the terminal
[role="terminal"]
-____
-\[[green]#INFO#] This is a useful info message.
-\[[yellow]#WARN#] This is an ominous warning message.
-\[[red]#ERROR#] This is a scary error message.
-____
+====
+[ [green]#INFO# ] This is a useful info message.
+
+[ [yellow]#WARN# ] This is an ominous warning message.
+
+[ [red]#ERROR# ] This is a scary error message.
+====
...But something like this when piped to less
@@ -44,6 +46,32 @@ ____
----
+As you can see, the escape codes are sent verbatim to the program on the other
+side of the pipe. If it doesn't properly render them by default (which newer
+versions of gnu less do now), you'll see those escape codes on your output.
+This is particularly annoying in the cases of log files. The same behavior
+comes out if the output stream is redirected into a file.
+
+So how do we detect that the end user has redirected output with a pipe or a
+redirection so we can remove the escape codes and just ouput plain text?
+
+
+The Solution
+------------
+
+Bash provides this really useful 'if switch', *-t*. From the bash man page...
+
+[quote, Bash(1)]
+____
+ -t fd True if file descriptor fd is open and refers to a terminal.
+____
+
+Let's give this a try.
+
+
+
+
+
:revdate: June 29, 2016
[role="datelastedit"]

Generated by cgit