motion-yapper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.travis.yml +2 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/motion-yapper.rb +1 -0
  8. data/lib/yapper.rb +3 -5
  9. data/lib/yapper/config.rb +2 -0
  10. data/lib/yapper/db.rb +105 -40
  11. data/lib/yapper/document.rb +7 -4
  12. data/lib/yapper/document/callbacks.rb +0 -7
  13. data/lib/yapper/document/{persistance.rb → persistence.rb} +27 -21
  14. data/lib/yapper/document/relation.rb +29 -22
  15. data/lib/yapper/document/selection.rb +122 -54
  16. data/lib/yapper/extensions.rb +12 -24
  17. data/lib/yapper/settings.rb +43 -0
  18. data/lib/yapper/timestamps.rb +2 -0
  19. data/lib/yapper/version.rb +1 -1
  20. data/{yapper.gemspec → motion-yapper.gemspec} +0 -0
  21. data/spec/integration/{where_spec.rb → criteria_spec.rb} +78 -10
  22. data/spec/integration/db_spec.rb +70 -0
  23. data/spec/integration/defaults_spec.rb +37 -0
  24. data/spec/integration/extensions_spec.rb +14 -0
  25. data/spec/integration/{persistance_spec.rb → persistence_spec.rb} +0 -0
  26. data/spec/integration/relation_spec.rb +4 -4
  27. data/vendor/Podfile.lock +9 -11
  28. data/vendor/Pods/.build/libPods-CocoaLumberjack.a +0 -0
  29. data/vendor/Pods/.build/libPods-NSData+MD5Digest.a +0 -0
  30. data/vendor/Pods/.build/libPods-YapDatabase.a +0 -0
  31. data/vendor/Pods/.build/libPods.a +0 -0
  32. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +4 -4
  33. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +14 -14
  34. data/vendor/Pods/{CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h → BuildHeaders/CocoaLumberjack/DDContextFilterLogFormatter.h} +6 -8
  35. data/vendor/Pods/BuildHeaders/CocoaLumberjack/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  36. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +67 -32
  37. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog+LOGV.h +99 -0
  38. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +98 -65
  39. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDMultiFormatter.h +30 -0
  40. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +39 -25
  41. data/vendor/Pods/BuildHeaders/YapDatabase/NSDictionary+YapDatabase.h +8 -0
  42. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +1 -0
  43. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +3 -0
  44. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +4 -4
  45. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +21 -19
  46. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +1 -1
  47. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +35 -31
  48. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +8 -35
  49. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -2
  50. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +17 -17
  51. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTypes.h +32 -0
  52. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +8 -0
  53. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +43 -21
  54. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationship.h +35 -0
  55. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipConnection.h +29 -0
  56. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdge.h +163 -0
  57. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdgePrivate.h +79 -0
  58. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipNode.h +99 -0
  59. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipOptions.h +59 -0
  60. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipPrivate.h +125 -0
  61. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipTransaction.h +384 -0
  62. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +49 -0
  63. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +10 -0
  64. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetupPrivate.h +18 -0
  65. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +131 -21
  66. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +48 -107
  67. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +2 -2
  68. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +1 -0
  69. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +17 -0
  70. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +10 -3
  71. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +18 -1
  72. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +75 -24
  73. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTypes.h +99 -0
  74. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +4 -4
  75. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +51 -50
  76. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +14 -14
  77. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +546 -546
  78. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +67 -32
  79. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1093 -907
  80. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog+LOGV.h +99 -0
  81. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +98 -65
  82. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +873 -748
  83. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +39 -25
  84. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1284 -1243
  85. data/vendor/Pods/{BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h → CocoaLumberjack/Lumberjack/Extensions/DDContextFilterLogFormatter.h} +6 -8
  86. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/{ContextFilterLogFormatter.m → DDContextFilterLogFormatter.m} +70 -70
  87. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  88. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDDispatchQueueLogFormatter.m +253 -0
  89. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.h +30 -0
  90. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.m +127 -0
  91. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +1 -1
  92. data/vendor/Pods/CocoaLumberjack/README.markdown +52 -15
  93. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +4 -4
  94. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +14 -14
  95. data/vendor/Pods/Headers/CocoaLumberjack/{ContextFilterLogFormatter.h → DDContextFilterLogFormatter.h} +6 -8
  96. data/vendor/Pods/Headers/CocoaLumberjack/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  97. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +67 -32
  98. data/vendor/Pods/Headers/CocoaLumberjack/DDLog+LOGV.h +99 -0
  99. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +98 -65
  100. data/vendor/Pods/Headers/CocoaLumberjack/DDMultiFormatter.h +30 -0
  101. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +39 -25
  102. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +3 -0
  103. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +4 -4
  104. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +21 -19
  105. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +8 -35
  106. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +17 -17
  107. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTypes.h +32 -0
  108. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationship.h +35 -0
  109. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipConnection.h +29 -0
  110. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipEdge.h +163 -0
  111. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipNode.h +99 -0
  112. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipOptions.h +59 -0
  113. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipTransaction.h +384 -0
  114. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +49 -0
  115. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +131 -21
  116. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +48 -107
  117. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +2 -2
  118. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +1 -0
  119. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +17 -0
  120. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +10 -3
  121. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +75 -24
  122. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTypes.h +99 -0
  123. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +2 -0
  124. data/vendor/Pods/Headers/____Pods-environment.h +15 -15
  125. data/vendor/Pods/Manifest.lock +9 -11
  126. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +1 -1
  127. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +2 -0
  128. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +1 -1
  129. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +1 -1
  130. data/vendor/Pods/{Pods-Acknowledgements.markdown → Pods-acknowledgements.markdown} +0 -37
  131. data/vendor/Pods/{Pods-Acknowledgements.plist → Pods-acknowledgements.plist} +0 -45
  132. data/vendor/Pods/Pods-environment.h +15 -15
  133. data/vendor/Pods/Pods.xcconfig +3 -3
  134. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +2426 -3155
  135. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-CocoaLumberjack.xcscheme +59 -0
  136. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-NSData+MD5Digest.xcscheme +59 -0
  137. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-YapDatabase.xcscheme +59 -0
  138. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods.xcscheme +59 -0
  139. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/xcschememanagement.plist +31 -0
  140. data/vendor/Pods/YapDatabase/README.md +3 -1
  141. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +0 -2
  142. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +8 -35
  143. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +25 -41
  144. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +17 -17
  145. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +403 -134
  146. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTypes.h +32 -0
  147. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +8 -0
  148. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +8 -8
  149. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +113 -62
  150. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +35 -31
  151. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +25 -0
  152. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +1 -1
  153. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +25 -1
  154. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipEdgePrivate.h +79 -0
  155. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipPrivate.h +125 -0
  156. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.h +35 -0
  157. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.m +129 -0
  158. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.h +29 -0
  159. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.m +802 -0
  160. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.h +163 -0
  161. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.m +408 -0
  162. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipNode.h +99 -0
  163. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.h +59 -0
  164. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.m +29 -0
  165. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.h +384 -0
  166. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.m +5254 -0
  167. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +10 -0
  168. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexSetupPrivate.h +18 -0
  169. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +49 -0
  170. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +12 -0
  171. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +9 -8
  172. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +62 -1
  173. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +148 -45
  174. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +18 -1
  175. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +2 -2
  176. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +15 -9
  177. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +17 -0
  178. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +211 -64
  179. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +48 -107
  180. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +10 -7
  181. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +1 -0
  182. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +13 -22
  183. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +10 -3
  184. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +75 -24
  185. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +725 -244
  186. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTypes.h +99 -0
  187. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.h +8 -0
  188. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.m +19 -0
  189. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +1 -0
  190. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +12 -0
  191. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +1 -1
  192. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +3 -3
  193. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +43 -21
  194. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +4 -0
  195. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +3 -0
  196. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +5 -0
  197. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +4 -4
  198. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +84 -93
  199. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +21 -19
  200. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +381 -209
  201. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +131 -21
  202. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +587 -267
  203. data/vendor/Pods/{Pods.bridgesupport → build-iPhoneSimulator/Pods.bridgesupport} +633 -2557
  204. data/vendor/Pods/build-iPhoneSimulator/libPods.a +0 -0
  205. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +2 -1
  206. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +2 -1
  207. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +4 -2
  208. metadata +80 -108
  209. data/Gemfile.lock +0 -63
  210. data/lib/yapper/attachment.rb +0 -48
  211. data/lib/yapper/document/attachment.rb +0 -26
  212. data/lib/yapper/sync.rb +0 -134
  213. data/lib/yapper/sync/data.rb +0 -12
  214. data/lib/yapper/sync/event.rb +0 -194
  215. data/lib/yapper/sync/queue.rb +0 -164
  216. data/spec/integration/all_spec.rb +0 -40
  217. data/spec/integration/sync_spec.rb +0 -42
  218. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +0 -641
  219. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +0 -1396
  220. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +0 -133
  221. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +0 -327
  222. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +0 -113
  223. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +0 -321
  224. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +0 -71
  225. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +0 -150
  226. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  227. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +0 -157
  228. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +0 -43
  229. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  230. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +0 -143
  231. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +0 -370
  232. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +0 -848
  233. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +0 -89
  234. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +0 -167
  235. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +0 -78
  236. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +0 -191
  237. data/vendor/Pods/AFNetworking/LICENSE +0 -19
  238. data/vendor/Pods/AFNetworking/README.md +0 -208
  239. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +0 -641
  240. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +0 -133
  241. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +0 -113
  242. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +0 -71
  243. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  244. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +0 -43
  245. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  246. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +0 -370
  247. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +0 -89
  248. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +0 -78
  249. data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +0 -109
  250. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +0 -251
  251. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +0 -641
  252. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +0 -133
  253. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +0 -113
  254. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +0 -71
  255. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  256. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +0 -43
  257. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  258. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +0 -370
  259. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +0 -89
  260. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +0 -78
  261. data/vendor/Pods/Headers/Reachability/Reachability.h +0 -109
  262. data/vendor/Pods/Headers/YapDatabase/YapCache.h +0 -90
  263. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +0 -29
  264. data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +0 -37
  265. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +0 -440
  266. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -19
  267. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +0 -69
  268. data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +0 -158
  269. data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +0 -17
  270. data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +0 -424
  271. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +0 -73
  272. data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +0 -13
  273. data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +0 -121
  274. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +0 -94
  275. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +0 -72
  276. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +0 -36
  277. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +0 -27
  278. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +0 -153
  279. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +0 -17
  280. data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +0 -74
  281. data/vendor/Pods/Headers/YapDatabase/YapNull.h +0 -17
  282. data/vendor/Pods/Headers/YapDatabase/YapTouch.h +0 -15
  283. data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +0 -17
  284. data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +0 -5
  285. data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +0 -5
  286. data/vendor/Pods/Pods-AFNetworking-dummy.m +0 -5
  287. data/vendor/Pods/Pods-AFNetworking-prefix.pch +0 -17
  288. data/vendor/Pods/Pods-AFNetworking.xcconfig +0 -1
  289. data/vendor/Pods/Pods-Reachability-Private.xcconfig +0 -5
  290. data/vendor/Pods/Pods-Reachability-dummy.m +0 -5
  291. data/vendor/Pods/Pods-Reachability-prefix.pch +0 -5
  292. data/vendor/Pods/Pods-Reachability.xcconfig +0 -1
  293. data/vendor/Pods/Reachability/LICENCE.txt +0 -24
  294. data/vendor/Pods/Reachability/README.md +0 -65
  295. data/vendor/Pods/Reachability/Reachability.h +0 -109
  296. data/vendor/Pods/Reachability/Reachability.m +0 -527
@@ -1,20 +1,24 @@
1
1
  #import <Foundation/Foundation.h>
2
2
  #if TARGET_OS_IPHONE
3
- #import <UIKit/UIColor.h>
3
+ #import <UIKit/UIColor.h> // iOS
4
+ #elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
5
+ #import <AppKit/NSColor.h> // OS X with AppKit
4
6
  #else
5
- #import <AppKit/NSColor.h>
7
+ #import "CLIColor.h" // OS X without AppKit
6
8
  #endif
7
9
 
8
10
  #import "DDLog.h"
9
11
 
12
+ #define LOG_CONTEXT_ALL INT_MAX
13
+
10
14
  /**
11
15
  * Welcome to Cocoa Lumberjack!
12
16
  *
13
17
  * The project page has a wealth of documentation if you have any questions.
14
- * https://github.com/robbiehanson/CocoaLumberjack
18
+ * https://github.com/CocoaLumberjack/CocoaLumberjack
15
19
  *
16
20
  * If you're new to the project you may wish to read the "Getting Started" wiki.
17
- * https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
21
+ * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted
18
22
  *
19
23
  *
20
24
  * This class provides a logger for Terminal output or Xcode console output,
@@ -33,23 +37,23 @@
33
37
 
34
38
  @interface DDTTYLogger : DDAbstractLogger <DDLogger>
35
39
  {
36
- NSCalendar *calendar;
37
- NSUInteger calendarUnitFlags;
38
-
39
- NSString *appName;
40
- char *app;
41
- size_t appLen;
42
-
43
- NSString *processID;
44
- char *pid;
45
- size_t pidLen;
46
-
47
- BOOL colorsEnabled;
48
- NSMutableArray *colorProfilesArray;
49
- NSMutableDictionary *colorProfilesDict;
40
+ NSCalendar *calendar;
41
+ NSUInteger calendarUnitFlags;
42
+
43
+ NSString *appName;
44
+ char *app;
45
+ size_t appLen;
46
+
47
+ NSString *processID;
48
+ char *pid;
49
+ size_t pidLen;
50
+
51
+ BOOL colorsEnabled;
52
+ NSMutableArray *colorProfilesArray;
53
+ NSMutableDictionary *colorProfilesDict;
50
54
  }
51
55
 
52
- + (DDTTYLogger *)sharedInstance;
56
+ + (instancetype)sharedInstance;
53
57
 
54
58
  /* Inherited from the DDLogger protocol:
55
59
  *
@@ -59,7 +63,7 @@
59
63
  * or it may use its own built in formatting style.
60
64
  *
61
65
  * More information about formatters can be found here:
62
- * https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomFormatters
66
+ * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomFormatters
63
67
  *
64
68
  * The actual implementation of these methods is inherited from DDAbstractLogger.
65
69
 
@@ -103,12 +107,14 @@
103
107
  * If you run the application from a shell, then DDTTYLogger will automatically map the given color to
104
108
  * the closest available color. (xterm-256color or xterm-color which have 256 and 16 supported colors respectively.)
105
109
  *
106
- * This method invokes setForegroundColor:backgroundColor:forFlag:context: and passes the default context (0).
110
+ * This method invokes setForegroundColor:backgroundColor:forFlag:context: and applies it to `LOG_CONTEXT_ALL`.
107
111
  **/
108
112
  #if TARGET_OS_IPHONE
109
113
  - (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask;
110
- #else
114
+ #elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
111
115
  - (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask;
116
+ #else
117
+ - (void)setForegroundColor:(CLIColor *)txtColor backgroundColor:(CLIColor *)bgColor forFlag:(int)mask;
112
118
  #endif
113
119
 
114
120
  /**
@@ -117,13 +123,17 @@
117
123
  * A logging context is often used to identify log messages coming from a 3rd party framework,
118
124
  * although logging context's can be used for many different functions.
119
125
  *
126
+ * Use LOG_CONTEXT_ALL to set the deafult color for all contexts that have no specific color set defined.
127
+ *
120
128
  * Logging context's are explained in further detail here:
121
- * https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomContext
129
+ * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomContext
122
130
  **/
123
131
  #if TARGET_OS_IPHONE
124
132
  - (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask context:(int)ctxt;
125
- #else
133
+ #elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
126
134
  - (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask context:(int)ctxt;
135
+ #else
136
+ - (void)setForegroundColor:(CLIColor *)txtColor backgroundColor:(CLIColor *)bgColor forFlag:(int)mask context:(int)ctxt;
127
137
  #endif
128
138
 
129
139
  /**
@@ -140,6 +150,8 @@
140
150
  * UIColor *purple = [UIColor colorWithRed:(64/255.0) green:(0/255.0) blue:(128/255.0) alpha:1.0];
141
151
  * #else
142
152
  * NSColor *purple = [NSColor colorWithCalibratedRed:(64/255.0) green:(0/255.0) blue:(128/255.0) alpha:1.0];
153
+ *
154
+ * Note: For CLI OS X projects that don't link with AppKit use CLIColor objects instead
143
155
  *
144
156
  * [[DDTTYLogger sharedInstance] setForegroundColor:purple backgroundColor:nil forTag:PurpleTag];
145
157
  * [DDLog addLogger:[DDTTYLogger sharedInstance]];
@@ -150,8 +162,10 @@
150
162
  **/
151
163
  #if TARGET_OS_IPHONE
152
164
  - (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forTag:(id <NSCopying>)tag;
153
- #else
165
+ #elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
154
166
  - (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forTag:(id <NSCopying>)tag;
167
+ #else
168
+ - (void)setForegroundColor:(CLIColor *)txtColor backgroundColor:(CLIColor *)bgColor forTag:(id <NSCopying>)tag;
155
169
  #endif
156
170
 
157
171
  /**
@@ -7,10 +7,10 @@
7
7
  * Welcome to Cocoa Lumberjack!
8
8
  *
9
9
  * The project page has a wealth of documentation if you have any questions.
10
- * https://github.com/robbiehanson/CocoaLumberjack
10
+ * https://github.com/CocoaLumberjack/CocoaLumberjack
11
11
  *
12
12
  * If you're new to the project you may wish to read the "Getting Started" wiki.
13
- * https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
13
+ * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted
14
14
  **/
15
15
 
16
16
  #if ! __has_feature(objc_arc)
@@ -29,7 +29,8 @@
29
29
  #define NSLogError(frmt, ...) do{ if(LOG_LEVEL >= 1) NSLog((frmt), ##__VA_ARGS__); } while(0)
30
30
  #define NSLogWarn(frmt, ...) do{ if(LOG_LEVEL >= 2) NSLog((frmt), ##__VA_ARGS__); } while(0)
31
31
  #define NSLogInfo(frmt, ...) do{ if(LOG_LEVEL >= 3) NSLog((frmt), ##__VA_ARGS__); } while(0)
32
- #define NSLogVerbose(frmt, ...) do{ if(LOG_LEVEL >= 4) NSLog((frmt), ##__VA_ARGS__); } while(0)
32
+ #define NSLogDebug(frmt, ...) do{ if(LOG_LEVEL >= 4) NSLog((frmt), ##__VA_ARGS__); } while(0)
33
+ #define NSLogVerbose(frmt, ...) do{ if(LOG_LEVEL >= 5) NSLog((frmt), ##__VA_ARGS__); } while(0)
33
34
 
34
35
  // Xcode does NOT natively support colors in the Xcode debugging console.
35
36
  // You'll need to install the XcodeColors plugin to see colors in the Xcode console.
@@ -64,15 +65,14 @@
64
65
  // Some simple defines to make life easier on ourself
65
66
 
66
67
  #if TARGET_OS_IPHONE
68
+ #define OSColor UIColor
67
69
  #define MakeColor(r, g, b) [UIColor colorWithRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
68
- #else
70
+ #elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
71
+ #define OSColor NSColor
69
72
  #define MakeColor(r, g, b) [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
70
- #endif
71
-
72
- #if TARGET_OS_IPHONE
73
- #define OSColor UIColor
74
73
  #else
75
- #define OSColor NSColor
74
+ #define OSColor CLIColor
75
+ #define MakeColor(r, g, b) [CLIColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
76
76
  #endif
77
77
 
78
78
  // If running in a shell, not all RGB colors will be supported.
@@ -88,34 +88,34 @@
88
88
 
89
89
  @interface DDTTYLoggerColorProfile : NSObject {
90
90
  @public
91
- int mask;
92
- int context;
93
-
94
- uint8_t fg_r;
95
- uint8_t fg_g;
96
- uint8_t fg_b;
97
-
98
- uint8_t bg_r;
99
- uint8_t bg_g;
100
- uint8_t bg_b;
101
-
102
- NSUInteger fgCodeIndex;
103
- NSString *fgCodeRaw;
104
-
105
- NSUInteger bgCodeIndex;
106
- NSString *bgCodeRaw;
107
-
108
- char fgCode[24];
109
- size_t fgCodeLen;
110
-
111
- char bgCode[24];
112
- size_t bgCodeLen;
113
-
114
- char resetCode[8];
115
- size_t resetCodeLen;
91
+ int mask;
92
+ int context;
93
+
94
+ uint8_t fg_r;
95
+ uint8_t fg_g;
96
+ uint8_t fg_b;
97
+
98
+ uint8_t bg_r;
99
+ uint8_t bg_g;
100
+ uint8_t bg_b;
101
+
102
+ NSUInteger fgCodeIndex;
103
+ NSString *fgCodeRaw;
104
+
105
+ NSUInteger bgCodeIndex;
106
+ NSString *bgCodeRaw;
107
+
108
+ char fgCode[24];
109
+ size_t fgCodeLen;
110
+
111
+ char bgCode[24];
112
+ size_t bgCodeLen;
113
+
114
+ char resetCode[8];
115
+ size_t resetCodeLen;
116
116
  }
117
117
 
118
- - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)mask context:(int)ctxt;
118
+ - (instancetype)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)mask context:(int)ctxt;
119
119
 
120
120
  @end
121
121
 
@@ -143,105 +143,105 @@ static DDTTYLogger *sharedInstance;
143
143
  **/
144
144
  + (void)initialize_colors_16
145
145
  {
146
- if (codes_fg || codes_bg || colors) return;
147
-
148
- NSMutableArray *m_codes_fg = [NSMutableArray arrayWithCapacity:16];
149
- NSMutableArray *m_codes_bg = [NSMutableArray arrayWithCapacity:16];
150
- NSMutableArray *m_colors = [NSMutableArray arrayWithCapacity:16];
151
-
152
- // In a standard shell only 16 colors are supported.
153
- //
154
- // More information about ansi escape codes can be found online.
155
- // http://en.wikipedia.org/wiki/ANSI_escape_code
156
-
157
- [m_codes_fg addObject:@"30m"]; // normal - black
158
- [m_codes_fg addObject:@"31m"]; // normal - red
159
- [m_codes_fg addObject:@"32m"]; // normal - green
160
- [m_codes_fg addObject:@"33m"]; // normal - yellow
161
- [m_codes_fg addObject:@"34m"]; // normal - blue
162
- [m_codes_fg addObject:@"35m"]; // normal - magenta
163
- [m_codes_fg addObject:@"36m"]; // normal - cyan
164
- [m_codes_fg addObject:@"37m"]; // normal - gray
165
- [m_codes_fg addObject:@"1;30m"]; // bright - darkgray
166
- [m_codes_fg addObject:@"1;31m"]; // bright - red
167
- [m_codes_fg addObject:@"1;32m"]; // bright - green
168
- [m_codes_fg addObject:@"1;33m"]; // bright - yellow
169
- [m_codes_fg addObject:@"1;34m"]; // bright - blue
170
- [m_codes_fg addObject:@"1;35m"]; // bright - magenta
171
- [m_codes_fg addObject:@"1;36m"]; // bright - cyan
172
- [m_codes_fg addObject:@"1;37m"]; // bright - white
173
-
174
- [m_codes_bg addObject:@"40m"]; // normal - black
175
- [m_codes_bg addObject:@"41m"]; // normal - red
176
- [m_codes_bg addObject:@"42m"]; // normal - green
177
- [m_codes_bg addObject:@"43m"]; // normal - yellow
178
- [m_codes_bg addObject:@"44m"]; // normal - blue
179
- [m_codes_bg addObject:@"45m"]; // normal - magenta
180
- [m_codes_bg addObject:@"46m"]; // normal - cyan
181
- [m_codes_bg addObject:@"47m"]; // normal - gray
182
- [m_codes_bg addObject:@"1;40m"]; // bright - darkgray
183
- [m_codes_bg addObject:@"1;41m"]; // bright - red
184
- [m_codes_bg addObject:@"1;42m"]; // bright - green
185
- [m_codes_bg addObject:@"1;43m"]; // bright - yellow
186
- [m_codes_bg addObject:@"1;44m"]; // bright - blue
187
- [m_codes_bg addObject:@"1;45m"]; // bright - magenta
188
- [m_codes_bg addObject:@"1;46m"]; // bright - cyan
189
- [m_codes_bg addObject:@"1;47m"]; // bright - white
190
-
146
+ if (codes_fg || codes_bg || colors) return;
147
+
148
+ NSMutableArray *m_codes_fg = [NSMutableArray arrayWithCapacity:16];
149
+ NSMutableArray *m_codes_bg = [NSMutableArray arrayWithCapacity:16];
150
+ NSMutableArray *m_colors = [NSMutableArray arrayWithCapacity:16];
151
+
152
+ // In a standard shell only 16 colors are supported.
153
+ //
154
+ // More information about ansi escape codes can be found online.
155
+ // http://en.wikipedia.org/wiki/ANSI_escape_code
156
+
157
+ [m_codes_fg addObject:@"30m"]; // normal - black
158
+ [m_codes_fg addObject:@"31m"]; // normal - red
159
+ [m_codes_fg addObject:@"32m"]; // normal - green
160
+ [m_codes_fg addObject:@"33m"]; // normal - yellow
161
+ [m_codes_fg addObject:@"34m"]; // normal - blue
162
+ [m_codes_fg addObject:@"35m"]; // normal - magenta
163
+ [m_codes_fg addObject:@"36m"]; // normal - cyan
164
+ [m_codes_fg addObject:@"37m"]; // normal - gray
165
+ [m_codes_fg addObject:@"1;30m"]; // bright - darkgray
166
+ [m_codes_fg addObject:@"1;31m"]; // bright - red
167
+ [m_codes_fg addObject:@"1;32m"]; // bright - green
168
+ [m_codes_fg addObject:@"1;33m"]; // bright - yellow
169
+ [m_codes_fg addObject:@"1;34m"]; // bright - blue
170
+ [m_codes_fg addObject:@"1;35m"]; // bright - magenta
171
+ [m_codes_fg addObject:@"1;36m"]; // bright - cyan
172
+ [m_codes_fg addObject:@"1;37m"]; // bright - white
173
+
174
+ [m_codes_bg addObject:@"40m"]; // normal - black
175
+ [m_codes_bg addObject:@"41m"]; // normal - red
176
+ [m_codes_bg addObject:@"42m"]; // normal - green
177
+ [m_codes_bg addObject:@"43m"]; // normal - yellow
178
+ [m_codes_bg addObject:@"44m"]; // normal - blue
179
+ [m_codes_bg addObject:@"45m"]; // normal - magenta
180
+ [m_codes_bg addObject:@"46m"]; // normal - cyan
181
+ [m_codes_bg addObject:@"47m"]; // normal - gray
182
+ [m_codes_bg addObject:@"1;40m"]; // bright - darkgray
183
+ [m_codes_bg addObject:@"1;41m"]; // bright - red
184
+ [m_codes_bg addObject:@"1;42m"]; // bright - green
185
+ [m_codes_bg addObject:@"1;43m"]; // bright - yellow
186
+ [m_codes_bg addObject:@"1;44m"]; // bright - blue
187
+ [m_codes_bg addObject:@"1;45m"]; // bright - magenta
188
+ [m_codes_bg addObject:@"1;46m"]; // bright - cyan
189
+ [m_codes_bg addObject:@"1;47m"]; // bright - white
190
+
191
191
  #if MAP_TO_TERMINAL_APP_COLORS
192
-
193
- // Standard Terminal.app colors:
194
- //
195
- // These are the default colors used by Apple's Terminal.app.
196
-
197
- [m_colors addObject:MakeColor( 0, 0, 0)]; // normal - black
198
- [m_colors addObject:MakeColor(194, 54, 33)]; // normal - red
199
- [m_colors addObject:MakeColor( 37, 188, 36)]; // normal - green
200
- [m_colors addObject:MakeColor(173, 173, 39)]; // normal - yellow
201
- [m_colors addObject:MakeColor( 73, 46, 225)]; // normal - blue
202
- [m_colors addObject:MakeColor(211, 56, 211)]; // normal - magenta
203
- [m_colors addObject:MakeColor( 51, 187, 200)]; // normal - cyan
204
- [m_colors addObject:MakeColor(203, 204, 205)]; // normal - gray
205
- [m_colors addObject:MakeColor(129, 131, 131)]; // bright - darkgray
206
- [m_colors addObject:MakeColor(252, 57, 31)]; // bright - red
207
- [m_colors addObject:MakeColor( 49, 231, 34)]; // bright - green
208
- [m_colors addObject:MakeColor(234, 236, 35)]; // bright - yellow
209
- [m_colors addObject:MakeColor( 88, 51, 255)]; // bright - blue
210
- [m_colors addObject:MakeColor(249, 53, 248)]; // bright - magenta
211
- [m_colors addObject:MakeColor( 20, 240, 240)]; // bright - cyan
212
- [m_colors addObject:MakeColor(233, 235, 235)]; // bright - white
213
-
192
+
193
+ // Standard Terminal.app colors:
194
+ //
195
+ // These are the default colors used by Apple's Terminal.app.
196
+
197
+ [m_colors addObject:MakeColor( 0, 0, 0)]; // normal - black
198
+ [m_colors addObject:MakeColor(194, 54, 33)]; // normal - red
199
+ [m_colors addObject:MakeColor( 37, 188, 36)]; // normal - green
200
+ [m_colors addObject:MakeColor(173, 173, 39)]; // normal - yellow
201
+ [m_colors addObject:MakeColor( 73, 46, 225)]; // normal - blue
202
+ [m_colors addObject:MakeColor(211, 56, 211)]; // normal - magenta
203
+ [m_colors addObject:MakeColor( 51, 187, 200)]; // normal - cyan
204
+ [m_colors addObject:MakeColor(203, 204, 205)]; // normal - gray
205
+ [m_colors addObject:MakeColor(129, 131, 131)]; // bright - darkgray
206
+ [m_colors addObject:MakeColor(252, 57, 31)]; // bright - red
207
+ [m_colors addObject:MakeColor( 49, 231, 34)]; // bright - green
208
+ [m_colors addObject:MakeColor(234, 236, 35)]; // bright - yellow
209
+ [m_colors addObject:MakeColor( 88, 51, 255)]; // bright - blue
210
+ [m_colors addObject:MakeColor(249, 53, 248)]; // bright - magenta
211
+ [m_colors addObject:MakeColor( 20, 240, 240)]; // bright - cyan
212
+ [m_colors addObject:MakeColor(233, 235, 235)]; // bright - white
213
+
214
214
  #else
215
-
216
- // Standard xterm colors:
217
- //
218
- // These are the default colors used by most xterm shells.
219
-
220
- [m_colors addObject:MakeColor( 0, 0, 0)]; // normal - black
221
- [m_colors addObject:MakeColor(205, 0, 0)]; // normal - red
222
- [m_colors addObject:MakeColor( 0, 205, 0)]; // normal - green
223
- [m_colors addObject:MakeColor(205, 205, 0)]; // normal - yellow
224
- [m_colors addObject:MakeColor( 0, 0, 238)]; // normal - blue
225
- [m_colors addObject:MakeColor(205, 0, 205)]; // normal - magenta
226
- [m_colors addObject:MakeColor( 0, 205, 205)]; // normal - cyan
227
- [m_colors addObject:MakeColor(229, 229, 229)]; // normal - gray
228
- [m_colors addObject:MakeColor(127, 127, 127)]; // bright - darkgray
229
- [m_colors addObject:MakeColor(255, 0, 0)]; // bright - red
230
- [m_colors addObject:MakeColor( 0, 255, 0)]; // bright - green
231
- [m_colors addObject:MakeColor(255, 255, 0)]; // bright - yellow
232
- [m_colors addObject:MakeColor( 92, 92, 255)]; // bright - blue
233
- [m_colors addObject:MakeColor(255, 0, 255)]; // bright - magenta
234
- [m_colors addObject:MakeColor( 0, 255, 255)]; // bright - cyan
235
- [m_colors addObject:MakeColor(255, 255, 255)]; // bright - white
236
-
215
+
216
+ // Standard xterm colors:
217
+ //
218
+ // These are the default colors used by most xterm shells.
219
+
220
+ [m_colors addObject:MakeColor( 0, 0, 0)]; // normal - black
221
+ [m_colors addObject:MakeColor(205, 0, 0)]; // normal - red
222
+ [m_colors addObject:MakeColor( 0, 205, 0)]; // normal - green
223
+ [m_colors addObject:MakeColor(205, 205, 0)]; // normal - yellow
224
+ [m_colors addObject:MakeColor( 0, 0, 238)]; // normal - blue
225
+ [m_colors addObject:MakeColor(205, 0, 205)]; // normal - magenta
226
+ [m_colors addObject:MakeColor( 0, 205, 205)]; // normal - cyan
227
+ [m_colors addObject:MakeColor(229, 229, 229)]; // normal - gray
228
+ [m_colors addObject:MakeColor(127, 127, 127)]; // bright - darkgray
229
+ [m_colors addObject:MakeColor(255, 0, 0)]; // bright - red
230
+ [m_colors addObject:MakeColor( 0, 255, 0)]; // bright - green
231
+ [m_colors addObject:MakeColor(255, 255, 0)]; // bright - yellow
232
+ [m_colors addObject:MakeColor( 92, 92, 255)]; // bright - blue
233
+ [m_colors addObject:MakeColor(255, 0, 255)]; // bright - magenta
234
+ [m_colors addObject:MakeColor( 0, 255, 255)]; // bright - cyan
235
+ [m_colors addObject:MakeColor(255, 255, 255)]; // bright - white
236
+
237
237
  #endif
238
-
239
- codes_fg = [m_codes_fg copy];
240
- codes_bg = [m_codes_bg copy];
241
- colors = [m_colors copy];
242
-
243
- NSAssert([codes_fg count] == [codes_bg count], @"Invalid colors/codes array(s)");
244
- NSAssert([codes_fg count] == [colors count], @"Invalid colors/codes array(s)");
238
+
239
+ codes_fg = [m_codes_fg copy];
240
+ codes_bg = [m_codes_bg copy];
241
+ colors = [m_colors copy];
242
+
243
+ NSAssert([codes_fg count] == [codes_bg count], @"Invalid colors/codes array(s)");
244
+ NSAssert([codes_fg count] == [colors count], @"Invalid colors/codes array(s)");
245
245
  }
246
246
 
247
247
  /**
@@ -252,459 +252,470 @@ static DDTTYLogger *sharedInstance;
252
252
  **/
253
253
  + (void)initialize_colors_256
254
254
  {
255
- if (codes_fg || codes_bg || colors) return;
256
-
257
- NSMutableArray *m_codes_fg = [NSMutableArray arrayWithCapacity:(256-16)];
258
- NSMutableArray *m_codes_bg = [NSMutableArray arrayWithCapacity:(256-16)];
259
- NSMutableArray *m_colors = [NSMutableArray arrayWithCapacity:(256-16)];
260
-
261
- #if MAP_TO_TERMINAL_APP_COLORS
262
-
263
- // Standard Terminal.app colors:
264
- //
265
- // These are the colors the Terminal.app uses in xterm-256color mode.
266
- // In this mode, the terminal supports 256 different colors, specified by 256 color codes.
267
- //
268
- // The first 16 color codes map to the original 16 color codes supported by the earlier xterm-color mode.
269
- // These are actually configurable, and thus we ignore them for the purposes of mapping,
270
- // as we can't rely on them being constant. They are largely duplicated anyway.
271
- //
272
- // The next 216 color codes are designed to run the spectrum, with several shades of every color.
273
- // While the color codes are standardized, the actual RGB values for each color code is not.
274
- // Apple's Terminal.app uses different RGB values from that of a standard xterm.
275
- // Apple's choices in colors are designed to be a little nicer on the eyes.
276
- //
277
- // The last 24 color codes represent a grayscale.
278
- //
279
- // Unfortunately, unlike the standard xterm color chart,
280
- // Apple's RGB values cannot be calculated using a simple formula (at least not that I know of).
281
- // Also, I don't know of any ways to programmatically query the shell for the RGB values.
282
- // So this big giant color chart had to be made by hand.
283
- //
284
- // More information about ansi escape codes can be found online.
285
- // http://en.wikipedia.org/wiki/ANSI_escape_code
286
-
287
- // Colors
288
-
289
- [m_colors addObject:MakeColor( 47, 49, 49)];
290
- [m_colors addObject:MakeColor( 60, 42, 144)];
291
- [m_colors addObject:MakeColor( 66, 44, 183)];
292
- [m_colors addObject:MakeColor( 73, 46, 222)];
293
- [m_colors addObject:MakeColor( 81, 50, 253)];
294
- [m_colors addObject:MakeColor( 88, 51, 255)];
295
-
296
- [m_colors addObject:MakeColor( 42, 128, 37)];
297
- [m_colors addObject:MakeColor( 42, 127, 128)];
298
- [m_colors addObject:MakeColor( 44, 126, 169)];
299
- [m_colors addObject:MakeColor( 56, 125, 209)];
300
- [m_colors addObject:MakeColor( 59, 124, 245)];
301
- [m_colors addObject:MakeColor( 66, 123, 255)];
302
-
303
- [m_colors addObject:MakeColor( 51, 163, 41)];
304
- [m_colors addObject:MakeColor( 39, 162, 121)];
305
- [m_colors addObject:MakeColor( 42, 161, 162)];
306
- [m_colors addObject:MakeColor( 53, 160, 202)];
307
- [m_colors addObject:MakeColor( 45, 159, 240)];
308
- [m_colors addObject:MakeColor( 58, 158, 255)];
309
-
310
- [m_colors addObject:MakeColor( 31, 196, 37)];
311
- [m_colors addObject:MakeColor( 48, 196, 115)];
312
- [m_colors addObject:MakeColor( 39, 195, 155)];
313
- [m_colors addObject:MakeColor( 49, 195, 195)];
314
- [m_colors addObject:MakeColor( 32, 194, 235)];
315
- [m_colors addObject:MakeColor( 53, 193, 255)];
316
-
317
- [m_colors addObject:MakeColor( 50, 229, 35)];
318
- [m_colors addObject:MakeColor( 40, 229, 109)];
319
- [m_colors addObject:MakeColor( 27, 229, 149)];
320
- [m_colors addObject:MakeColor( 49, 228, 189)];
321
- [m_colors addObject:MakeColor( 33, 228, 228)];
322
- [m_colors addObject:MakeColor( 53, 227, 255)];
323
-
324
- [m_colors addObject:MakeColor( 27, 254, 30)];
325
- [m_colors addObject:MakeColor( 30, 254, 103)];
326
- [m_colors addObject:MakeColor( 45, 254, 143)];
327
- [m_colors addObject:MakeColor( 38, 253, 182)];
328
- [m_colors addObject:MakeColor( 38, 253, 222)];
329
- [m_colors addObject:MakeColor( 42, 253, 252)];
330
-
331
- [m_colors addObject:MakeColor(140, 48, 40)];
332
- [m_colors addObject:MakeColor(136, 51, 136)];
333
- [m_colors addObject:MakeColor(135, 52, 177)];
334
- [m_colors addObject:MakeColor(134, 52, 217)];
335
- [m_colors addObject:MakeColor(135, 56, 248)];
336
- [m_colors addObject:MakeColor(134, 53, 255)];
337
-
338
- [m_colors addObject:MakeColor(125, 125, 38)];
339
- [m_colors addObject:MakeColor(124, 125, 125)];
340
- [m_colors addObject:MakeColor(122, 124, 166)];
341
- [m_colors addObject:MakeColor(123, 124, 207)];
342
- [m_colors addObject:MakeColor(123, 122, 247)];
343
- [m_colors addObject:MakeColor(124, 121, 255)];
344
-
345
- [m_colors addObject:MakeColor(119, 160, 35)];
346
- [m_colors addObject:MakeColor(117, 160, 120)];
347
- [m_colors addObject:MakeColor(117, 160, 160)];
348
- [m_colors addObject:MakeColor(115, 159, 201)];
349
- [m_colors addObject:MakeColor(116, 158, 240)];
350
- [m_colors addObject:MakeColor(117, 157, 255)];
351
-
352
- [m_colors addObject:MakeColor(113, 195, 39)];
353
- [m_colors addObject:MakeColor(110, 194, 114)];
354
- [m_colors addObject:MakeColor(111, 194, 154)];
355
- [m_colors addObject:MakeColor(108, 194, 194)];
356
- [m_colors addObject:MakeColor(109, 193, 234)];
357
- [m_colors addObject:MakeColor(108, 192, 255)];
358
-
359
- [m_colors addObject:MakeColor(105, 228, 30)];
360
- [m_colors addObject:MakeColor(103, 228, 109)];
361
- [m_colors addObject:MakeColor(105, 228, 148)];
362
- [m_colors addObject:MakeColor(100, 227, 188)];
363
- [m_colors addObject:MakeColor( 99, 227, 227)];
364
- [m_colors addObject:MakeColor( 99, 226, 253)];
365
-
366
- [m_colors addObject:MakeColor( 92, 253, 34)];
367
- [m_colors addObject:MakeColor( 96, 253, 103)];
368
- [m_colors addObject:MakeColor( 97, 253, 142)];
369
- [m_colors addObject:MakeColor( 88, 253, 182)];
370
- [m_colors addObject:MakeColor( 93, 253, 221)];
371
- [m_colors addObject:MakeColor( 88, 254, 251)];
372
-
373
- [m_colors addObject:MakeColor(177, 53, 34)];
374
- [m_colors addObject:MakeColor(174, 54, 131)];
375
- [m_colors addObject:MakeColor(172, 55, 172)];
376
- [m_colors addObject:MakeColor(171, 57, 213)];
377
- [m_colors addObject:MakeColor(170, 55, 249)];
378
- [m_colors addObject:MakeColor(170, 57, 255)];
379
-
380
- [m_colors addObject:MakeColor(165, 123, 37)];
381
- [m_colors addObject:MakeColor(163, 123, 123)];
382
- [m_colors addObject:MakeColor(162, 123, 164)];
383
- [m_colors addObject:MakeColor(161, 122, 205)];
384
- [m_colors addObject:MakeColor(161, 121, 241)];
385
- [m_colors addObject:MakeColor(161, 121, 255)];
386
-
387
- [m_colors addObject:MakeColor(158, 159, 33)];
388
- [m_colors addObject:MakeColor(157, 158, 118)];
389
- [m_colors addObject:MakeColor(157, 158, 159)];
390
- [m_colors addObject:MakeColor(155, 157, 199)];
391
- [m_colors addObject:MakeColor(155, 157, 239)];
392
- [m_colors addObject:MakeColor(154, 156, 255)];
393
-
394
- [m_colors addObject:MakeColor(152, 193, 40)];
395
- [m_colors addObject:MakeColor(151, 193, 113)];
396
- [m_colors addObject:MakeColor(150, 193, 153)];
397
- [m_colors addObject:MakeColor(150, 192, 193)];
398
- [m_colors addObject:MakeColor(148, 192, 232)];
399
- [m_colors addObject:MakeColor(149, 191, 253)];
400
-
401
- [m_colors addObject:MakeColor(146, 227, 28)];
402
- [m_colors addObject:MakeColor(144, 227, 108)];
403
- [m_colors addObject:MakeColor(144, 227, 147)];
404
- [m_colors addObject:MakeColor(144, 227, 187)];
405
- [m_colors addObject:MakeColor(142, 226, 227)];
406
- [m_colors addObject:MakeColor(142, 225, 252)];
407
-
408
- [m_colors addObject:MakeColor(138, 253, 36)];
409
- [m_colors addObject:MakeColor(137, 253, 102)];
410
- [m_colors addObject:MakeColor(136, 253, 141)];
411
- [m_colors addObject:MakeColor(138, 254, 181)];
412
- [m_colors addObject:MakeColor(135, 255, 220)];
413
- [m_colors addObject:MakeColor(133, 255, 250)];
414
-
415
- [m_colors addObject:MakeColor(214, 57, 30)];
416
- [m_colors addObject:MakeColor(211, 59, 126)];
417
- [m_colors addObject:MakeColor(209, 57, 168)];
418
- [m_colors addObject:MakeColor(208, 55, 208)];
419
- [m_colors addObject:MakeColor(207, 58, 247)];
420
- [m_colors addObject:MakeColor(206, 61, 255)];
421
-
422
- [m_colors addObject:MakeColor(204, 121, 32)];
423
- [m_colors addObject:MakeColor(202, 121, 121)];
424
- [m_colors addObject:MakeColor(201, 121, 161)];
425
- [m_colors addObject:MakeColor(200, 120, 202)];
426
- [m_colors addObject:MakeColor(200, 120, 241)];
427
- [m_colors addObject:MakeColor(198, 119, 255)];
428
-
429
- [m_colors addObject:MakeColor(198, 157, 37)];
430
- [m_colors addObject:MakeColor(196, 157, 116)];
431
- [m_colors addObject:MakeColor(195, 156, 157)];
432
- [m_colors addObject:MakeColor(195, 156, 197)];
433
- [m_colors addObject:MakeColor(194, 155, 236)];
434
- [m_colors addObject:MakeColor(193, 155, 255)];
435
-
436
- [m_colors addObject:MakeColor(191, 192, 36)];
437
- [m_colors addObject:MakeColor(190, 191, 112)];
438
- [m_colors addObject:MakeColor(189, 191, 152)];
439
- [m_colors addObject:MakeColor(189, 191, 191)];
440
- [m_colors addObject:MakeColor(188, 190, 230)];
441
- [m_colors addObject:MakeColor(187, 190, 253)];
442
-
443
- [m_colors addObject:MakeColor(185, 226, 28)];
444
- [m_colors addObject:MakeColor(184, 226, 106)];
445
- [m_colors addObject:MakeColor(183, 225, 146)];
446
- [m_colors addObject:MakeColor(183, 225, 186)];
447
- [m_colors addObject:MakeColor(182, 225, 225)];
448
- [m_colors addObject:MakeColor(181, 224, 252)];
449
-
450
- [m_colors addObject:MakeColor(178, 255, 35)];
451
- [m_colors addObject:MakeColor(178, 255, 101)];
452
- [m_colors addObject:MakeColor(177, 254, 141)];
453
- [m_colors addObject:MakeColor(176, 254, 180)];
454
- [m_colors addObject:MakeColor(176, 254, 220)];
455
- [m_colors addObject:MakeColor(175, 253, 249)];
456
-
457
- [m_colors addObject:MakeColor(247, 56, 30)];
458
- [m_colors addObject:MakeColor(245, 57, 122)];
459
- [m_colors addObject:MakeColor(243, 59, 163)];
460
- [m_colors addObject:MakeColor(244, 60, 204)];
461
- [m_colors addObject:MakeColor(242, 59, 241)];
462
- [m_colors addObject:MakeColor(240, 55, 255)];
463
-
464
- [m_colors addObject:MakeColor(241, 119, 36)];
465
- [m_colors addObject:MakeColor(240, 120, 118)];
466
- [m_colors addObject:MakeColor(238, 119, 158)];
467
- [m_colors addObject:MakeColor(237, 119, 199)];
468
- [m_colors addObject:MakeColor(237, 118, 238)];
469
- [m_colors addObject:MakeColor(236, 118, 255)];
470
-
471
- [m_colors addObject:MakeColor(235, 154, 36)];
472
- [m_colors addObject:MakeColor(235, 154, 114)];
473
- [m_colors addObject:MakeColor(234, 154, 154)];
474
- [m_colors addObject:MakeColor(232, 154, 194)];
475
- [m_colors addObject:MakeColor(232, 153, 234)];
476
- [m_colors addObject:MakeColor(232, 153, 255)];
477
-
478
- [m_colors addObject:MakeColor(230, 190, 30)];
479
- [m_colors addObject:MakeColor(229, 189, 110)];
480
- [m_colors addObject:MakeColor(228, 189, 150)];
481
- [m_colors addObject:MakeColor(227, 189, 190)];
482
- [m_colors addObject:MakeColor(227, 189, 229)];
483
- [m_colors addObject:MakeColor(226, 188, 255)];
484
-
485
- [m_colors addObject:MakeColor(224, 224, 35)];
486
- [m_colors addObject:MakeColor(223, 224, 105)];
487
- [m_colors addObject:MakeColor(222, 224, 144)];
488
- [m_colors addObject:MakeColor(222, 223, 184)];
489
- [m_colors addObject:MakeColor(222, 223, 224)];
490
- [m_colors addObject:MakeColor(220, 223, 253)];
491
-
492
- [m_colors addObject:MakeColor(217, 253, 28)];
493
- [m_colors addObject:MakeColor(217, 253, 99)];
494
- [m_colors addObject:MakeColor(216, 252, 139)];
495
- [m_colors addObject:MakeColor(216, 252, 179)];
496
- [m_colors addObject:MakeColor(215, 252, 218)];
497
- [m_colors addObject:MakeColor(215, 251, 250)];
498
-
499
- [m_colors addObject:MakeColor(255, 61, 30)];
500
- [m_colors addObject:MakeColor(255, 60, 118)];
501
- [m_colors addObject:MakeColor(255, 58, 159)];
502
- [m_colors addObject:MakeColor(255, 56, 199)];
503
- [m_colors addObject:MakeColor(255, 55, 238)];
504
- [m_colors addObject:MakeColor(255, 59, 255)];
505
-
506
- [m_colors addObject:MakeColor(255, 117, 29)];
507
- [m_colors addObject:MakeColor(255, 117, 115)];
508
- [m_colors addObject:MakeColor(255, 117, 155)];
509
- [m_colors addObject:MakeColor(255, 117, 195)];
510
- [m_colors addObject:MakeColor(255, 116, 235)];
511
- [m_colors addObject:MakeColor(254, 116, 255)];
512
-
513
- [m_colors addObject:MakeColor(255, 152, 27)];
514
- [m_colors addObject:MakeColor(255, 152, 111)];
515
- [m_colors addObject:MakeColor(254, 152, 152)];
516
- [m_colors addObject:MakeColor(255, 152, 192)];
517
- [m_colors addObject:MakeColor(254, 151, 231)];
518
- [m_colors addObject:MakeColor(253, 151, 253)];
519
-
520
- [m_colors addObject:MakeColor(255, 187, 33)];
521
- [m_colors addObject:MakeColor(253, 187, 107)];
522
- [m_colors addObject:MakeColor(252, 187, 148)];
523
- [m_colors addObject:MakeColor(253, 187, 187)];
524
- [m_colors addObject:MakeColor(254, 187, 227)];
525
- [m_colors addObject:MakeColor(252, 186, 252)];
526
-
527
- [m_colors addObject:MakeColor(252, 222, 34)];
528
- [m_colors addObject:MakeColor(251, 222, 103)];
529
- [m_colors addObject:MakeColor(251, 222, 143)];
530
- [m_colors addObject:MakeColor(250, 222, 182)];
531
- [m_colors addObject:MakeColor(251, 221, 222)];
532
- [m_colors addObject:MakeColor(252, 221, 252)];
533
-
534
- [m_colors addObject:MakeColor(251, 252, 15)];
535
- [m_colors addObject:MakeColor(251, 252, 97)];
536
- [m_colors addObject:MakeColor(249, 252, 137)];
537
- [m_colors addObject:MakeColor(247, 252, 177)];
538
- [m_colors addObject:MakeColor(247, 253, 217)];
539
- [m_colors addObject:MakeColor(254, 255, 255)];
540
-
541
- // Grayscale
542
-
543
- [m_colors addObject:MakeColor( 52, 53, 53)];
544
- [m_colors addObject:MakeColor( 57, 58, 59)];
545
- [m_colors addObject:MakeColor( 66, 67, 67)];
546
- [m_colors addObject:MakeColor( 75, 76, 76)];
547
- [m_colors addObject:MakeColor( 83, 85, 85)];
548
- [m_colors addObject:MakeColor( 92, 93, 94)];
549
-
550
- [m_colors addObject:MakeColor(101, 102, 102)];
551
- [m_colors addObject:MakeColor(109, 111, 111)];
552
- [m_colors addObject:MakeColor(118, 119, 119)];
553
- [m_colors addObject:MakeColor(126, 127, 128)];
554
- [m_colors addObject:MakeColor(134, 136, 136)];
555
- [m_colors addObject:MakeColor(143, 144, 145)];
556
-
557
- [m_colors addObject:MakeColor(151, 152, 153)];
558
- [m_colors addObject:MakeColor(159, 161, 161)];
559
- [m_colors addObject:MakeColor(167, 169, 169)];
560
- [m_colors addObject:MakeColor(176, 177, 177)];
561
- [m_colors addObject:MakeColor(184, 185, 186)];
562
- [m_colors addObject:MakeColor(192, 193, 194)];
563
-
564
- [m_colors addObject:MakeColor(200, 201, 202)];
565
- [m_colors addObject:MakeColor(208, 209, 210)];
566
- [m_colors addObject:MakeColor(216, 218, 218)];
567
- [m_colors addObject:MakeColor(224, 226, 226)];
568
- [m_colors addObject:MakeColor(232, 234, 234)];
569
- [m_colors addObject:MakeColor(240, 242, 242)];
570
-
571
- // Color codes
572
-
573
- int index = 16;
574
-
575
- while (index < 256)
576
- {
577
- [m_codes_fg addObject:[NSString stringWithFormat:@"38;5;%dm", index]];
578
- [m_codes_bg addObject:[NSString stringWithFormat:@"48;5;%dm", index]];
579
-
580
- index++;
581
- }
582
-
583
- #else
584
-
585
- // Standard xterm colors:
586
- //
587
- // These are the colors xterm shells use in xterm-256color mode.
588
- // In this mode, the shell supports 256 different colors, specified by 256 color codes.
589
- //
590
- // The first 16 color codes map to the original 16 color codes supported by the earlier xterm-color mode.
591
- // These are generally configurable, and thus we ignore them for the purposes of mapping,
592
- // as we can't rely on them being constant. They are largely duplicated anyway.
593
- //
594
- // The next 216 color codes are designed to run the spectrum, with several shades of every color.
595
- // The last 24 color codes represent a grayscale.
596
- //
597
- // While the color codes are standardized, the actual RGB values for each color code is not.
598
- // However most standard xterms follow a well known color chart,
599
- // which can easily be calculated using the simple formula below.
600
- //
601
- // More information about ansi escape codes can be found online.
602
- // http://en.wikipedia.org/wiki/ANSI_escape_code
603
-
604
- int index = 16;
605
-
606
- int r; // red
607
- int g; // green
608
- int b; // blue
609
-
610
- int ri; // r increment
611
- int gi; // g increment
612
- int bi; // b increment
613
-
614
- // Calculate xterm colors (using standard algorithm)
615
-
616
- int r = 0;
617
- int g = 0;
618
- int b = 0;
619
-
620
- for (ri = 0; ri < 6; ri++)
621
- {
622
- r = (ri == 0) ? 0 : 95 + (40 * (ri - 1));
623
-
624
- for (gi = 0; gi < 6; gi++)
625
- {
626
- g = (gi == 0) ? 0 : 95 + (40 * (gi - 1));
627
-
628
- for (bi = 0; bi < 6; bi++)
629
- {
630
- b = (bi == 0) ? 0 : 95 + (40 * (bi - 1));
631
-
632
- [m_codes_fg addObject:[NSString stringWithFormat:@"38;5;%dm", index]];
633
- [m_codes_bg addObject:[NSString stringWithFormat:@"48;5;%dm", index]];
634
- [m_colors addObject:MakeColor(r, g, b)];
635
-
636
- index++;
637
- }
638
- }
639
- }
640
-
641
- // Calculate xterm grayscale (using standard algorithm)
642
-
643
- r = 8;
644
- g = 8;
645
- b = 8;
646
-
647
- while (index < 256)
648
- {
649
- [m_codes_fg addObject:[NSString stringWithFormat:@"38;5;%dm", index]];
650
- [m_codes_bg addObject:[NSString stringWithFormat:@"48;5;%dm", index]];
651
- [m_colors addObject:MakeColor(r, g, b)];
652
-
653
- r += 10;
654
- g += 10;
655
- b += 10;
656
-
657
- index++;
658
- }
659
-
660
- #endif
661
-
662
- codes_fg = [m_codes_fg copy];
663
- codes_bg = [m_codes_bg copy];
664
- colors = [m_colors copy];
665
-
666
- NSAssert([codes_fg count] == [codes_bg count], @"Invalid colors/codes array(s)");
667
- NSAssert([codes_fg count] == [colors count], @"Invalid colors/codes array(s)");
255
+ if (codes_fg || codes_bg || colors) return;
256
+
257
+ NSMutableArray *m_codes_fg = [NSMutableArray arrayWithCapacity:(256-16)];
258
+ NSMutableArray *m_codes_bg = [NSMutableArray arrayWithCapacity:(256-16)];
259
+ NSMutableArray *m_colors = [NSMutableArray arrayWithCapacity:(256-16)];
260
+
261
+ #if MAP_TO_TERMINAL_APP_COLORS
262
+
263
+ // Standard Terminal.app colors:
264
+ //
265
+ // These are the colors the Terminal.app uses in xterm-256color mode.
266
+ // In this mode, the terminal supports 256 different colors, specified by 256 color codes.
267
+ //
268
+ // The first 16 color codes map to the original 16 color codes supported by the earlier xterm-color mode.
269
+ // These are actually configurable, and thus we ignore them for the purposes of mapping,
270
+ // as we can't rely on them being constant. They are largely duplicated anyway.
271
+ //
272
+ // The next 216 color codes are designed to run the spectrum, with several shades of every color.
273
+ // While the color codes are standardized, the actual RGB values for each color code is not.
274
+ // Apple's Terminal.app uses different RGB values from that of a standard xterm.
275
+ // Apple's choices in colors are designed to be a little nicer on the eyes.
276
+ //
277
+ // The last 24 color codes represent a grayscale.
278
+ //
279
+ // Unfortunately, unlike the standard xterm color chart,
280
+ // Apple's RGB values cannot be calculated using a simple formula (at least not that I know of).
281
+ // Also, I don't know of any ways to programmatically query the shell for the RGB values.
282
+ // So this big giant color chart had to be made by hand.
283
+ //
284
+ // More information about ansi escape codes can be found online.
285
+ // http://en.wikipedia.org/wiki/ANSI_escape_code
286
+
287
+ // Colors
288
+
289
+ [m_colors addObject:MakeColor( 47, 49, 49)];
290
+ [m_colors addObject:MakeColor( 60, 42, 144)];
291
+ [m_colors addObject:MakeColor( 66, 44, 183)];
292
+ [m_colors addObject:MakeColor( 73, 46, 222)];
293
+ [m_colors addObject:MakeColor( 81, 50, 253)];
294
+ [m_colors addObject:MakeColor( 88, 51, 255)];
295
+
296
+ [m_colors addObject:MakeColor( 42, 128, 37)];
297
+ [m_colors addObject:MakeColor( 42, 127, 128)];
298
+ [m_colors addObject:MakeColor( 44, 126, 169)];
299
+ [m_colors addObject:MakeColor( 56, 125, 209)];
300
+ [m_colors addObject:MakeColor( 59, 124, 245)];
301
+ [m_colors addObject:MakeColor( 66, 123, 255)];
302
+
303
+ [m_colors addObject:MakeColor( 51, 163, 41)];
304
+ [m_colors addObject:MakeColor( 39, 162, 121)];
305
+ [m_colors addObject:MakeColor( 42, 161, 162)];
306
+ [m_colors addObject:MakeColor( 53, 160, 202)];
307
+ [m_colors addObject:MakeColor( 45, 159, 240)];
308
+ [m_colors addObject:MakeColor( 58, 158, 255)];
309
+
310
+ [m_colors addObject:MakeColor( 31, 196, 37)];
311
+ [m_colors addObject:MakeColor( 48, 196, 115)];
312
+ [m_colors addObject:MakeColor( 39, 195, 155)];
313
+ [m_colors addObject:MakeColor( 49, 195, 195)];
314
+ [m_colors addObject:MakeColor( 32, 194, 235)];
315
+ [m_colors addObject:MakeColor( 53, 193, 255)];
316
+
317
+ [m_colors addObject:MakeColor( 50, 229, 35)];
318
+ [m_colors addObject:MakeColor( 40, 229, 109)];
319
+ [m_colors addObject:MakeColor( 27, 229, 149)];
320
+ [m_colors addObject:MakeColor( 49, 228, 189)];
321
+ [m_colors addObject:MakeColor( 33, 228, 228)];
322
+ [m_colors addObject:MakeColor( 53, 227, 255)];
323
+
324
+ [m_colors addObject:MakeColor( 27, 254, 30)];
325
+ [m_colors addObject:MakeColor( 30, 254, 103)];
326
+ [m_colors addObject:MakeColor( 45, 254, 143)];
327
+ [m_colors addObject:MakeColor( 38, 253, 182)];
328
+ [m_colors addObject:MakeColor( 38, 253, 222)];
329
+ [m_colors addObject:MakeColor( 42, 253, 252)];
330
+
331
+ [m_colors addObject:MakeColor(140, 48, 40)];
332
+ [m_colors addObject:MakeColor(136, 51, 136)];
333
+ [m_colors addObject:MakeColor(135, 52, 177)];
334
+ [m_colors addObject:MakeColor(134, 52, 217)];
335
+ [m_colors addObject:MakeColor(135, 56, 248)];
336
+ [m_colors addObject:MakeColor(134, 53, 255)];
337
+
338
+ [m_colors addObject:MakeColor(125, 125, 38)];
339
+ [m_colors addObject:MakeColor(124, 125, 125)];
340
+ [m_colors addObject:MakeColor(122, 124, 166)];
341
+ [m_colors addObject:MakeColor(123, 124, 207)];
342
+ [m_colors addObject:MakeColor(123, 122, 247)];
343
+ [m_colors addObject:MakeColor(124, 121, 255)];
344
+
345
+ [m_colors addObject:MakeColor(119, 160, 35)];
346
+ [m_colors addObject:MakeColor(117, 160, 120)];
347
+ [m_colors addObject:MakeColor(117, 160, 160)];
348
+ [m_colors addObject:MakeColor(115, 159, 201)];
349
+ [m_colors addObject:MakeColor(116, 158, 240)];
350
+ [m_colors addObject:MakeColor(117, 157, 255)];
351
+
352
+ [m_colors addObject:MakeColor(113, 195, 39)];
353
+ [m_colors addObject:MakeColor(110, 194, 114)];
354
+ [m_colors addObject:MakeColor(111, 194, 154)];
355
+ [m_colors addObject:MakeColor(108, 194, 194)];
356
+ [m_colors addObject:MakeColor(109, 193, 234)];
357
+ [m_colors addObject:MakeColor(108, 192, 255)];
358
+
359
+ [m_colors addObject:MakeColor(105, 228, 30)];
360
+ [m_colors addObject:MakeColor(103, 228, 109)];
361
+ [m_colors addObject:MakeColor(105, 228, 148)];
362
+ [m_colors addObject:MakeColor(100, 227, 188)];
363
+ [m_colors addObject:MakeColor( 99, 227, 227)];
364
+ [m_colors addObject:MakeColor( 99, 226, 253)];
365
+
366
+ [m_colors addObject:MakeColor( 92, 253, 34)];
367
+ [m_colors addObject:MakeColor( 96, 253, 103)];
368
+ [m_colors addObject:MakeColor( 97, 253, 142)];
369
+ [m_colors addObject:MakeColor( 88, 253, 182)];
370
+ [m_colors addObject:MakeColor( 93, 253, 221)];
371
+ [m_colors addObject:MakeColor( 88, 254, 251)];
372
+
373
+ [m_colors addObject:MakeColor(177, 53, 34)];
374
+ [m_colors addObject:MakeColor(174, 54, 131)];
375
+ [m_colors addObject:MakeColor(172, 55, 172)];
376
+ [m_colors addObject:MakeColor(171, 57, 213)];
377
+ [m_colors addObject:MakeColor(170, 55, 249)];
378
+ [m_colors addObject:MakeColor(170, 57, 255)];
379
+
380
+ [m_colors addObject:MakeColor(165, 123, 37)];
381
+ [m_colors addObject:MakeColor(163, 123, 123)];
382
+ [m_colors addObject:MakeColor(162, 123, 164)];
383
+ [m_colors addObject:MakeColor(161, 122, 205)];
384
+ [m_colors addObject:MakeColor(161, 121, 241)];
385
+ [m_colors addObject:MakeColor(161, 121, 255)];
386
+
387
+ [m_colors addObject:MakeColor(158, 159, 33)];
388
+ [m_colors addObject:MakeColor(157, 158, 118)];
389
+ [m_colors addObject:MakeColor(157, 158, 159)];
390
+ [m_colors addObject:MakeColor(155, 157, 199)];
391
+ [m_colors addObject:MakeColor(155, 157, 239)];
392
+ [m_colors addObject:MakeColor(154, 156, 255)];
393
+
394
+ [m_colors addObject:MakeColor(152, 193, 40)];
395
+ [m_colors addObject:MakeColor(151, 193, 113)];
396
+ [m_colors addObject:MakeColor(150, 193, 153)];
397
+ [m_colors addObject:MakeColor(150, 192, 193)];
398
+ [m_colors addObject:MakeColor(148, 192, 232)];
399
+ [m_colors addObject:MakeColor(149, 191, 253)];
400
+
401
+ [m_colors addObject:MakeColor(146, 227, 28)];
402
+ [m_colors addObject:MakeColor(144, 227, 108)];
403
+ [m_colors addObject:MakeColor(144, 227, 147)];
404
+ [m_colors addObject:MakeColor(144, 227, 187)];
405
+ [m_colors addObject:MakeColor(142, 226, 227)];
406
+ [m_colors addObject:MakeColor(142, 225, 252)];
407
+
408
+ [m_colors addObject:MakeColor(138, 253, 36)];
409
+ [m_colors addObject:MakeColor(137, 253, 102)];
410
+ [m_colors addObject:MakeColor(136, 253, 141)];
411
+ [m_colors addObject:MakeColor(138, 254, 181)];
412
+ [m_colors addObject:MakeColor(135, 255, 220)];
413
+ [m_colors addObject:MakeColor(133, 255, 250)];
414
+
415
+ [m_colors addObject:MakeColor(214, 57, 30)];
416
+ [m_colors addObject:MakeColor(211, 59, 126)];
417
+ [m_colors addObject:MakeColor(209, 57, 168)];
418
+ [m_colors addObject:MakeColor(208, 55, 208)];
419
+ [m_colors addObject:MakeColor(207, 58, 247)];
420
+ [m_colors addObject:MakeColor(206, 61, 255)];
421
+
422
+ [m_colors addObject:MakeColor(204, 121, 32)];
423
+ [m_colors addObject:MakeColor(202, 121, 121)];
424
+ [m_colors addObject:MakeColor(201, 121, 161)];
425
+ [m_colors addObject:MakeColor(200, 120, 202)];
426
+ [m_colors addObject:MakeColor(200, 120, 241)];
427
+ [m_colors addObject:MakeColor(198, 119, 255)];
428
+
429
+ [m_colors addObject:MakeColor(198, 157, 37)];
430
+ [m_colors addObject:MakeColor(196, 157, 116)];
431
+ [m_colors addObject:MakeColor(195, 156, 157)];
432
+ [m_colors addObject:MakeColor(195, 156, 197)];
433
+ [m_colors addObject:MakeColor(194, 155, 236)];
434
+ [m_colors addObject:MakeColor(193, 155, 255)];
435
+
436
+ [m_colors addObject:MakeColor(191, 192, 36)];
437
+ [m_colors addObject:MakeColor(190, 191, 112)];
438
+ [m_colors addObject:MakeColor(189, 191, 152)];
439
+ [m_colors addObject:MakeColor(189, 191, 191)];
440
+ [m_colors addObject:MakeColor(188, 190, 230)];
441
+ [m_colors addObject:MakeColor(187, 190, 253)];
442
+
443
+ [m_colors addObject:MakeColor(185, 226, 28)];
444
+ [m_colors addObject:MakeColor(184, 226, 106)];
445
+ [m_colors addObject:MakeColor(183, 225, 146)];
446
+ [m_colors addObject:MakeColor(183, 225, 186)];
447
+ [m_colors addObject:MakeColor(182, 225, 225)];
448
+ [m_colors addObject:MakeColor(181, 224, 252)];
449
+
450
+ [m_colors addObject:MakeColor(178, 255, 35)];
451
+ [m_colors addObject:MakeColor(178, 255, 101)];
452
+ [m_colors addObject:MakeColor(177, 254, 141)];
453
+ [m_colors addObject:MakeColor(176, 254, 180)];
454
+ [m_colors addObject:MakeColor(176, 254, 220)];
455
+ [m_colors addObject:MakeColor(175, 253, 249)];
456
+
457
+ [m_colors addObject:MakeColor(247, 56, 30)];
458
+ [m_colors addObject:MakeColor(245, 57, 122)];
459
+ [m_colors addObject:MakeColor(243, 59, 163)];
460
+ [m_colors addObject:MakeColor(244, 60, 204)];
461
+ [m_colors addObject:MakeColor(242, 59, 241)];
462
+ [m_colors addObject:MakeColor(240, 55, 255)];
463
+
464
+ [m_colors addObject:MakeColor(241, 119, 36)];
465
+ [m_colors addObject:MakeColor(240, 120, 118)];
466
+ [m_colors addObject:MakeColor(238, 119, 158)];
467
+ [m_colors addObject:MakeColor(237, 119, 199)];
468
+ [m_colors addObject:MakeColor(237, 118, 238)];
469
+ [m_colors addObject:MakeColor(236, 118, 255)];
470
+
471
+ [m_colors addObject:MakeColor(235, 154, 36)];
472
+ [m_colors addObject:MakeColor(235, 154, 114)];
473
+ [m_colors addObject:MakeColor(234, 154, 154)];
474
+ [m_colors addObject:MakeColor(232, 154, 194)];
475
+ [m_colors addObject:MakeColor(232, 153, 234)];
476
+ [m_colors addObject:MakeColor(232, 153, 255)];
477
+
478
+ [m_colors addObject:MakeColor(230, 190, 30)];
479
+ [m_colors addObject:MakeColor(229, 189, 110)];
480
+ [m_colors addObject:MakeColor(228, 189, 150)];
481
+ [m_colors addObject:MakeColor(227, 189, 190)];
482
+ [m_colors addObject:MakeColor(227, 189, 229)];
483
+ [m_colors addObject:MakeColor(226, 188, 255)];
484
+
485
+ [m_colors addObject:MakeColor(224, 224, 35)];
486
+ [m_colors addObject:MakeColor(223, 224, 105)];
487
+ [m_colors addObject:MakeColor(222, 224, 144)];
488
+ [m_colors addObject:MakeColor(222, 223, 184)];
489
+ [m_colors addObject:MakeColor(222, 223, 224)];
490
+ [m_colors addObject:MakeColor(220, 223, 253)];
491
+
492
+ [m_colors addObject:MakeColor(217, 253, 28)];
493
+ [m_colors addObject:MakeColor(217, 253, 99)];
494
+ [m_colors addObject:MakeColor(216, 252, 139)];
495
+ [m_colors addObject:MakeColor(216, 252, 179)];
496
+ [m_colors addObject:MakeColor(215, 252, 218)];
497
+ [m_colors addObject:MakeColor(215, 251, 250)];
498
+
499
+ [m_colors addObject:MakeColor(255, 61, 30)];
500
+ [m_colors addObject:MakeColor(255, 60, 118)];
501
+ [m_colors addObject:MakeColor(255, 58, 159)];
502
+ [m_colors addObject:MakeColor(255, 56, 199)];
503
+ [m_colors addObject:MakeColor(255, 55, 238)];
504
+ [m_colors addObject:MakeColor(255, 59, 255)];
505
+
506
+ [m_colors addObject:MakeColor(255, 117, 29)];
507
+ [m_colors addObject:MakeColor(255, 117, 115)];
508
+ [m_colors addObject:MakeColor(255, 117, 155)];
509
+ [m_colors addObject:MakeColor(255, 117, 195)];
510
+ [m_colors addObject:MakeColor(255, 116, 235)];
511
+ [m_colors addObject:MakeColor(254, 116, 255)];
512
+
513
+ [m_colors addObject:MakeColor(255, 152, 27)];
514
+ [m_colors addObject:MakeColor(255, 152, 111)];
515
+ [m_colors addObject:MakeColor(254, 152, 152)];
516
+ [m_colors addObject:MakeColor(255, 152, 192)];
517
+ [m_colors addObject:MakeColor(254, 151, 231)];
518
+ [m_colors addObject:MakeColor(253, 151, 253)];
519
+
520
+ [m_colors addObject:MakeColor(255, 187, 33)];
521
+ [m_colors addObject:MakeColor(253, 187, 107)];
522
+ [m_colors addObject:MakeColor(252, 187, 148)];
523
+ [m_colors addObject:MakeColor(253, 187, 187)];
524
+ [m_colors addObject:MakeColor(254, 187, 227)];
525
+ [m_colors addObject:MakeColor(252, 186, 252)];
526
+
527
+ [m_colors addObject:MakeColor(252, 222, 34)];
528
+ [m_colors addObject:MakeColor(251, 222, 103)];
529
+ [m_colors addObject:MakeColor(251, 222, 143)];
530
+ [m_colors addObject:MakeColor(250, 222, 182)];
531
+ [m_colors addObject:MakeColor(251, 221, 222)];
532
+ [m_colors addObject:MakeColor(252, 221, 252)];
533
+
534
+ [m_colors addObject:MakeColor(251, 252, 15)];
535
+ [m_colors addObject:MakeColor(251, 252, 97)];
536
+ [m_colors addObject:MakeColor(249, 252, 137)];
537
+ [m_colors addObject:MakeColor(247, 252, 177)];
538
+ [m_colors addObject:MakeColor(247, 253, 217)];
539
+ [m_colors addObject:MakeColor(254, 255, 255)];
540
+
541
+ // Grayscale
542
+
543
+ [m_colors addObject:MakeColor( 52, 53, 53)];
544
+ [m_colors addObject:MakeColor( 57, 58, 59)];
545
+ [m_colors addObject:MakeColor( 66, 67, 67)];
546
+ [m_colors addObject:MakeColor( 75, 76, 76)];
547
+ [m_colors addObject:MakeColor( 83, 85, 85)];
548
+ [m_colors addObject:MakeColor( 92, 93, 94)];
549
+
550
+ [m_colors addObject:MakeColor(101, 102, 102)];
551
+ [m_colors addObject:MakeColor(109, 111, 111)];
552
+ [m_colors addObject:MakeColor(118, 119, 119)];
553
+ [m_colors addObject:MakeColor(126, 127, 128)];
554
+ [m_colors addObject:MakeColor(134, 136, 136)];
555
+ [m_colors addObject:MakeColor(143, 144, 145)];
556
+
557
+ [m_colors addObject:MakeColor(151, 152, 153)];
558
+ [m_colors addObject:MakeColor(159, 161, 161)];
559
+ [m_colors addObject:MakeColor(167, 169, 169)];
560
+ [m_colors addObject:MakeColor(176, 177, 177)];
561
+ [m_colors addObject:MakeColor(184, 185, 186)];
562
+ [m_colors addObject:MakeColor(192, 193, 194)];
563
+
564
+ [m_colors addObject:MakeColor(200, 201, 202)];
565
+ [m_colors addObject:MakeColor(208, 209, 210)];
566
+ [m_colors addObject:MakeColor(216, 218, 218)];
567
+ [m_colors addObject:MakeColor(224, 226, 226)];
568
+ [m_colors addObject:MakeColor(232, 234, 234)];
569
+ [m_colors addObject:MakeColor(240, 242, 242)];
570
+
571
+ // Color codes
572
+
573
+ int index = 16;
574
+
575
+ while (index < 256)
576
+ {
577
+ [m_codes_fg addObject:[NSString stringWithFormat:@"38;5;%dm", index]];
578
+ [m_codes_bg addObject:[NSString stringWithFormat:@"48;5;%dm", index]];
579
+
580
+ index++;
581
+ }
582
+
583
+ #else
584
+
585
+ // Standard xterm colors:
586
+ //
587
+ // These are the colors xterm shells use in xterm-256color mode.
588
+ // In this mode, the shell supports 256 different colors, specified by 256 color codes.
589
+ //
590
+ // The first 16 color codes map to the original 16 color codes supported by the earlier xterm-color mode.
591
+ // These are generally configurable, and thus we ignore them for the purposes of mapping,
592
+ // as we can't rely on them being constant. They are largely duplicated anyway.
593
+ //
594
+ // The next 216 color codes are designed to run the spectrum, with several shades of every color.
595
+ // The last 24 color codes represent a grayscale.
596
+ //
597
+ // While the color codes are standardized, the actual RGB values for each color code is not.
598
+ // However most standard xterms follow a well known color chart,
599
+ // which can easily be calculated using the simple formula below.
600
+ //
601
+ // More information about ansi escape codes can be found online.
602
+ // http://en.wikipedia.org/wiki/ANSI_escape_code
603
+
604
+ int index = 16;
605
+
606
+ int r; // red
607
+ int g; // green
608
+ int b; // blue
609
+
610
+ int ri; // r increment
611
+ int gi; // g increment
612
+ int bi; // b increment
613
+
614
+ // Calculate xterm colors (using standard algorithm)
615
+
616
+ int r = 0;
617
+ int g = 0;
618
+ int b = 0;
619
+
620
+ for (ri = 0; ri < 6; ri++)
621
+ {
622
+ r = (ri == 0) ? 0 : 95 + (40 * (ri - 1));
623
+
624
+ for (gi = 0; gi < 6; gi++)
625
+ {
626
+ g = (gi == 0) ? 0 : 95 + (40 * (gi - 1));
627
+
628
+ for (bi = 0; bi < 6; bi++)
629
+ {
630
+ b = (bi == 0) ? 0 : 95 + (40 * (bi - 1));
631
+
632
+ [m_codes_fg addObject:[NSString stringWithFormat:@"38;5;%dm", index]];
633
+ [m_codes_bg addObject:[NSString stringWithFormat:@"48;5;%dm", index]];
634
+ [m_colors addObject:MakeColor(r, g, b)];
635
+
636
+ index++;
637
+ }
638
+ }
639
+ }
640
+
641
+ // Calculate xterm grayscale (using standard algorithm)
642
+
643
+ r = 8;
644
+ g = 8;
645
+ b = 8;
646
+
647
+ while (index < 256)
648
+ {
649
+ [m_codes_fg addObject:[NSString stringWithFormat:@"38;5;%dm", index]];
650
+ [m_codes_bg addObject:[NSString stringWithFormat:@"48;5;%dm", index]];
651
+ [m_colors addObject:MakeColor(r, g, b)];
652
+
653
+ r += 10;
654
+ g += 10;
655
+ b += 10;
656
+
657
+ index++;
658
+ }
659
+
660
+ #endif
661
+
662
+ codes_fg = [m_codes_fg copy];
663
+ codes_bg = [m_codes_bg copy];
664
+ colors = [m_colors copy];
665
+
666
+ NSAssert([codes_fg count] == [codes_bg count], @"Invalid colors/codes array(s)");
667
+ NSAssert([codes_fg count] == [colors count], @"Invalid colors/codes array(s)");
668
668
  }
669
669
 
670
670
  + (void)getRed:(CGFloat *)rPtr green:(CGFloat *)gPtr blue:(CGFloat *)bPtr fromColor:(OSColor *)color
671
671
  {
672
- #if TARGET_OS_IPHONE
673
-
674
- // iOS
675
-
676
- if ([color respondsToSelector:@selector(getRed:green:blue:alpha:)])
677
- {
678
- [color getRed:rPtr green:gPtr blue:bPtr alpha:NULL];
679
- }
680
- else
681
- {
682
- // The method getRed:green:blue:alpha: was only available starting iOS 5.
683
- // So in iOS 4 and earlier, we have to jump through hoops.
684
-
685
- CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
686
-
687
- unsigned char pixel[4];
688
- CGContextRef context = CGBitmapContextCreate(&pixel, 1, 1, 8, 4, rgbColorSpace, kCGImageAlphaNoneSkipLast);
689
-
690
- CGContextSetFillColorWithColor(context, [color CGColor]);
691
- CGContextFillRect(context, CGRectMake(0, 0, 1, 1));
692
-
693
- if (rPtr) { *rPtr = pixel[0] / 255.0f; }
694
- if (gPtr) { *gPtr = pixel[1] / 255.0f; }
695
- if (bPtr) { *bPtr = pixel[2] / 255.0f; }
696
-
697
- CGContextRelease(context);
698
- CGColorSpaceRelease(rgbColorSpace);
699
- }
700
-
701
- #else
702
-
703
- // Mac OS X
704
-
705
- [color getRed:rPtr green:gPtr blue:bPtr alpha:NULL];
706
-
707
- #endif
672
+ #if TARGET_OS_IPHONE
673
+
674
+ // iOS
675
+
676
+ BOOL done = NO;
677
+
678
+ if ([color respondsToSelector:@selector(getRed:green:blue:alpha:)])
679
+ {
680
+ done = [color getRed:rPtr green:gPtr blue:bPtr alpha:NULL];
681
+ }
682
+
683
+ if (!done)
684
+ {
685
+ // The method getRed:green:blue:alpha: was only available starting iOS 5.
686
+ // So in iOS 4 and earlier, we have to jump through hoops.
687
+
688
+ CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
689
+
690
+ unsigned char pixel[4];
691
+ CGContextRef context = CGBitmapContextCreate(&pixel, 1, 1, 8, 4, rgbColorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaNoneSkipLast);
692
+
693
+ CGContextSetFillColorWithColor(context, [color CGColor]);
694
+ CGContextFillRect(context, CGRectMake(0, 0, 1, 1));
695
+
696
+ if (rPtr) { *rPtr = pixel[0] / 255.0f; }
697
+ if (gPtr) { *gPtr = pixel[1] / 255.0f; }
698
+ if (bPtr) { *bPtr = pixel[2] / 255.0f; }
699
+
700
+ CGContextRelease(context);
701
+ CGColorSpaceRelease(rgbColorSpace);
702
+ }
703
+
704
+ #elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
705
+
706
+ // OS X with AppKit
707
+
708
+ NSColor *safeColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
709
+
710
+ [safeColor getRed:rPtr green:gPtr blue:bPtr alpha:NULL];
711
+
712
+ #else
713
+
714
+ // OS X without AppKit
715
+
716
+ [color getRed:rPtr green:gPtr blue:bPtr alpha:NULL];
717
+
718
+ #endif
708
719
  }
709
720
 
710
721
  /**
@@ -717,41 +728,41 @@ static DDTTYLogger *sharedInstance;
717
728
  **/
718
729
  + (NSUInteger)codeIndexForColor:(OSColor *)inColor
719
730
  {
720
- CGFloat inR, inG, inB;
721
- [self getRed:&inR green:&inG blue:&inB fromColor:inColor];
722
-
723
- NSUInteger bestIndex = 0;
724
- CGFloat lowestDistance = 100.0f;
725
-
726
- NSUInteger i = 0;
727
- for (OSColor *color in colors)
728
- {
729
- // Calculate Euclidean distance (lower value means closer to given color)
730
-
731
- CGFloat r, g, b;
732
- [self getRed:&r green:&g blue:&b fromColor:color];
733
-
734
- #if CGFLOAT_IS_DOUBLE
735
- CGFloat distance = sqrt(pow(r-inR, 2.0) + pow(g-inG, 2.0) + pow(b-inB, 2.0));
736
- #else
737
- CGFloat distance = sqrtf(powf(r-inR, 2.0f) + powf(g-inG, 2.0f) + powf(b-inB, 2.0f));
738
- #endif
739
-
740
- NSLogVerbose(@"DDTTYLogger: %3lu : %.3f,%.3f,%.3f & %.3f,%.3f,%.3f = %.6f",
741
- (unsigned long)i, inR, inG, inB, r, g, b, distance);
742
-
743
- if (distance < lowestDistance)
744
- {
745
- bestIndex = i;
746
- lowestDistance = distance;
747
-
748
- NSLogVerbose(@"DDTTYLogger: New best index = %lu", (unsigned long)bestIndex);
749
- }
750
-
751
- i++;
752
- }
753
-
754
- return bestIndex;
731
+ CGFloat inR, inG, inB;
732
+ [self getRed:&inR green:&inG blue:&inB fromColor:inColor];
733
+
734
+ NSUInteger bestIndex = 0;
735
+ CGFloat lowestDistance = 100.0f;
736
+
737
+ NSUInteger i = 0;
738
+ for (OSColor *color in colors)
739
+ {
740
+ // Calculate Euclidean distance (lower value means closer to given color)
741
+
742
+ CGFloat r, g, b;
743
+ [self getRed:&r green:&g blue:&b fromColor:color];
744
+
745
+ #if CGFLOAT_IS_DOUBLE
746
+ CGFloat distance = sqrt(pow(r-inR, 2.0) + pow(g-inG, 2.0) + pow(b-inB, 2.0));
747
+ #else
748
+ CGFloat distance = sqrtf(powf(r-inR, 2.0f) + powf(g-inG, 2.0f) + powf(b-inB, 2.0f));
749
+ #endif
750
+
751
+ NSLogVerbose(@"DDTTYLogger: %3lu : %.3f,%.3f,%.3f & %.3f,%.3f,%.3f = %.6f",
752
+ (unsigned long)i, inR, inG, inB, r, g, b, distance);
753
+
754
+ if (distance < lowestDistance)
755
+ {
756
+ bestIndex = i;
757
+ lowestDistance = distance;
758
+
759
+ NSLogVerbose(@"DDTTYLogger: New best index = %lu", (unsigned long)bestIndex);
760
+ }
761
+
762
+ i++;
763
+ }
764
+
765
+ return bestIndex;
755
766
  }
756
767
 
757
768
  /**
@@ -764,592 +775,620 @@ static DDTTYLogger *sharedInstance;
764
775
  **/
765
776
  + (void)initialize
766
777
  {
767
- static BOOL initialized = NO;
768
- if (!initialized)
769
- {
770
- initialized = YES;
771
-
772
- char *term = getenv("TERM");
773
- if (term)
774
- {
775
- if (strcasestr(term, "color") != NULL)
776
- {
777
- isaColorTTY = YES;
778
- isaColor256TTY = (strcasestr(term, "256") != NULL);
779
-
780
- if (isaColor256TTY)
781
- [self initialize_colors_256];
782
- else
783
- [self initialize_colors_16];
784
- }
785
- }
786
- else
787
- {
788
- // Xcode does NOT natively support colors in the Xcode debugging console.
789
- // You'll need to install the XcodeColors plugin to see colors in the Xcode console.
790
- //
791
- // PS - Please read the header file before diving into the source code.
792
-
793
- char *xcode_colors = getenv("XcodeColors");
794
- if (xcode_colors && (strcmp(xcode_colors, "YES") == 0))
795
- {
796
- isaXcodeColorTTY = YES;
797
- }
798
- }
799
-
800
- NSLogInfo(@"DDTTYLogger: isaColorTTY = %@", (isaColorTTY ? @"YES" : @"NO"));
801
- NSLogInfo(@"DDTTYLogger: isaColor256TTY: %@", (isaColor256TTY ? @"YES" : @"NO"));
802
- NSLogInfo(@"DDTTYLogger: isaXcodeColorTTY: %@", (isaXcodeColorTTY ? @"YES" : @"NO"));
803
-
804
- sharedInstance = [[DDTTYLogger alloc] init];
805
- }
778
+ static BOOL initialized = NO;
779
+ if (!initialized)
780
+ {
781
+ initialized = YES;
782
+
783
+ char *term = getenv("TERM");
784
+ if (term)
785
+ {
786
+ if (strcasestr(term, "color") != NULL)
787
+ {
788
+ isaColorTTY = YES;
789
+ isaColor256TTY = (strcasestr(term, "256") != NULL);
790
+
791
+ if (isaColor256TTY)
792
+ [self initialize_colors_256];
793
+ else
794
+ [self initialize_colors_16];
795
+ }
796
+ }
797
+ else
798
+ {
799
+ // Xcode does NOT natively support colors in the Xcode debugging console.
800
+ // You'll need to install the XcodeColors plugin to see colors in the Xcode console.
801
+ //
802
+ // PS - Please read the header file before diving into the source code.
803
+
804
+ char *xcode_colors = getenv("XcodeColors");
805
+ if (xcode_colors && (strcmp(xcode_colors, "YES") == 0))
806
+ {
807
+ isaXcodeColorTTY = YES;
808
+ }
809
+ }
810
+
811
+ NSLogInfo(@"DDTTYLogger: isaColorTTY = %@", (isaColorTTY ? @"YES" : @"NO"));
812
+ NSLogInfo(@"DDTTYLogger: isaColor256TTY: %@", (isaColor256TTY ? @"YES" : @"NO"));
813
+ NSLogInfo(@"DDTTYLogger: isaXcodeColorTTY: %@", (isaXcodeColorTTY ? @"YES" : @"NO"));
814
+
815
+ sharedInstance = [[[self class] alloc] init];
816
+ }
806
817
  }
807
818
 
808
- + (DDTTYLogger *)sharedInstance
819
+ + (instancetype)sharedInstance
809
820
  {
810
- return sharedInstance;
821
+ return sharedInstance;
811
822
  }
812
823
 
813
824
  - (id)init
814
825
  {
815
- if (sharedInstance != nil)
816
- {
817
- return nil;
818
- }
819
-
820
- if ((self = [super init]))
821
- {
822
- calendar = [NSCalendar autoupdatingCurrentCalendar];
823
-
824
- calendarUnitFlags = 0;
825
- calendarUnitFlags |= NSYearCalendarUnit;
826
- calendarUnitFlags |= NSMonthCalendarUnit;
827
- calendarUnitFlags |= NSDayCalendarUnit;
828
- calendarUnitFlags |= NSHourCalendarUnit;
829
- calendarUnitFlags |= NSMinuteCalendarUnit;
830
- calendarUnitFlags |= NSSecondCalendarUnit;
831
-
832
- // Initialze 'app' variable (char *)
833
-
834
- appName = [[NSProcessInfo processInfo] processName];
835
-
836
- appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
837
- app = (char *)malloc(appLen + 1);
838
-
839
- [appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];
840
-
841
- // Initialize 'pid' variable (char *)
842
-
843
- processID = [NSString stringWithFormat:@"%i", (int)getpid()];
844
-
845
- pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
846
- pid = (char *)malloc(pidLen + 1);
847
-
848
- [processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];
849
-
850
- // Initialize color stuff
851
-
852
- colorsEnabled = NO;
853
- colorProfilesArray = [[NSMutableArray alloc] initWithCapacity:8];
854
- colorProfilesDict = [[NSMutableDictionary alloc] initWithCapacity:8];
855
- }
856
- return self;
826
+ if (sharedInstance != nil)
827
+ {
828
+ return nil;
829
+ }
830
+
831
+ if ((self = [super init]))
832
+ {
833
+ calendar = [NSCalendar autoupdatingCurrentCalendar];
834
+
835
+ calendarUnitFlags = 0;
836
+ calendarUnitFlags |= NSYearCalendarUnit;
837
+ calendarUnitFlags |= NSMonthCalendarUnit;
838
+ calendarUnitFlags |= NSDayCalendarUnit;
839
+ calendarUnitFlags |= NSHourCalendarUnit;
840
+ calendarUnitFlags |= NSMinuteCalendarUnit;
841
+ calendarUnitFlags |= NSSecondCalendarUnit;
842
+
843
+ // Initialze 'app' variable (char *)
844
+
845
+ appName = [[NSProcessInfo processInfo] processName];
846
+
847
+ appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
848
+ if (appLen == 0) {
849
+ appName = @"<UnnamedApp>";
850
+ appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
851
+ }
852
+ app = (char *)malloc(appLen + 1);
853
+ if (app == NULL) return nil;
854
+
855
+ BOOL processedAppName = [appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];
856
+ if (NO == processedAppName) return nil;
857
+
858
+ // Initialize 'pid' variable (char *)
859
+
860
+ processID = [NSString stringWithFormat:@"%i", (int)getpid()];
861
+
862
+ pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
863
+ pid = (char *)malloc(pidLen + 1);
864
+ if (pid == NULL) return nil;
865
+
866
+ BOOL processedID = [processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];
867
+ if (NO == processedID) return nil;
868
+
869
+ // Initialize color stuff
870
+
871
+ colorsEnabled = NO;
872
+ colorProfilesArray = [[NSMutableArray alloc] initWithCapacity:8];
873
+ colorProfilesDict = [[NSMutableDictionary alloc] initWithCapacity:8];
874
+ }
875
+ return self;
857
876
  }
858
877
 
859
878
  - (void)loadDefaultColorProfiles
860
879
  {
861
- [self setForegroundColor:MakeColor(214, 57, 30) backgroundColor:nil forFlag:LOG_FLAG_ERROR];
862
- [self setForegroundColor:MakeColor(204, 121, 32) backgroundColor:nil forFlag:LOG_FLAG_WARN];
880
+ [self setForegroundColor:MakeColor(214, 57, 30) backgroundColor:nil forFlag:LOG_FLAG_ERROR];
881
+ [self setForegroundColor:MakeColor(204, 121, 32) backgroundColor:nil forFlag:LOG_FLAG_WARN];
863
882
  }
864
883
 
865
884
  - (BOOL)colorsEnabled
866
885
  {
867
- // The design of this method is taken from the DDAbstractLogger implementation.
868
- // For extensive documentation please refer to the DDAbstractLogger implementation.
869
-
870
- // Note: The internal implementation MUST access the colorsEnabled variable directly,
871
- // This method is designed explicitly for external access.
872
- //
873
- // Using "self." syntax to go through this method will cause immediate deadlock.
874
- // This is the intended result. Fix it by accessing the ivar directly.
875
- // Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.
876
-
877
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
878
- NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");
879
-
880
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
881
-
882
- __block BOOL result;
883
-
884
- dispatch_sync(globalLoggingQueue, ^{
885
- dispatch_sync(loggerQueue, ^{
886
- result = colorsEnabled;
887
- });
888
- });
889
-
890
- return result;
886
+ // The design of this method is taken from the DDAbstractLogger implementation.
887
+ // For extensive documentation please refer to the DDAbstractLogger implementation.
888
+
889
+ // Note: The internal implementation MUST access the colorsEnabled variable directly,
890
+ // This method is designed explicitly for external access.
891
+ //
892
+ // Using "self." syntax to go through this method will cause immediate deadlock.
893
+ // This is the intended result. Fix it by accessing the ivar directly.
894
+ // Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.
895
+
896
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
897
+ NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");
898
+
899
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
900
+
901
+ __block BOOL result;
902
+
903
+ dispatch_sync(globalLoggingQueue, ^{
904
+ dispatch_sync(loggerQueue, ^{
905
+ result = colorsEnabled;
906
+ });
907
+ });
908
+
909
+ return result;
891
910
  }
892
911
 
893
912
  - (void)setColorsEnabled:(BOOL)newColorsEnabled
894
913
  {
895
- dispatch_block_t block = ^{ @autoreleasepool {
896
-
897
- colorsEnabled = newColorsEnabled;
898
-
899
- if ([colorProfilesArray count] == 0) {
900
- [self loadDefaultColorProfiles];
901
- }
902
- }};
903
-
904
- // The design of this method is taken from the DDAbstractLogger implementation.
905
- // For extensive documentation please refer to the DDAbstractLogger implementation.
906
-
907
- // Note: The internal implementation MUST access the colorsEnabled variable directly,
908
- // This method is designed explicitly for external access.
909
- //
910
- // Using "self." syntax to go through this method will cause immediate deadlock.
911
- // This is the intended result. Fix it by accessing the ivar directly.
912
- // Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.
913
-
914
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
915
- NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");
916
-
917
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
918
-
919
- dispatch_async(globalLoggingQueue, ^{
920
- dispatch_async(loggerQueue, block);
921
- });
914
+ dispatch_block_t block = ^{ @autoreleasepool {
915
+
916
+ colorsEnabled = newColorsEnabled;
917
+
918
+ if ([colorProfilesArray count] == 0) {
919
+ [self loadDefaultColorProfiles];
920
+ }
921
+ }};
922
+
923
+ // The design of this method is taken from the DDAbstractLogger implementation.
924
+ // For extensive documentation please refer to the DDAbstractLogger implementation.
925
+
926
+ // Note: The internal implementation MUST access the colorsEnabled variable directly,
927
+ // This method is designed explicitly for external access.
928
+ //
929
+ // Using "self." syntax to go through this method will cause immediate deadlock.
930
+ // This is the intended result. Fix it by accessing the ivar directly.
931
+ // Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.
932
+
933
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
934
+ NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");
935
+
936
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
937
+
938
+ dispatch_async(globalLoggingQueue, ^{
939
+ dispatch_async(loggerQueue, block);
940
+ });
922
941
  }
923
942
 
924
943
  - (void)setForegroundColor:(OSColor *)txtColor backgroundColor:(OSColor *)bgColor forFlag:(int)mask
925
944
  {
926
- [self setForegroundColor:txtColor backgroundColor:bgColor forFlag:mask context:0];
945
+ [self setForegroundColor:txtColor backgroundColor:bgColor forFlag:mask context:LOG_CONTEXT_ALL];
927
946
  }
928
947
 
929
948
  - (void)setForegroundColor:(OSColor *)txtColor backgroundColor:(OSColor *)bgColor forFlag:(int)mask context:(int)ctxt
930
949
  {
931
- dispatch_block_t block = ^{ @autoreleasepool {
932
-
933
- DDTTYLoggerColorProfile *newColorProfile =
934
- [[DDTTYLoggerColorProfile alloc] initWithForegroundColor:txtColor
935
- backgroundColor:bgColor
936
- flag:mask
937
- context:ctxt];
938
-
939
- NSLogInfo(@"DDTTYLogger: newColorProfile: %@", newColorProfile);
940
-
941
- NSUInteger i = 0;
942
- for (DDTTYLoggerColorProfile *colorProfile in colorProfilesArray)
943
- {
944
- if ((colorProfile->mask == mask) && (colorProfile->context == ctxt))
945
- {
946
- break;
947
- }
948
-
949
- i++;
950
- }
951
-
952
- if (i < [colorProfilesArray count])
953
- [colorProfilesArray replaceObjectAtIndex:i withObject:newColorProfile];
954
- else
955
- [colorProfilesArray addObject:newColorProfile];
956
- }};
957
-
958
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
959
- // For documentation please refer to the DDAbstractLogger implementation.
960
-
961
- if ([self isOnInternalLoggerQueue])
962
- {
963
- block();
964
- }
965
- else
966
- {
967
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
968
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
969
-
970
- dispatch_async(globalLoggingQueue, ^{
971
- dispatch_async(loggerQueue, block);
972
- });
973
- }
950
+ dispatch_block_t block = ^{ @autoreleasepool {
951
+
952
+ DDTTYLoggerColorProfile *newColorProfile =
953
+ [[DDTTYLoggerColorProfile alloc] initWithForegroundColor:txtColor
954
+ backgroundColor:bgColor
955
+ flag:mask
956
+ context:ctxt];
957
+
958
+ NSLogInfo(@"DDTTYLogger: newColorProfile: %@", newColorProfile);
959
+
960
+ NSUInteger i = 0;
961
+ for (DDTTYLoggerColorProfile *colorProfile in colorProfilesArray)
962
+ {
963
+ if ((colorProfile->mask == mask) && (colorProfile->context == ctxt))
964
+ {
965
+ break;
966
+ }
967
+
968
+ i++;
969
+ }
970
+
971
+ if (i < [colorProfilesArray count])
972
+ [colorProfilesArray replaceObjectAtIndex:i withObject:newColorProfile];
973
+ else
974
+ [colorProfilesArray addObject:newColorProfile];
975
+ }};
976
+
977
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
978
+ // For documentation please refer to the DDAbstractLogger implementation.
979
+
980
+ if ([self isOnInternalLoggerQueue])
981
+ {
982
+ block();
983
+ }
984
+ else
985
+ {
986
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
987
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
988
+
989
+ dispatch_async(globalLoggingQueue, ^{
990
+ dispatch_async(loggerQueue, block);
991
+ });
992
+ }
974
993
  }
975
994
 
976
995
  - (void)setForegroundColor:(OSColor *)txtColor backgroundColor:(OSColor *)bgColor forTag:(id <NSCopying>)tag
977
996
  {
978
- NSAssert([(id <NSObject>)tag conformsToProtocol:@protocol(NSCopying)], @"Invalid tag");
979
-
980
- dispatch_block_t block = ^{ @autoreleasepool {
981
-
982
- DDTTYLoggerColorProfile *newColorProfile =
983
- [[DDTTYLoggerColorProfile alloc] initWithForegroundColor:txtColor
984
- backgroundColor:bgColor
985
- flag:0
986
- context:0];
987
-
988
- NSLogInfo(@"DDTTYLogger: newColorProfile: %@", newColorProfile);
989
-
990
- [colorProfilesDict setObject:newColorProfile forKey:tag];
991
- }};
992
-
993
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
994
- // For documentation please refer to the DDAbstractLogger implementation.
995
-
996
- if ([self isOnInternalLoggerQueue])
997
- {
998
- block();
999
- }
1000
- else
1001
- {
1002
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1003
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1004
-
1005
- dispatch_async(globalLoggingQueue, ^{
1006
- dispatch_async(loggerQueue, block);
1007
- });
1008
- }
997
+ NSAssert([(id <NSObject>)tag conformsToProtocol:@protocol(NSCopying)], @"Invalid tag");
998
+
999
+ dispatch_block_t block = ^{ @autoreleasepool {
1000
+
1001
+ DDTTYLoggerColorProfile *newColorProfile =
1002
+ [[DDTTYLoggerColorProfile alloc] initWithForegroundColor:txtColor
1003
+ backgroundColor:bgColor
1004
+ flag:0
1005
+ context:0];
1006
+
1007
+ NSLogInfo(@"DDTTYLogger: newColorProfile: %@", newColorProfile);
1008
+
1009
+ [colorProfilesDict setObject:newColorProfile forKey:tag];
1010
+ }};
1011
+
1012
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1013
+ // For documentation please refer to the DDAbstractLogger implementation.
1014
+
1015
+ if ([self isOnInternalLoggerQueue])
1016
+ {
1017
+ block();
1018
+ }
1019
+ else
1020
+ {
1021
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1022
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1023
+
1024
+ dispatch_async(globalLoggingQueue, ^{
1025
+ dispatch_async(loggerQueue, block);
1026
+ });
1027
+ }
1009
1028
  }
1010
1029
 
1011
1030
  - (void)clearColorsForFlag:(int)mask
1012
1031
  {
1013
- [self clearColorsForFlag:mask context:0];
1032
+ [self clearColorsForFlag:mask context:0];
1014
1033
  }
1015
1034
 
1016
1035
  - (void)clearColorsForFlag:(int)mask context:(int)context
1017
1036
  {
1018
- dispatch_block_t block = ^{ @autoreleasepool {
1019
-
1020
- NSUInteger i = 0;
1021
- for (DDTTYLoggerColorProfile *colorProfile in colorProfilesArray)
1022
- {
1023
- if ((colorProfile->mask == mask) && (colorProfile->context == context))
1024
- {
1025
- break;
1026
- }
1027
-
1028
- i++;
1029
- }
1030
-
1031
- if (i < [colorProfilesArray count])
1032
- {
1033
- [colorProfilesArray removeObjectAtIndex:i];
1034
- }
1035
- }};
1036
-
1037
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1038
- // For documentation please refer to the DDAbstractLogger implementation.
1039
-
1040
- if ([self isOnInternalLoggerQueue])
1041
- {
1042
- block();
1043
- }
1044
- else
1045
- {
1046
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1047
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1048
-
1049
- dispatch_async(globalLoggingQueue, ^{
1050
- dispatch_async(loggerQueue, block);
1051
- });
1052
- }
1037
+ dispatch_block_t block = ^{ @autoreleasepool {
1038
+
1039
+ NSUInteger i = 0;
1040
+ for (DDTTYLoggerColorProfile *colorProfile in colorProfilesArray)
1041
+ {
1042
+ if ((colorProfile->mask == mask) && (colorProfile->context == context))
1043
+ {
1044
+ break;
1045
+ }
1046
+
1047
+ i++;
1048
+ }
1049
+
1050
+ if (i < [colorProfilesArray count])
1051
+ {
1052
+ [colorProfilesArray removeObjectAtIndex:i];
1053
+ }
1054
+ }};
1055
+
1056
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1057
+ // For documentation please refer to the DDAbstractLogger implementation.
1058
+
1059
+ if ([self isOnInternalLoggerQueue])
1060
+ {
1061
+ block();
1062
+ }
1063
+ else
1064
+ {
1065
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1066
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1067
+
1068
+ dispatch_async(globalLoggingQueue, ^{
1069
+ dispatch_async(loggerQueue, block);
1070
+ });
1071
+ }
1053
1072
  }
1054
1073
 
1055
1074
  - (void)clearColorsForTag:(id <NSCopying>)tag
1056
1075
  {
1057
- NSAssert([(id <NSObject>)tag conformsToProtocol:@protocol(NSCopying)], @"Invalid tag");
1058
-
1059
- dispatch_block_t block = ^{ @autoreleasepool {
1060
-
1061
- [colorProfilesDict removeObjectForKey:tag];
1062
- }};
1063
-
1064
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1065
- // For documentation please refer to the DDAbstractLogger implementation.
1066
-
1067
- if ([self isOnInternalLoggerQueue])
1068
- {
1069
- block();
1070
- }
1071
- else
1072
- {
1073
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1074
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1075
-
1076
- dispatch_async(globalLoggingQueue, ^{
1077
- dispatch_async(loggerQueue, block);
1078
- });
1079
- }
1076
+ NSAssert([(id <NSObject>)tag conformsToProtocol:@protocol(NSCopying)], @"Invalid tag");
1077
+
1078
+ dispatch_block_t block = ^{ @autoreleasepool {
1079
+
1080
+ [colorProfilesDict removeObjectForKey:tag];
1081
+ }};
1082
+
1083
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1084
+ // For documentation please refer to the DDAbstractLogger implementation.
1085
+
1086
+ if ([self isOnInternalLoggerQueue])
1087
+ {
1088
+ block();
1089
+ }
1090
+ else
1091
+ {
1092
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1093
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1094
+
1095
+ dispatch_async(globalLoggingQueue, ^{
1096
+ dispatch_async(loggerQueue, block);
1097
+ });
1098
+ }
1080
1099
  }
1081
1100
 
1082
1101
  - (void)clearColorsForAllFlags
1083
1102
  {
1084
- dispatch_block_t block = ^{ @autoreleasepool {
1085
-
1086
- [colorProfilesArray removeAllObjects];
1087
- }};
1088
-
1089
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1090
- // For documentation please refer to the DDAbstractLogger implementation.
1091
-
1092
- if ([self isOnInternalLoggerQueue])
1093
- {
1094
- block();
1095
- }
1096
- else
1097
- {
1098
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1099
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1100
-
1101
- dispatch_async(globalLoggingQueue, ^{
1102
- dispatch_async(loggerQueue, block);
1103
- });
1104
- }
1103
+ dispatch_block_t block = ^{ @autoreleasepool {
1104
+
1105
+ [colorProfilesArray removeAllObjects];
1106
+ }};
1107
+
1108
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1109
+ // For documentation please refer to the DDAbstractLogger implementation.
1110
+
1111
+ if ([self isOnInternalLoggerQueue])
1112
+ {
1113
+ block();
1114
+ }
1115
+ else
1116
+ {
1117
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1118
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1119
+
1120
+ dispatch_async(globalLoggingQueue, ^{
1121
+ dispatch_async(loggerQueue, block);
1122
+ });
1123
+ }
1105
1124
  }
1106
1125
 
1107
1126
  - (void)clearColorsForAllTags
1108
1127
  {
1109
- dispatch_block_t block = ^{ @autoreleasepool {
1110
-
1111
- [colorProfilesDict removeAllObjects];
1112
- }};
1113
-
1114
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1115
- // For documentation please refer to the DDAbstractLogger implementation.
1116
-
1117
- if ([self isOnInternalLoggerQueue])
1118
- {
1119
- block();
1120
- }
1121
- else
1122
- {
1123
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1124
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1125
-
1126
- dispatch_async(globalLoggingQueue, ^{
1127
- dispatch_async(loggerQueue, block);
1128
- });
1129
- }
1128
+ dispatch_block_t block = ^{ @autoreleasepool {
1129
+
1130
+ [colorProfilesDict removeAllObjects];
1131
+ }};
1132
+
1133
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1134
+ // For documentation please refer to the DDAbstractLogger implementation.
1135
+
1136
+ if ([self isOnInternalLoggerQueue])
1137
+ {
1138
+ block();
1139
+ }
1140
+ else
1141
+ {
1142
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1143
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1144
+
1145
+ dispatch_async(globalLoggingQueue, ^{
1146
+ dispatch_async(loggerQueue, block);
1147
+ });
1148
+ }
1130
1149
  }
1131
1150
 
1132
1151
  - (void)clearAllColors
1133
1152
  {
1134
- dispatch_block_t block = ^{ @autoreleasepool {
1135
-
1136
- [colorProfilesArray removeAllObjects];
1137
- [colorProfilesDict removeAllObjects];
1138
- }};
1139
-
1140
- // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1141
- // For documentation please refer to the DDAbstractLogger implementation.
1142
-
1143
- if ([self isOnInternalLoggerQueue])
1144
- {
1145
- block();
1146
- }
1147
- else
1148
- {
1149
- dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1150
- NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1151
-
1152
- dispatch_async(globalLoggingQueue, ^{
1153
- dispatch_async(loggerQueue, block);
1154
- });
1155
- }
1153
+ dispatch_block_t block = ^{ @autoreleasepool {
1154
+
1155
+ [colorProfilesArray removeAllObjects];
1156
+ [colorProfilesDict removeAllObjects];
1157
+ }};
1158
+
1159
+ // The design of the setter logic below is taken from the DDAbstractLogger implementation.
1160
+ // For documentation please refer to the DDAbstractLogger implementation.
1161
+
1162
+ if ([self isOnInternalLoggerQueue])
1163
+ {
1164
+ block();
1165
+ }
1166
+ else
1167
+ {
1168
+ dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
1169
+ NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
1170
+
1171
+ dispatch_async(globalLoggingQueue, ^{
1172
+ dispatch_async(loggerQueue, block);
1173
+ });
1174
+ }
1156
1175
  }
1157
1176
 
1158
1177
  - (void)logMessage:(DDLogMessage *)logMessage
1159
1178
  {
1160
- NSString *logMsg = logMessage->logMsg;
1161
- BOOL isFormatted = NO;
1162
-
1163
- if (formatter)
1164
- {
1165
- logMsg = [formatter formatLogMessage:logMessage];
1166
- isFormatted = logMsg != logMessage->logMsg;
1167
- }
1168
-
1169
- if (logMsg)
1170
- {
1171
- // Search for a color profile associated with the log message
1172
-
1173
- DDTTYLoggerColorProfile *colorProfile = nil;
1174
-
1175
- if (colorsEnabled)
1176
- {
1177
- if (logMessage->tag)
1178
- {
1179
- colorProfile = [colorProfilesDict objectForKey:logMessage->tag];
1180
- }
1181
- if (colorProfile == nil)
1182
- {
1183
- for (DDTTYLoggerColorProfile *cp in colorProfilesArray)
1184
- {
1185
- if ((logMessage->logFlag & cp->mask) && (logMessage->logContext == cp->context))
1186
- {
1187
- colorProfile = cp;
1188
- break;
1189
- }
1190
- }
1191
- }
1192
- }
1193
-
1194
- // Convert log message to C string.
1195
- //
1196
- // We use the stack instead of the heap for speed if possible.
1197
- // But we're extra cautious to avoid a stack overflow.
1198
-
1199
- NSUInteger msgLen = [logMsg lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1200
- const BOOL useStack = msgLen < (1024 * 4);
1201
-
1202
- char msgStack[useStack ? (msgLen + 1) : 1]; // Analyzer doesn't like zero-size array, hence the 1
1203
- char *msg = useStack ? msgStack : (char *)malloc(msgLen + 1);
1204
-
1205
- [logMsg getCString:msg maxLength:(msgLen + 1) encoding:NSUTF8StringEncoding];
1206
-
1207
- // Write the log message to STDERR
1208
-
1209
- if (isFormatted)
1210
- {
1211
- // The log message has already been formatted.
1212
-
1213
- struct iovec v[5];
1214
-
1215
- if (colorProfile)
1216
- {
1217
- v[0].iov_base = colorProfile->fgCode;
1218
- v[0].iov_len = colorProfile->fgCodeLen;
1179
+ NSString *logMsg = logMessage->logMsg;
1180
+ BOOL isFormatted = NO;
1181
+
1182
+ if (formatter)
1183
+ {
1184
+ logMsg = [formatter formatLogMessage:logMessage];
1185
+ isFormatted = logMsg != logMessage->logMsg;
1186
+ }
1187
+
1188
+ if (logMsg)
1189
+ {
1190
+ // Search for a color profile associated with the log message
1191
+
1192
+ DDTTYLoggerColorProfile *colorProfile = nil;
1193
+
1194
+ if (colorsEnabled)
1195
+ {
1196
+ if (logMessage->tag)
1197
+ {
1198
+ colorProfile = [colorProfilesDict objectForKey:logMessage->tag];
1199
+ }
1200
+ if (colorProfile == nil)
1201
+ {
1202
+ for (DDTTYLoggerColorProfile *cp in colorProfilesArray)
1203
+ {
1204
+ if (logMessage->logFlag & cp->mask)
1205
+ {
1206
+ // Color profile set for this context?
1207
+ if (logMessage->logContext == cp->context)
1208
+ {
1209
+ colorProfile = cp;
1210
+
1211
+ // Stop searching
1212
+ break;
1213
+ }
1214
+
1215
+ // Check if LOG_CONTEXT_ALL was specified as a default color for this flag
1216
+ if (cp->context == LOG_CONTEXT_ALL)
1217
+ {
1218
+ colorProfile = cp;
1219
+
1220
+ // We don't break to keep searching for more specific color profiles for the context
1221
+ }
1222
+ }
1223
+ }
1224
+ }
1225
+ }
1226
+
1227
+ // Convert log message to C string.
1228
+ //
1229
+ // We use the stack instead of the heap for speed if possible.
1230
+ // But we're extra cautious to avoid a stack overflow.
1231
+
1232
+ NSUInteger msgLen = [logMsg lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1233
+ const BOOL useStack = msgLen < (1024 * 4);
1234
+
1235
+ char msgStack[useStack ? (msgLen + 1) : 1]; // Analyzer doesn't like zero-size array, hence the 1
1236
+ char *msg = useStack ? msgStack : (char *)malloc(msgLen + 1);
1237
+ if (msg == NULL) return;
1238
+
1239
+ BOOL logMsgEnc = [logMsg getCString:msg maxLength:(msgLen + 1) encoding:NSUTF8StringEncoding];
1240
+ if (!logMsgEnc)
1241
+ {
1242
+ if (!useStack && msg != NULL) free(msg);
1243
+ return;
1244
+ }
1245
+
1246
+ // Write the log message to STDERR
1247
+
1248
+ if (isFormatted)
1249
+ {
1250
+ // The log message has already been formatted.
1251
+
1252
+ struct iovec v[5];
1253
+
1254
+ if (colorProfile)
1255
+ {
1256
+ v[0].iov_base = colorProfile->fgCode;
1257
+ v[0].iov_len = colorProfile->fgCodeLen;
1219
1258
 
1220
- v[1].iov_base = colorProfile->bgCode;
1221
- v[1].iov_len = colorProfile->bgCodeLen;
1259
+ v[1].iov_base = colorProfile->bgCode;
1260
+ v[1].iov_len = colorProfile->bgCodeLen;
1222
1261
 
1223
- v[4].iov_base = colorProfile->resetCode;
1224
- v[4].iov_len = colorProfile->resetCodeLen;
1225
- }
1226
- else
1227
- {
1228
- v[0].iov_base = "";
1229
- v[0].iov_len = 0;
1230
-
1231
- v[1].iov_base = "";
1232
- v[1].iov_len = 0;
1233
-
1234
- v[4].iov_base = "";
1235
- v[4].iov_len = 0;
1236
- }
1237
-
1238
- v[2].iov_base = (char *)msg;
1239
- v[2].iov_len = msgLen;
1240
-
1241
- v[3].iov_base = "\n";
1242
- v[3].iov_len = (msg[msgLen] == '\n') ? 0 : 1;
1243
-
1244
- writev(STDERR_FILENO, v, 5);
1245
- }
1246
- else
1247
- {
1248
- // The log message is unformatted, so apply standard NSLog style formatting.
1249
-
1250
- int len;
1251
-
1252
- // Calculate timestamp.
1253
- // The technique below is faster than using NSDateFormatter.
1254
-
1255
- NSDateComponents *components = [calendar components:calendarUnitFlags fromDate:logMessage->timestamp];
1256
-
1257
- NSTimeInterval epoch = [logMessage->timestamp timeIntervalSinceReferenceDate];
1258
- int milliseconds = (int)((epoch - floor(epoch)) * 1000);
1259
-
1260
- char ts[24];
1261
- len = snprintf(ts, 24, "%04ld-%02ld-%02ld %02ld:%02ld:%02ld:%03d", // yyyy-MM-dd HH:mm:ss:SSS
1262
- (long)components.year,
1263
- (long)components.month,
1264
- (long)components.day,
1265
- (long)components.hour,
1266
- (long)components.minute,
1267
- (long)components.second, milliseconds);
1268
-
1269
- size_t tsLen = MIN(24-1, len);
1270
-
1271
- // Calculate thread ID
1272
- //
1273
- // How many characters do we need for the thread id?
1274
- // logMessage->machThreadID is of type mach_port_t, which is an unsigned int.
1275
- //
1276
- // 1 hex char = 4 bits
1277
- // 8 hex chars for 32 bit, plus ending '\0' = 9
1278
-
1279
- char tid[9];
1280
- len = snprintf(tid, 9, "%x", logMessage->machThreadID);
1281
-
1282
- size_t tidLen = MIN(9-1, len);
1283
-
1284
- // Here is our format: "%s %s[%i:%s] %s", timestamp, appName, processID, threadID, logMsg
1285
-
1286
- struct iovec v[13];
1287
-
1288
- if (colorProfile)
1289
- {
1290
- v[0].iov_base = colorProfile->fgCode;
1291
- v[0].iov_len = colorProfile->fgCodeLen;
1262
+ v[4].iov_base = colorProfile->resetCode;
1263
+ v[4].iov_len = colorProfile->resetCodeLen;
1264
+ }
1265
+ else
1266
+ {
1267
+ v[0].iov_base = "";
1268
+ v[0].iov_len = 0;
1269
+
1270
+ v[1].iov_base = "";
1271
+ v[1].iov_len = 0;
1272
+
1273
+ v[4].iov_base = "";
1274
+ v[4].iov_len = 0;
1275
+ }
1276
+
1277
+ v[2].iov_base = (char *)msg;
1278
+ v[2].iov_len = msgLen;
1279
+
1280
+ v[3].iov_base = "\n";
1281
+ v[3].iov_len = (msg[msgLen] == '\n') ? 0 : 1;
1282
+
1283
+ writev(STDERR_FILENO, v, 5);
1284
+ }
1285
+ else
1286
+ {
1287
+ // The log message is unformatted, so apply standard NSLog style formatting.
1288
+
1289
+ int len;
1290
+
1291
+ // Calculate timestamp.
1292
+ // The technique below is faster than using NSDateFormatter.
1293
+
1294
+ NSDateComponents *components = [calendar components:calendarUnitFlags fromDate:logMessage->timestamp];
1295
+
1296
+ NSTimeInterval epoch = [logMessage->timestamp timeIntervalSinceReferenceDate];
1297
+ int milliseconds = (int)((epoch - floor(epoch)) * 1000);
1298
+
1299
+ char ts[24];
1300
+ len = snprintf(ts, 24, "%04ld-%02ld-%02ld %02ld:%02ld:%02ld:%03d", // yyyy-MM-dd HH:mm:ss:SSS
1301
+ (long)components.year,
1302
+ (long)components.month,
1303
+ (long)components.day,
1304
+ (long)components.hour,
1305
+ (long)components.minute,
1306
+ (long)components.second, milliseconds);
1307
+
1308
+ size_t tsLen = MIN(24-1, len);
1309
+
1310
+ // Calculate thread ID
1311
+ //
1312
+ // How many characters do we need for the thread id?
1313
+ // logMessage->machThreadID is of type mach_port_t, which is an unsigned int.
1314
+ //
1315
+ // 1 hex char = 4 bits
1316
+ // 8 hex chars for 32 bit, plus ending '\0' = 9
1317
+
1318
+ char tid[9];
1319
+ len = snprintf(tid, 9, "%x", logMessage->machThreadID);
1320
+
1321
+ size_t tidLen = MIN(9-1, len);
1322
+
1323
+ // Here is our format: "%s %s[%i:%s] %s", timestamp, appName, processID, threadID, logMsg
1324
+
1325
+ struct iovec v[13];
1326
+
1327
+ if (colorProfile)
1328
+ {
1329
+ v[0].iov_base = colorProfile->fgCode;
1330
+ v[0].iov_len = colorProfile->fgCodeLen;
1292
1331
 
1293
- v[1].iov_base = colorProfile->bgCode;
1294
- v[1].iov_len = colorProfile->bgCodeLen;
1332
+ v[1].iov_base = colorProfile->bgCode;
1333
+ v[1].iov_len = colorProfile->bgCodeLen;
1295
1334
 
1296
- v[12].iov_base = colorProfile->resetCode;
1297
- v[12].iov_len = colorProfile->resetCodeLen;
1298
- }
1299
- else
1300
- {
1301
- v[0].iov_base = "";
1302
- v[0].iov_len = 0;
1335
+ v[12].iov_base = colorProfile->resetCode;
1336
+ v[12].iov_len = colorProfile->resetCodeLen;
1337
+ }
1338
+ else
1339
+ {
1340
+ v[0].iov_base = "";
1341
+ v[0].iov_len = 0;
1303
1342
 
1304
- v[1].iov_base = "";
1305
- v[1].iov_len = 0;
1343
+ v[1].iov_base = "";
1344
+ v[1].iov_len = 0;
1306
1345
 
1307
- v[12].iov_base = "";
1308
- v[12].iov_len = 0;
1309
- }
1310
-
1311
- v[2].iov_base = ts;
1312
- v[2].iov_len = tsLen;
1313
-
1314
- v[3].iov_base = " ";
1315
- v[3].iov_len = 1;
1316
-
1317
- v[4].iov_base = app;
1318
- v[4].iov_len = appLen;
1319
-
1320
- v[5].iov_base = "[";
1321
- v[5].iov_len = 1;
1322
-
1323
- v[6].iov_base = pid;
1324
- v[6].iov_len = pidLen;
1325
-
1326
- v[7].iov_base = ":";
1327
- v[7].iov_len = 1;
1328
-
1329
- v[8].iov_base = tid;
1330
- v[8].iov_len = MIN((size_t)8, tidLen); // snprintf doesn't return what you might think
1331
-
1332
- v[9].iov_base = "] ";
1333
- v[9].iov_len = 2;
1334
-
1335
- v[10].iov_base = (char *)msg;
1336
- v[10].iov_len = msgLen;
1337
-
1338
- v[11].iov_base = "\n";
1339
- v[11].iov_len = (msg[msgLen] == '\n') ? 0 : 1;
1340
-
1341
- writev(STDERR_FILENO, v, 13);
1342
- }
1343
-
1344
- if (!useStack) {
1345
- free(msg);
1346
- }
1347
- }
1346
+ v[12].iov_base = "";
1347
+ v[12].iov_len = 0;
1348
+ }
1349
+
1350
+ v[2].iov_base = ts;
1351
+ v[2].iov_len = tsLen;
1352
+
1353
+ v[3].iov_base = " ";
1354
+ v[3].iov_len = 1;
1355
+
1356
+ v[4].iov_base = app;
1357
+ v[4].iov_len = appLen;
1358
+
1359
+ v[5].iov_base = "[";
1360
+ v[5].iov_len = 1;
1361
+
1362
+ v[6].iov_base = pid;
1363
+ v[6].iov_len = pidLen;
1364
+
1365
+ v[7].iov_base = ":";
1366
+ v[7].iov_len = 1;
1367
+
1368
+ v[8].iov_base = tid;
1369
+ v[8].iov_len = MIN((size_t)8, tidLen); // snprintf doesn't return what you might think
1370
+
1371
+ v[9].iov_base = "] ";
1372
+ v[9].iov_len = 2;
1373
+
1374
+ v[10].iov_base = (char *)msg;
1375
+ v[10].iov_len = msgLen;
1376
+
1377
+ v[11].iov_base = "\n";
1378
+ v[11].iov_len = (msg[msgLen] == '\n') ? 0 : 1;
1379
+
1380
+ writev(STDERR_FILENO, v, 13);
1381
+ }
1382
+
1383
+ if (!useStack) {
1384
+ free(msg);
1385
+ }
1386
+ }
1348
1387
  }
1349
1388
 
1350
1389
  - (NSString *)loggerName
1351
1390
  {
1352
- return @"cocoa.lumberjack.ttyLogger";
1391
+ return @"cocoa.lumberjack.ttyLogger";
1353
1392
  }
1354
1393
 
1355
1394
  @end
@@ -1358,122 +1397,124 @@ static DDTTYLogger *sharedInstance;
1358
1397
 
1359
1398
  @implementation DDTTYLoggerColorProfile
1360
1399
 
1361
- - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)aMask context:(int)ctxt
1400
+ - (instancetype)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)aMask context:(int)ctxt
1362
1401
  {
1363
- if ((self = [super init]))
1364
- {
1365
- mask = aMask;
1366
- context = ctxt;
1367
-
1368
- CGFloat r, g, b;
1369
-
1370
- if (fgColor)
1371
- {
1372
- [DDTTYLogger getRed:&r green:&g blue:&b fromColor:fgColor];
1373
-
1374
- fg_r = (uint8_t)(r * 255.0f);
1375
- fg_g = (uint8_t)(g * 255.0f);
1376
- fg_b = (uint8_t)(b * 255.0f);
1377
- }
1378
- if (bgColor)
1379
- {
1380
- [DDTTYLogger getRed:&r green:&g blue:&b fromColor:bgColor];
1381
-
1382
- bg_r = (uint8_t)(r * 255.0f);
1383
- bg_g = (uint8_t)(g * 255.0f);
1384
- bg_b = (uint8_t)(b * 255.0f);
1385
- }
1386
-
1387
- if (fgColor && isaColorTTY)
1388
- {
1389
- // Map foreground color to closest available shell color
1390
-
1391
- fgCodeIndex = [DDTTYLogger codeIndexForColor:fgColor];
1392
- fgCodeRaw = [codes_fg objectAtIndex:fgCodeIndex];
1393
-
1394
- NSString *escapeSeq = @"\033[";
1395
-
1396
- NSUInteger len1 = [escapeSeq lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1397
- NSUInteger len2 = [fgCodeRaw lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1398
-
1399
- [escapeSeq getCString:(fgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding];
1400
- [fgCodeRaw getCString:(fgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding];
1401
-
1402
- fgCodeLen = len1+len2;
1403
- }
1404
- else if (fgColor && isaXcodeColorTTY)
1405
- {
1406
- // Convert foreground color to color code sequence
1407
-
1408
- const char *escapeSeq = XCODE_COLORS_ESCAPE_SEQ;
1409
-
1410
- int result = snprintf(fgCode, 24, "%sfg%u,%u,%u;", escapeSeq, fg_r, fg_g, fg_b);
1411
- fgCodeLen = MIN(result, (24-1));
1412
- }
1413
- else
1414
- {
1415
- // No foreground color or no color support
1416
-
1417
- fgCode[0] = '\0';
1418
- fgCodeLen = 0;
1419
- }
1420
-
1421
- if (bgColor && isaColorTTY)
1422
- {
1423
- // Map background color to closest available shell color
1424
-
1425
- bgCodeIndex = [DDTTYLogger codeIndexForColor:bgColor];
1426
- bgCodeRaw = [codes_bg objectAtIndex:bgCodeIndex];
1427
-
1428
- NSString *escapeSeq = @"\033[";
1429
-
1430
- NSUInteger len1 = [escapeSeq lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1431
- NSUInteger len2 = [bgCodeRaw lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1432
-
1433
- [escapeSeq getCString:(bgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding];
1434
- [bgCodeRaw getCString:(bgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding];
1435
-
1436
- bgCodeLen = len1+len2;
1437
- }
1438
- else if (bgColor && isaXcodeColorTTY)
1439
- {
1440
- // Convert background color to color code sequence
1441
-
1442
- const char *escapeSeq = XCODE_COLORS_ESCAPE_SEQ;
1443
-
1444
- int result = snprintf(bgCode, 24, "%sbg%u,%u,%u;", escapeSeq, bg_r, bg_g, bg_b);
1445
- bgCodeLen = MIN(result, (24-1));
1446
- }
1447
- else
1448
- {
1449
- // No background color or no color support
1450
-
1451
- bgCode[0] = '\0';
1452
- bgCodeLen = 0;
1453
- }
1454
-
1455
- if (isaColorTTY)
1456
- {
1457
- resetCodeLen = snprintf(resetCode, 8, "\033[0m");
1458
- }
1459
- else if (isaXcodeColorTTY)
1460
- {
1461
- resetCodeLen = snprintf(resetCode, 8, XCODE_COLORS_RESET);
1462
- }
1463
- else
1464
- {
1465
- resetCode[0] = '\0';
1466
- resetCodeLen = 0;
1467
- }
1468
- }
1469
- return self;
1402
+ if ((self = [super init]))
1403
+ {
1404
+ mask = aMask;
1405
+ context = ctxt;
1406
+
1407
+ CGFloat r, g, b;
1408
+
1409
+ if (fgColor)
1410
+ {
1411
+ [DDTTYLogger getRed:&r green:&g blue:&b fromColor:fgColor];
1412
+
1413
+ fg_r = (uint8_t)(r * 255.0f);
1414
+ fg_g = (uint8_t)(g * 255.0f);
1415
+ fg_b = (uint8_t)(b * 255.0f);
1416
+ }
1417
+ if (bgColor)
1418
+ {
1419
+ [DDTTYLogger getRed:&r green:&g blue:&b fromColor:bgColor];
1420
+
1421
+ bg_r = (uint8_t)(r * 255.0f);
1422
+ bg_g = (uint8_t)(g * 255.0f);
1423
+ bg_b = (uint8_t)(b * 255.0f);
1424
+ }
1425
+
1426
+ if (fgColor && isaColorTTY)
1427
+ {
1428
+ // Map foreground color to closest available shell color
1429
+
1430
+ fgCodeIndex = [DDTTYLogger codeIndexForColor:fgColor];
1431
+ fgCodeRaw = [codes_fg objectAtIndex:fgCodeIndex];
1432
+
1433
+ NSString *escapeSeq = @"\033[";
1434
+
1435
+ NSUInteger len1 = [escapeSeq lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1436
+ NSUInteger len2 = [fgCodeRaw lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1437
+
1438
+ BOOL escapeSeqEnc = [escapeSeq getCString:(fgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding];
1439
+ BOOL fgCodeRawEsc = [fgCodeRaw getCString:(fgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding];
1440
+ if (!escapeSeqEnc || !fgCodeRawEsc) return nil;
1441
+
1442
+ fgCodeLen = len1+len2;
1443
+ }
1444
+ else if (fgColor && isaXcodeColorTTY)
1445
+ {
1446
+ // Convert foreground color to color code sequence
1447
+
1448
+ const char *escapeSeq = XCODE_COLORS_ESCAPE_SEQ;
1449
+
1450
+ int result = snprintf(fgCode, 24, "%sfg%u,%u,%u;", escapeSeq, fg_r, fg_g, fg_b);
1451
+ fgCodeLen = MIN(result, (24-1));
1452
+ }
1453
+ else
1454
+ {
1455
+ // No foreground color or no color support
1456
+
1457
+ fgCode[0] = '\0';
1458
+ fgCodeLen = 0;
1459
+ }
1460
+
1461
+ if (bgColor && isaColorTTY)
1462
+ {
1463
+ // Map background color to closest available shell color
1464
+
1465
+ bgCodeIndex = [DDTTYLogger codeIndexForColor:bgColor];
1466
+ bgCodeRaw = [codes_bg objectAtIndex:bgCodeIndex];
1467
+
1468
+ NSString *escapeSeq = @"\033[";
1469
+
1470
+ NSUInteger len1 = [escapeSeq lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1471
+ NSUInteger len2 = [bgCodeRaw lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1472
+
1473
+ BOOL escapeSeqEnc = [escapeSeq getCString:(bgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding];
1474
+ BOOL bgCodeRawEsc = [bgCodeRaw getCString:(bgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding];
1475
+ if (!escapeSeqEnc || !bgCodeRawEsc) return nil;
1476
+
1477
+ bgCodeLen = len1+len2;
1478
+ }
1479
+ else if (bgColor && isaXcodeColorTTY)
1480
+ {
1481
+ // Convert background color to color code sequence
1482
+
1483
+ const char *escapeSeq = XCODE_COLORS_ESCAPE_SEQ;
1484
+
1485
+ int result = snprintf(bgCode, 24, "%sbg%u,%u,%u;", escapeSeq, bg_r, bg_g, bg_b);
1486
+ bgCodeLen = MIN(result, (24-1));
1487
+ }
1488
+ else
1489
+ {
1490
+ // No background color or no color support
1491
+
1492
+ bgCode[0] = '\0';
1493
+ bgCodeLen = 0;
1494
+ }
1495
+
1496
+ if (isaColorTTY)
1497
+ {
1498
+ resetCodeLen = snprintf(resetCode, 8, "\033[0m");
1499
+ }
1500
+ else if (isaXcodeColorTTY)
1501
+ {
1502
+ resetCodeLen = snprintf(resetCode, 8, XCODE_COLORS_RESET);
1503
+ }
1504
+ else
1505
+ {
1506
+ resetCode[0] = '\0';
1507
+ resetCodeLen = 0;
1508
+ }
1509
+ }
1510
+ return self;
1470
1511
  }
1471
1512
 
1472
1513
  - (NSString *)description
1473
1514
  {
1474
- return [NSString stringWithFormat:
1475
- @"<DDTTYLoggerColorProfile: %p mask:%i ctxt:%i fg:%u,%u,%u bg:%u,%u,%u fgCode:%@ bgCode:%@>",
1476
- self, mask, context, fg_r, fg_g, fg_b, bg_r, bg_g, bg_b, fgCodeRaw, bgCodeRaw];
1515
+ return [NSString stringWithFormat:
1516
+ @"<DDTTYLoggerColorProfile: %p mask:%i ctxt:%i fg:%u,%u,%u bg:%u,%u,%u fgCode:%@ bgCode:%@>",
1517
+ self, mask, context, fg_r, fg_g, fg_b, bg_r, bg_g, bg_b, fgCodeRaw, bgCodeRaw];
1477
1518
  }
1478
1519
 
1479
1520
  @end