{"id":230,"date":"2011-06-17T00:07:34","date_gmt":"2011-06-16T15:07:34","guid":{"rendered":"http:\/\/daily.belltail.jp\/?p=230"},"modified":"2011-06-17T00:18:40","modified_gmt":"2011-06-16T15:18:40","slug":"%e6%a8%99%e6%ba%96%e5%85%a5%e5%87%ba%e5%8a%9b%e5%85%88%e3%81%8c%e5%ae%9f%e9%9a%9b%e3%81%ab%e3%81%af%e7%ab%af%e6%9c%ab%e3%81%aa%e3%81%ae%e3%81%8b%e3%82%92%e8%aa%bf%e3%81%b9%e3%82%8b%e3%81%ab%e3%81%af","status":"publish","type":"post","link":"https:\/\/daily.belltail.jp\/?p=230","title":{"rendered":"\u6a19\u6e96\u5165\u51fa\u529b\u5148\u304c\u5b9f\u969b\u306b\u306f\u7aef\u672b\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u308b\u306b\u306f"},"content":{"rendered":"<p>\u624b\u629c\u304d\u8a18\u4e8b\u3067\u3059\uff0e<br \/>\n\u3068\u3044\u3046\u304b\u3053\u3063\u3061\u306f\u30b5\u30d6\u30d6\u30ed\u30b0\u306a\u306e\u3067\u5e73\u5e38\u904b\u8ee2\u304c\u3053\u308c\u3067\u306a\u3044\u3068\u3044\u304b\u3093\u306e\u3067\u3059\u304c\uff0e<\/p>\n<p>\u3055\u3066\uff0c\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u304a\u3044\u3066\uff0c\u6a19\u6e96\u5165\u529b\u30fb\u6a19\u6e96\u51fa\u529b\u30fb\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u304c\u305d\u308c\u305e\u308c\u7aef\u672b\u304b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u307e\u305f\u306f\u30d1\u30a4\u30d7\u3055\u308c\u3066\u5225\u306e\u30d5\u30a1\u30a4\u30eb\u307e\u305f\u306f\u30d7\u30ed\u30bb\u30b9\u306b\u6e21\u3055\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u305f\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\uff0e<\/p>\n<p>\u4eca\u65e5\u306f\u305d\u306e\u65b9\u6cd5\u3092\uff0e<\/p>\n<p><!--more--><\/p>\n<p>*\u305d\u3082\u305d\u3082\u306a\u3093\u3067\u305d\u3093\u306a\u3053\u3068\u3057\u305f\u3044\u304b<\/p>\n<p>POSIX\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u306b\u3088\u3063\u3066\u7aef\u672b\u306b\u51fa\u529b\u3059\u308b\u6587\u5b57\u306e\u8272\u3092\u9069\u5f53\u306b\u5909\u3048\u3066\u307f\u307e\u3057\u3087\u3046\uff0e<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;string&gt;\r\n#include &lt;boost\/format.hpp&gt;\r\n\r\nstd::string gen(int col)\r\n{\r\n  static const char esc = 0x1b;\r\n  return (boost::format(&quot;%c&#x5B;%dm&quot;) % esc % col).str();\r\n}\r\n\r\nint main()\r\n{\r\n  std::cout &lt;&lt; gen(31);\r\n  std::cout &lt;&lt; &quot;hoge&quot; &lt;&lt; std::endl;\r\n}\r\n<\/pre>\n<p>\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u81ea\u4f53\u306f\u672c\u8cea\u7684\u3058\u3083\u306a\u3044\u306e\u3067\u8aac\u660e\u306f\u4ed6\u306b\u8b72\u308b\u3068\u3057\u3066\uff0e<\/p>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\uff0c\u8d64\u6587\u5b57\u3067hoge\u3068\u51fa\u529b\u3055\u308c\u307e\u3059\uff0e\u2229( \u30fb\u03c9\u30fb)\u2229\u3084\u3063\u305f\u306d<\/p>\n<p>\u3067\u3082\u3053\u3046\u3059\u308b\u3068\u2026<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n% .\/a.out &gt; out.txt\r\n% less out.txt\r\n<\/pre>\n<p>less\u3067\u8868\u793a\u3055\u308c\u308b\u6587\u5b57\u5217\u306f\u306a\u306b\u3084\u3089\u30d8\u30f3\u3067\u3059\uff0e<br \/>\n\u305d\u3046\uff0c\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u5148\u30d5\u30a1\u30a4\u30eb\u306b\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u307e\u3067\u51fa\u529b\u3055\u308c\u3066\u3057\u307e\u3046\u304b\u3089\u3067\u3059\uff0e<\/p>\n<p>\u3061\u306a\u307f\u306bless\u3058\u3083\u306a\u304fcat\u3067\u51fa\u3059\u3068\uff0c\u8272\u304c\u3061\u3083\u3093\u3068\u3064\u3044\u3066\u8868\u793a\u3055\u308c\u307e\u3059\uff0e\u4f55\u3082\u8003\u3048\u3066\u306a\u304b\u3063\u305f\u3089\uff0c\u5168\u304f\u3082\u3063\u3066\u671f\u5f85\u901a\u308a\u3060\u3068\u30b9\u30eb\u30fc\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u306d\uff0e<\/p>\n<p>\u3067\uff0c\u3053\u308c\u3067\u306f\u56f0\u308b\u306e\u3067\uff0c\u5b9f\u884c\u6642\u306b\u6a19\u6e96\u5165\u51fa\u529b\u5148\u304c\u7aef\u672b\u304b\u305d\u308c\u4ee5\u5916\u304b\u8abf\u3079\u3066\u305d\u308c\u306b\u5fdc\u3058\u3066\u51fa\u529b\u6587\u5b57\u5217\u3092\u5909\u3048\u307e\u3057\u3087\u3046\uff0e<\/p>\n<p>\u3053\u308c\u306f\uff0c\u4f8b\u3048\u3070\u6a19\u6e96\u30b3\u30de\u30f3\u30c9\u306els\u306a\u3093\u304b\u3067\u666e\u901a\u306b\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\uff0e<\/p>\n<p>*\u3068\u3044\u3046\u3053\u3068\u3067\u3084\u308a\u65b9<\/p>\n<p>\u7d30\u304b\u304f\u8aac\u660e\u3059\u308b\u5fc5\u8981\u306f\u307e\u3063\u3063\u3063\u305f\u304f\u7121\u3044\u3067\u3059\uff0e\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3067\u4e00\u767a\u3067\u3059\uff0e<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;unistd.h&gt;\r\n\r\nint main()\r\n{\r\n  const bool stdin_console = isatty(STDIN_FILENO);\r\n  const bool stdout_console = isatty(STDOUT_FILENO);\r\n  const bool stderr_console = isatty(STDERR_FILENO);\r\n\r\n  std::cout &lt;&lt; &quot;stdin-&gt;&quot; &lt;&lt; (stdin_console ? &quot;&quot; : &quot; not&quot;) &lt;&lt; &quot; terminal&quot; &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; &quot;stdout-&gt;&quot; &lt;&lt; (stdout_console ? &quot;&quot; : &quot; not&quot;) &lt;&lt; &quot; terminal&quot; &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; &quot;stderr-&gt;&quot; &lt;&lt; (stderr_console ? &quot;&quot; : &quot; not&quot;) &lt;&lt; &quot; terminal&quot; &lt;&lt; std::endl;\r\n}\r\n<\/pre>\n<p>\u306f\u3044\uff0c\u3053\u308c\u3060\u3051\u3067\u3059\uff0e<\/p>\n<p>\u305d\u3093\u306a\u304b\u3093\u3058\u3067\u3055\u3063\u304d\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304d\u63db\u3048\u308b\u306a\u3089\uff0c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;string&gt;\r\n#include &lt;unistd.h&gt;\r\n#include &lt;boost\/format.hpp&gt;\r\n#include &lt;boost\/optional.hpp&gt;\r\n\r\nstd::string gen(int col)\r\n{\r\n  static const char esc = 0x1b;\r\n  static boost::optional&lt;bool&gt; is_atty;\r\n  if(!is_atty)\r\n    is_atty = isatty(STDOUT_FILENO);\r\n\r\n  if(!*is_atty)\r\n    return std::string();\r\n  return (boost::format(&quot;%c&#x5B;%dm&quot;) % esc % col).str();\r\n}\r\n\r\nint main()\r\n{\r\n  std::cout &lt;&lt; gen(31);\r\n  std::cout &lt;&lt; &quot;hoge&quot; &lt;&lt; std::endl;\r\n}\r\n<\/pre>\n<p>\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3067\u3059\u3057\u6bce\u56de\u547c\u3076\u306e\u306f\u30a2\u30ec\u306a\u306e\u3067is_atty\u306bisatty\u3057\u305f\u7d50\u679c\u3092\u5165\u308c\u3068\u304d\u307e\u3059\uff0e<br \/>\n\u6700\u521d\u3060\u3051\u306f\u3061\u3083\u3093\u3068\u5224\u5b9a\u3059\u308b\u3088\u3046\u306boptional\u306b\u5165\u308c\u3066\u307e\u3059\uff0e<\/p>\n<p>\u3053\u306e\u65b9\u6cd5\u3067\uff0c\u7aef\u672b\u306e\u6642\u3068\u305d\u3046\u3067\u306a\u3044\u6642\u3067\u81ea\u7531\u306b\u51fa\u529b\u3092\u3044\u3058\u308c\u307e\u3059\uff0e<\/p>\n<p>\u305d\u3046\u306f\u8a00\u3063\u3066\u3082\uff0c\u51fa\u529b\u306e\u5f62\u5f0f\u3092\u3044\u3058\u308b\u3053\u3068\u306f\u3042\u3063\u3066\u3082\u51fa\u529b\u306e\u5185\u5bb9\u81ea\u4f53\u3092\u3044\u3058\u308b\u3053\u3068\u306f\u3042\u307e\u308a\u8ce2\u660e\u3067\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\uff0e<br \/>\n\u307e\u3055\u306bls\u30b3\u30de\u30f3\u30c9\u3067\u306e\u4f7f\u3044\u65b9\u304c\u3074\u3063\u305f\u308a\u3067\u3057\u3087\u3046\uff0e<\/p>\n<p>#\u3066\u304b\u4e0a\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3063\u3066\u305f\u3076\u3093\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3058\u3083\u306a\u3044\u3067\u3059\u306d\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u624b\u629c\u304d\u8a18\u4e8b\u3067\u3059\uff0e \u3068\u3044\u3046\u304b\u3053\u3063\u3061\u306f\u30b5\u30d6\u30d6\u30ed\u30b0\u306a\u306e\u3067\u5e73\u5e38\u904b\u8ee2\u304c\u3053\u308c\u3067\u306a\u3044\u3068\u3044\u304b\u3093\u306e\u3067\u3059\u304c\uff0e \u3055\u3066\uff0c\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u304a\u3044\u3066\uff0c\u6a19\u6e96\u5165\u529b\u30fb\u6a19\u6e96\u51fa\u529b\u30fb\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u304c\u305d\u308c\u305e\u308c\u7aef\u672b\u304b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u307e\u305f\u306f\u30d1\u30a4\u30d7\u3055\u308c\u3066\u5225\u306e\u30d5\u30a1\u30a4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-1","tag-linux"],"_links":{"self":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":0,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"wp:attachment":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}