色つきテキストを、コマンド・ラインから.rtfに保存する?
iPhone 5s, OS X Yosemite (10.10.5), Mac mini(mid 2011), iMac(late 2009)
iPhone 5s, OS X Yosemite (10.10.5), Mac mini(mid 2011), iMac(late 2009)
はい、当面はrgb直接指定でトライします。泥沼の恐れもありそうです。
後者のスクリプトを動かしてみました。
ターミナルに出た後で、QuickLookが立ち上がらず、カーソル点滅で止まっています。
^Cで抜けた後で、/tmpをみると、quicklook_x...x.htmlが出来ています。
% qlmanage -p quicklook_pJiDqM.html 10:20:06 Testing Quick Look preview with files:
quicklook_pJiDqM.html
2016-04-04 10:21:01.276 qlmanage[933:52891] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x9303, name = 'com.apple.CFPasteboardClient'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2016-04-04 10:21:01.276 qlmanage[933:52891] Failed to allocate communication port for com.apple.CFPasteboardClient; this is likely due to sandbox restrictions
Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: conn 0x2b233 token 0x1ffffffffffe85
Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: Backtrace (at 9480.69):
Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 0 CoreGraphics 0x00007fff945de261 CGSBacktraceCreate + 59 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 1 CoreGraphics 0x00007fff94632ff4 _ZN16CGSUpdateManager14disable_updateEv + 84 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 2 AppKit 0x00007fff8ca24d15 -[NSWindow disableScreenUpdatesUntilFlush] + 127 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 3 AppKit 0x00007fff8ca2395a -[NSView(NSInternal) geometryInWindowDidChange] + 185 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 4 AppKit 0x00007fff8ca23581 -[NSView _invalidateFocus] + 437 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 5 AppKit 0x00007fff8ca40e67 -[NSView setFrameSize:] + 1735 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 6 AppKit 0x00007fff8ca3ff83 -[NSView setFrame:] + 464 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 7 AppKit 0x00007fff8caac17f -[NSView resizeWithOldSuperviewSize:] + 694 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 8 AppKit 0x00007fff8caaaacc -[NSView resizeSubviewsWithOldSize:] + 317 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 9 AppKit 0x00007fff8ca42002 NSViewLevelLayout + 165 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 10 AppKit 0x00007fff8cbb30b4 -[NSView _layoutSubtreeWithOldSize:] + 373 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 11 AppKit 0x00007fff8cbb3305 -[NSView _layoutSubtreeWithOldSize:] + 966 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 12 AppKit 0x00007fff8cbb3305 -[NSView _layoutSubtreeWithOldSize:] + 966 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 13 AppKit 0x00007fff8cbb2d60 -[NSView layoutSubtreeIfNeeded] + 885 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 14 AppKit 0x00007fff8cbb28ba _NSViewLayoutSubtreesThatUseAutolayoutIfNeeded + 71 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 15 AppKit 0x00007fff8cbb2841 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 84 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 16 AppKit 0x00007fff8cbd1d3d -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 246 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 17 AppKit 0x00007fff8ca7652e _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 612 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 18 AppKit 0x00007fff8d1ac171 __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke1540 + 46 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 19 CoreFoundation 0x00007fff8a2dc127 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 20 CoreFoundation 0x00007fff8a2dc080 __CFRunLoopDoObservers + 368 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 21 CoreFoundation 0x00007fff8a2ce188 __CFRunLoopRun + 872 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 22 CoreFoundation 0x00007fff8a2cdbd8 CFRunLoopRunSpecific + 296 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 23 QuickLookUI 0x00007fff8c123b20 -[QLPreviewView _startTimeOut] + 189 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 24 QuickLookUI 0x00007fff8c12398f -[QLPreviewView _startLoadingDocumentWithTimeoutDate:] + 674 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 25 QuickLookUI 0x00007fff8c10617e -[QLPreviewPanelController _setCurrentPreviewItem:withTransition:blocking:] + 289 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 26 QuickLookUI 0x00007fff8c1058b3 -[QLPreviewPanelController _refreshLayoutAndContentBlocking:] + 250 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 27 QuickLookUI 0x00007fff8c106f59 -[QLPreviewPanelController willOpen] + 734 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 28 QuickLookUI 0x00007fff8c0fd93c -[QLPreviewPanel _openWithEffect:willOpen:toFullscreen:] + 897 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 29 qlmanage 0x000000010488cea6 qlmanage + 155302 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 30 qlmanage 0x000000010486c48f qlmanage + 21647 Apr 4 10:21:16 MmM11.local qlmanage[933] <Warning>: void CGSUpdateManager::log() const: 31 libdyld.dylib 0x00007fff88a0f5c9 start + 1
とりあえずは、TextEditベースで作業します。
sandbox がどうのこうのと云っていますね。つまり、OS X 10.7 以降では qlmanage は使えないということですかね。これについてどう対処できるのか、私には判りません。
qlmanage sandbox でググったところ、幾つかそれらしいのがヒットして、QLEnableTextSelection を有効にする事が OS X 10.9 等で問題を引き起こしているようです。
その場合の対処法は、以下のコマンドで QLEnableTextSelection を無効にする事です。
defaults delete com.apple.finder QLEnableTextSelection killall Finder
chandanaさんによると:
OS X 10.7 以降では qlmanage は使えないということですかね。
少なくとも、近くにあった.rtfはqlmanageで開けました。また「man qimanage」も存在しています。当方、「Yosemite 10.10.5」です。
以下のコマンドで QLEnableTextSelection を無効にする事です。
何度も「delete, write」を繰り返しましたがダメでした。当面はqlmanageはお預けにします。お手数をおかけして申し訳なく思います。
QLEnableTextSelection を delete しても効かないが、 false に設定すれば直る、という報告もありますね。
#!/bin/bash defaults write com.apple.finder QLEnableTextSelection -bool false killall Finder qlmanage -r
さらにだめ押しで、ログアウト又はリスタートですかね。
よく判りませんが、ご参考までに。
chandanaさんによると:
QLEnableTextSelection を delete しても効かないが、 false に設定すれば直る、という報告もありますね。
#!/bin/bash defaults write com.apple.finder QLEnableTextSelection -bool false killall Finder qlmanage -r
さらにだめ押しで、ログアウト又はリスタートですかね。
やはりダメした。
自分でもエラーメッセージの最初の2行だけを眺めてみました。ただし、見易さのために行間に空行をいれました。
2016-04-04 22:31:34.211 qlmanage[1795:600300] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x8c03, name = 'com.apple.CFPasteboardClient'
See /usr/include/servers/bootstrap_defs.h for the error codes.
こんなところに 'com.apple.CFPasteboardClient'が出てくるのかとおどろきました。
で「 failed 1100 」を見るために「/usr/include/servers/bootstrap_defs.h 」を出してみました。それに関連するものは;
#define BOOTSTRAP_NOT_PRIVILEGED 1100
他をながめると「 __MAC_10_10,」の後ろ向きな記述が二箇所ありました。
__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_4, __MAC_10_10, __IPHONE_2_0, __IPHONE_7_0)
XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL5
kern_return_t
bootstrap_create_server(mach_port_t bp, cmd_t server_cmd, uid_t server_uid,
boolean_t on_demand, mach_port_t *server_port);
__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_4, __MAC_10_10, __IPHONE_2_0, __IPHONE_7_0)
XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL3
kern_return_t
bootstrap_subset(mach_port_t bp, mach_port_t requestor_port,
mach_port_t *subset_port);
他の、__MAC_10_4や__MAC_10_5に関しては、
__OSX_AVAILABLE_STARTING(__MAC_10_4,
といった前向きの記述がありました。
__MAC_10_10が「Yosemite 10.10.5」に対応するのならば、当方の場合、ある種の制限があるのかもしれません。
他方、今頃になって気がつきましたが、Terminar出力を直接にhtml書類に出来るのは凄いですね。何としても、類似性の高い色再現性を作りたくなりました。
aha.c の色指定部分を変更するパッチを作ってみました。文字色は Wikipedia のもの、背景色は DigitalColor Meter.app で採取したものです。
--- aha.org.c 2016-04-04 23:30:15.000000000 +0900 +++ aha.c 2016-04-04 23:29:15.000000000 +0900 @@ -264,22 +264,22 @@ } if (colorshema!=1) { - printf(".dimgray {color: dimgray;}\n"); - printf(".red {color: red;}\n"); - printf(".green {color: green;}\n"); - printf(".yellow {color: olive;}\n"); - printf(".blue {color: blue;}\n"); - printf(".purple {color: purple;}\n"); - printf(".cyan {color: teal;}\n"); - printf(".white {color: gray;}\n"); - printf(".bg-black {background-color: black;}\n"); - printf(".bg-red {background-color: red;}\n"); - printf(".bg-green {background-color: green;}\n"); - printf(".bg-yellow {background-color: olive;}\n"); - printf(".bg-blue {background-color: blue;}\n"); - printf(".bg-purple {background-color: purple;}\n"); - printf(".bg-cyan {background-color: teal;}\n"); - printf(".bg-white {background-color: gray;}\n"); + printf(".dimgray {color: rgb(0,0,0);}\n"); + printf(".red {color: rgb(194,54,33);}\n"); + printf(".green {color: rgb(37,188,36);}\n"); + printf(".yellow {color: rgb(173,173,39);}\n"); + printf(".blue {color: rgb(73,46,225);}\n"); + printf(".purple {color: rgb(211,56,211);}\n"); + printf(".cyan {color: rgb(51,187,200);}\n"); + printf(".white {color: rgb(203,204,205);}\n"); + printf(".bg-black {background-color: rgb(0,0,0);}\n"); + printf(".bg-red {background-color: rgb(153,0,0);}\n"); + printf(".bg-green {background-color: rgb(0,166,0);}\n"); + printf(".bg-yellow {background-color: rgb(153,153,0);}\n"); + printf(".bg-blue {background-color: rgb(0,0,179);}\n"); + printf(".bg-purple {background-color: rgb(179,0,179);}\n"); + printf(".bg-cyan {background-color: rgb(0,166,179);}\n"); + printf(".bg-white {background-color: rgb(191,191,191);}\n"); } else { @@ -495,52 +495,52 @@ case 0: if (stylesheet) printf("dimgray "); else - printf("color:dimgray;"); + printf("color:rgb(0,0,0);"); break; //Black case 1: if (stylesheet) printf("red "); else - printf("color:red;"); + printf("color:rgb(194,54,33);"); break; //Red case 2: if (stylesheet) printf("green "); else if (colorshema!=1) - printf("color:green;"); + printf("color:rgb(37,188,36);"); else printf("color:lime;"); break; //Green case 3: if (stylesheet) printf("yellow "); else if (colorshema!=1) - printf("color:olive;"); + printf("color:rgb(173,173,39);"); else printf("color:yellow;"); break; //Yellow case 4: if (stylesheet) printf("blue "); else if (colorshema!=1) - printf("color:blue;"); + printf("color:rgb(73,46,225);"); else printf("color:#3333FF;"); break; //Blue case 5: if (stylesheet) printf("purple "); else if (colorshema!=1) - printf("color:purple;"); + printf("color:rgb(211,56,211);"); else printf("color:fuchsia;"); break; //Purple case 6: if (stylesheet) printf("cyan "); else if (colorshema!=1) - printf("color:teal;"); + printf("color:rgb(51,187,200);"); else printf("color:aqua;"); break; //Cyan case 7: if (stylesheet) printf("white "); else if (colorshema!=1) - printf("color:gray;"); + printf("color:rgb(203,204,205);"); else printf("color:white;"); break; //White @@ -557,52 +557,52 @@ case 0: if (stylesheet) printf("bg-black "); else - printf("background-color:black;"); + printf("background-color:rgb(0,0,0);"); break; //Black case 1: if (stylesheet) printf("bg-red "); else - printf("background-color:red;"); + printf("background-color:rgb(153,0,0);"); break; //Red case 2: if (stylesheet) printf("bg-green "); else if (colorshema!=1) - printf("background-color:green;"); + printf("background-color:rgb(0,166,0);"); else printf("background-color:lime;"); break; //Green case 3: if (stylesheet) printf("bg-yellow "); else if (colorshema!=1) - printf("background-color:olive;"); + printf("background-color:rgb(153,153,0);"); else printf("background-color:yellow;"); break; //Yellow case 4: if (stylesheet) printf("bg-blue "); else if (colorshema!=1) - printf("background-color:blue;"); + printf("background-color:rgb(0,0,179);"); else printf("background-color:#3333FF;"); break; //Blue case 5: if (stylesheet) printf("bg-purple "); else if (colorshema!=1) - printf("background-color:purple;"); + printf("background-color:rgb(179,0,179);"); else printf("background-color:fuchsia;"); break; //Purple case 6: if (stylesheet) printf("bg-cyan "); else if (colorshema!=1) - printf("background-color:teal;"); + printf("background-color:rgb(0,166,179);"); else printf("background-color:aqua;"); break; //Cyan case 7: if (stylesheet) printf("bg-white "); else if (colorshema!=1) - printf("background-color:gray;"); + printf("background-color:rgb(191,191,191);"); else printf("background-color:white;"); break; //White
↑を aha.c と同じフォルダに、ファイル名 patch.txt で保存し、
cd で当該フォルダに移動してから、
aha.c 中のタブ文字をスペース4文字に展開して、上書き保存し、
perl -i -ple 's|\t| |g' aha.c
パッチを当てて、
patch <patch.txt
コンパイル
make
Hiro.Sさんによると:
aha.c の色指定部分を変更するパッチを作ってみました。文字色は Wikipedia のもの、背景色は DigitalColor Meter.app で採取したものです。
有難うございます。昨日はバタバタしていてご返信がおくれました。
パッチやディフというと朧げながら記憶の隅にある程だなので、使わせていただきます。
実は、ターミナルでのカラー設定では明示的にカラー名が出てこないので検討しようと思っていました;
でも、頂いた事例をもとに練習してみます。
取り急ぎ、ご報告まで。
Hiro.Sさん、
ご教示の修正は通った様です(main.cのサイズとタイムスタンプ、ahaのタイムスタンプ)。
しかし結果の色は同じ様です。これから外出するので、ご報告は遅れます、悪しからす。
自己コメントです。
「ANSI escape code」を眺めていると、「256-color mode」という記法がありました。これならカラー・コードの変換なしでhtmlに使用できる気もします。むしろ問題は、ahaでは、256色表示のエスケープ・コードの変換をさせないことが可能かどうかですね。
aha.c を見れば判ると思うけど、aha は拡張 256 色には対応していません。それらの色を扱いたいなら、aha のソースコードを自分で拡張するか、別のコンバータを探してください。
chandanaさんによると:
aha.c を見れば判ると思うけど、aha は拡張 256 色には対応していません。それらの色を扱いたいなら、aha のソースコードを自分で拡張するか、別のコンバータを探してください。
了解です。htmlで256色をみると、web安全色を中心に選択するのが好まれているようです。この辺りから初めて、terminal2htmlのようなのを探してみます。
折角ですから、aha.cを丁寧に眺めてみます。何か判るといいのですが...。
その後、ターミナル出力で、色付きの文字のカラー指定をrgb値で与えるユーティリティを探しましたがありませんでした。そこでターミナルWeb安全色の色付けはできるので、Web安全色の出力例を拝見して、rgbの順に6進法の順番に並べると考えやすいので、Web安全色の番号から、rgbの値に変換する関数をつくりました。
その計算結果の一部を図cに示します。
図c wsc2rgbの一部
この関数のプログラムを下記に示しておきます。
#!/bin/zsh
# USAGE: wsc2rgb↩️
wsc2rgb(){
#set -x
#wsc=16+Red*36+Green*6+Blue
wsc=$(($1))
nnn=$((wsc-16))
blue=$((nnn%6))
nn=$((nnn-blue))
green=$(((nn/6)%6))
red=$(((nnn/36)%6))
wscCheck=$((red*36+green*6+blue+16))
blueV=$((blue*51))
greenV=$((green*51))
redV=$((red*51))
}
############################# main ###################################
redV0=$((0))
echo " decimal hex recal"
echo " #wsc red grn blu rd gr bl #wsc "
echo " ---- ----------- -------- ----"
for (( wsc=16; wsc<=231; wsc++ )) do
wsc2rgb $wsc
if [[ $redV0 -ne $redV ]] then
echo
redV0=$redV
fi
printf " %3d %.3d %.3d %.3d %.2X %.2X %.2X %.3d\n"\
$wsc $redV $greenV $blueV $redV $greenV $blueV $wsnCheck
done
このあと、ahaのような感じで、ターミナル出力をteeで受けて、全体をblockquoteで包み、色付けしたところを、スクリプトで検索し、フォアグランド/バックグラウンドのhtml形式に変換するという予定です。
流れは読めましたが、実際上は忘れていることが多くて、難儀しそうです。Swiftでスマートな解決策があると嬉しいですが...。
色つきテキストを、コマンド・ラインから.rtfに保存する?