summaryrefslogtreecommitdiff
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
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.
-rw-r--r--res/style.css16
-rw-r--r--src/linux_development:detecting_output_type.ascii44
2 files changed, 49 insertions, 11 deletions
diff --git a/res/style.css b/res/style.css
index 9f89119..0a11dfb 100644
--- a/res/style.css
+++ b/res/style.css
@@ -219,18 +219,28 @@ dl {
padding:10px 0px;
}
-div.terminal div pre {
+div.terminal div {
display:block;
padding:5px;
margin:5px 0px;
- font-family: Monospace;
background-color:#222;
- color:#ddd;
border:1px solid #999;
border-radius:5px;
overflow:auto;
}
+div.terminal div pre,
+div.terminal div div.paragraph,
+div.terminal div div.paragraph p {
+ font-family: monospace;
+ background:none;
+ padding:0px;
+ margin:0px 0px;
+ border:none;
+ overflow:auto;
+ color:#ddd;
+}
+
ul li p {
line-height:1.2em;
margin-top:5px;
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