git-remote-ops 0.1.0 → 0.2.0

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 (274) hide show
  1. package/AGENTS.md +33 -32
  2. package/README.md +80 -206
  3. package/dist/cli.js +215 -0
  4. package/dist/cli.js.map +1 -0
  5. package/{types → dist}/client.d.ts +11 -15
  6. package/dist/client.d.ts.map +1 -0
  7. package/{esm → dist}/client.js +107 -83
  8. package/dist/client.js.map +1 -0
  9. package/{types → dist}/errors.d.ts +30 -16
  10. package/dist/errors.d.ts.map +1 -0
  11. package/{esm → dist}/errors.js +17 -8
  12. package/dist/errors.js.map +1 -0
  13. package/{types → dist}/index.d.ts +1 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/{esm → dist}/index.js +2 -0
  16. package/dist/index.js.map +1 -0
  17. package/{types → dist}/logger.d.ts +11 -0
  18. package/dist/logger.d.ts.map +1 -0
  19. package/{esm → dist}/logger.js +3 -19
  20. package/dist/logger.js.map +1 -0
  21. package/{esm → dist}/objects/commit.js +1 -0
  22. package/dist/objects/commit.js.map +1 -0
  23. package/{esm → dist}/objects/index.js +1 -0
  24. package/dist/objects/index.js.map +1 -0
  25. package/{types → dist}/objects/tree.d.ts.map +1 -1
  26. package/{esm → dist}/objects/tree.js +2 -2
  27. package/dist/objects/tree.js.map +1 -0
  28. package/{esm → dist}/pack/delta.js +1 -0
  29. package/dist/pack/delta.js.map +1 -0
  30. package/{esm → dist}/pack/index.js +1 -0
  31. package/dist/pack/index.js.map +1 -0
  32. package/{types → dist}/pack/objects.d.ts.map +1 -1
  33. package/{esm → dist}/pack/objects.js +3 -3
  34. package/dist/pack/objects.js.map +1 -0
  35. package/{types → dist}/pack/parser.d.ts +19 -3
  36. package/dist/pack/parser.d.ts.map +1 -0
  37. package/{esm → dist}/pack/parser.js +46 -15
  38. package/dist/pack/parser.js.map +1 -0
  39. package/{esm → dist}/protocol/index.js +1 -0
  40. package/dist/protocol/index.js.map +1 -0
  41. package/{types → dist}/protocol/pkt_line.d.ts +3 -3
  42. package/{types → dist}/protocol/pkt_line.d.ts.map +1 -1
  43. package/{esm → dist}/protocol/pkt_line.js +1 -0
  44. package/dist/protocol/pkt_line.js.map +1 -0
  45. package/{esm → dist}/protocol/refs.js +1 -0
  46. package/dist/protocol/refs.js.map +1 -0
  47. package/{types → dist}/protocol/upload_pack.d.ts +1 -0
  48. package/{types → dist}/protocol/upload_pack.d.ts.map +1 -1
  49. package/{esm → dist}/protocol/upload_pack.js +10 -1
  50. package/dist/protocol/upload_pack.js.map +1 -0
  51. package/dist/store.d.ts +28 -0
  52. package/dist/store.d.ts.map +1 -0
  53. package/dist/store.js +179 -0
  54. package/dist/store.js.map +1 -0
  55. package/{types → dist}/transport.d.ts +15 -2
  56. package/dist/transport.d.ts.map +1 -0
  57. package/{esm → dist}/transport.js +44 -15
  58. package/dist/transport.js.map +1 -0
  59. package/{types → dist}/types.d.ts +12 -7
  60. package/dist/types.d.ts.map +1 -0
  61. package/{esm → dist}/types.js +1 -0
  62. package/dist/types.js.map +1 -0
  63. package/package.json +42 -29
  64. package/esm/_dnt.shims.js +0 -72
  65. package/esm/cli.js +0 -217
  66. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_argument_types.js +0 -1
  67. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_errors.js +0 -133
  68. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_spread.js +0 -1
  69. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_type_utils.js +0 -1
  70. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_utils.js +0 -141
  71. package/esm/deps/jsr.io/@cliffy/command/1.1.0/command.js +0 -1861
  72. package/esm/deps/jsr.io/@cliffy/command/1.1.0/help/_help_generator.js +0 -357
  73. package/esm/deps/jsr.io/@cliffy/command/1.1.0/mod.js +0 -13
  74. package/esm/deps/jsr.io/@cliffy/command/1.1.0/type.js +0 -27
  75. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/action_list.js +0 -16
  76. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/boolean.js +0 -13
  77. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/child_command.js +0 -14
  78. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/command.js +0 -9
  79. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/enum.js +0 -24
  80. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/file.js +0 -12
  81. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/integer.js +0 -9
  82. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/number.js +0 -9
  83. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/secret.js +0 -7
  84. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/string.js +0 -9
  85. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types.js +0 -2
  86. package/esm/deps/jsr.io/@cliffy/command/1.1.0/upgrade/_check_version.js +0 -26
  87. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/_errors.js +0 -129
  88. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/_utils.js +0 -100
  89. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/_validate_flags.js +0 -166
  90. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/flags.js +0 -750
  91. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/mod.js +0 -55
  92. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/boolean.js +0 -11
  93. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/integer.js +0 -9
  94. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/number.js +0 -11
  95. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/string.js +0 -4
  96. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types.js +0 -1
  97. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/exit.js +0 -16
  98. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_args.js +0 -11
  99. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_columns.js +0 -25
  100. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_env.js +0 -18
  101. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/inspect.js +0 -11
  102. package/esm/deps/jsr.io/@cliffy/table/1.1.0/_layout.js +0 -616
  103. package/esm/deps/jsr.io/@cliffy/table/1.1.0/_utils.js +0 -79
  104. package/esm/deps/jsr.io/@cliffy/table/1.1.0/border.js +0 -18
  105. package/esm/deps/jsr.io/@cliffy/table/1.1.0/cell.js +0 -190
  106. package/esm/deps/jsr.io/@cliffy/table/1.1.0/column.js +0 -117
  107. package/esm/deps/jsr.io/@cliffy/table/1.1.0/consume_words.js +0 -64
  108. package/esm/deps/jsr.io/@cliffy/table/1.1.0/mod.js +0 -42
  109. package/esm/deps/jsr.io/@cliffy/table/1.1.0/row.js +0 -82
  110. package/esm/deps/jsr.io/@cliffy/table/1.1.0/table.js +0 -341
  111. package/esm/deps/jsr.io/@cliffy/table/1.1.0/unicode_width.js +0 -101
  112. package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.js +0 -2
  113. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.js +0 -237
  114. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.js +0 -2277
  115. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.js +0 -46
  116. package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.js +0 -132
  117. package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.js +0 -270
  118. package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.js +0 -23
  119. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +0 -61
  120. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  121. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  122. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  123. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  124. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.js +0 -903
  125. package/esm/deps/jsr.io/@std/text/1.0.18/closest_string.js +0 -46
  126. package/esm/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.js +0 -127
  127. package/esm/package.json +0 -3
  128. package/types/_dnt.shims.d.ts +0 -16
  129. package/types/_dnt.shims.d.ts.map +0 -1
  130. package/types/client.d.ts.map +0 -1
  131. package/types/deps/jsr.io/@cliffy/command/1.1.0/_argument_types.d.ts +0 -163
  132. package/types/deps/jsr.io/@cliffy/command/1.1.0/_argument_types.d.ts.map +0 -1
  133. package/types/deps/jsr.io/@cliffy/command/1.1.0/_errors.d.ts +0 -71
  134. package/types/deps/jsr.io/@cliffy/command/1.1.0/_errors.d.ts.map +0 -1
  135. package/types/deps/jsr.io/@cliffy/command/1.1.0/_spread.d.ts +0 -16
  136. package/types/deps/jsr.io/@cliffy/command/1.1.0/_spread.d.ts.map +0 -1
  137. package/types/deps/jsr.io/@cliffy/command/1.1.0/_type_utils.d.ts +0 -15
  138. package/types/deps/jsr.io/@cliffy/command/1.1.0/_type_utils.d.ts.map +0 -1
  139. package/types/deps/jsr.io/@cliffy/command/1.1.0/_utils.d.ts +0 -38
  140. package/types/deps/jsr.io/@cliffy/command/1.1.0/_utils.d.ts.map +0 -1
  141. package/types/deps/jsr.io/@cliffy/command/1.1.0/command.d.ts +0 -1086
  142. package/types/deps/jsr.io/@cliffy/command/1.1.0/command.d.ts.map +0 -1
  143. package/types/deps/jsr.io/@cliffy/command/1.1.0/help/_help_generator.d.ts +0 -33
  144. package/types/deps/jsr.io/@cliffy/command/1.1.0/help/_help_generator.d.ts.map +0 -1
  145. package/types/deps/jsr.io/@cliffy/command/1.1.0/mod.d.ts +0 -78
  146. package/types/deps/jsr.io/@cliffy/command/1.1.0/mod.d.ts.map +0 -1
  147. package/types/deps/jsr.io/@cliffy/command/1.1.0/type.d.ts +0 -51
  148. package/types/deps/jsr.io/@cliffy/command/1.1.0/type.d.ts.map +0 -1
  149. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/action_list.d.ts +0 -10
  150. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/action_list.d.ts.map +0 -1
  151. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/boolean.d.ts +0 -10
  152. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/boolean.d.ts.map +0 -1
  153. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/child_command.d.ts +0 -10
  154. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/child_command.d.ts.map +0 -1
  155. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/command.d.ts +0 -8
  156. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/command.d.ts.map +0 -1
  157. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/enum.d.ts +0 -11
  158. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/enum.d.ts.map +0 -1
  159. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/file.d.ts +0 -6
  160. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/file.d.ts.map +0 -1
  161. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/integer.d.ts +0 -8
  162. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/integer.d.ts.map +0 -1
  163. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/number.d.ts +0 -8
  164. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/number.d.ts.map +0 -1
  165. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/secret.d.ts +0 -6
  166. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/secret.d.ts.map +0 -1
  167. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/string.d.ts +0 -8
  168. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/string.d.ts.map +0 -1
  169. package/types/deps/jsr.io/@cliffy/command/1.1.0/types.d.ts +0 -161
  170. package/types/deps/jsr.io/@cliffy/command/1.1.0/types.d.ts.map +0 -1
  171. package/types/deps/jsr.io/@cliffy/command/1.1.0/upgrade/_check_version.d.ts +0 -4
  172. package/types/deps/jsr.io/@cliffy/command/1.1.0/upgrade/_check_version.d.ts.map +0 -1
  173. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_errors.d.ts +0 -67
  174. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_errors.d.ts.map +0 -1
  175. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_utils.d.ts +0 -17
  176. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_utils.d.ts.map +0 -1
  177. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_validate_flags.d.ts +0 -11
  178. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_validate_flags.d.ts.map +0 -1
  179. package/types/deps/jsr.io/@cliffy/flags/1.1.0/flags.d.ts +0 -154
  180. package/types/deps/jsr.io/@cliffy/flags/1.1.0/flags.d.ts.map +0 -1
  181. package/types/deps/jsr.io/@cliffy/flags/1.1.0/mod.d.ts +0 -57
  182. package/types/deps/jsr.io/@cliffy/flags/1.1.0/mod.d.ts.map +0 -1
  183. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/boolean.d.ts +0 -4
  184. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/boolean.d.ts.map +0 -1
  185. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/integer.d.ts +0 -4
  186. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/integer.d.ts.map +0 -1
  187. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/number.d.ts +0 -4
  188. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/number.d.ts.map +0 -1
  189. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/string.d.ts +0 -4
  190. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/string.d.ts.map +0 -1
  191. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types.d.ts +0 -170
  192. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types.d.ts.map +0 -1
  193. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/exit.d.ts +0 -8
  194. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/exit.d.ts.map +0 -1
  195. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_args.d.ts +0 -7
  196. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_args.d.ts.map +0 -1
  197. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_columns.d.ts +0 -7
  198. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_columns.d.ts.map +0 -1
  199. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_env.d.ts +0 -8
  200. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_env.d.ts.map +0 -1
  201. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/inspect.d.ts +0 -7
  202. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/inspect.d.ts.map +0 -1
  203. package/types/deps/jsr.io/@cliffy/table/1.1.0/_layout.d.ts +0 -108
  204. package/types/deps/jsr.io/@cliffy/table/1.1.0/_layout.d.ts.map +0 -1
  205. package/types/deps/jsr.io/@cliffy/table/1.1.0/_utils.d.ts +0 -26
  206. package/types/deps/jsr.io/@cliffy/table/1.1.0/_utils.d.ts.map +0 -1
  207. package/types/deps/jsr.io/@cliffy/table/1.1.0/border.d.ts +0 -21
  208. package/types/deps/jsr.io/@cliffy/table/1.1.0/border.d.ts.map +0 -1
  209. package/types/deps/jsr.io/@cliffy/table/1.1.0/cell.d.ts +0 -155
  210. package/types/deps/jsr.io/@cliffy/table/1.1.0/cell.d.ts.map +0 -1
  211. package/types/deps/jsr.io/@cliffy/table/1.1.0/column.d.ts +0 -97
  212. package/types/deps/jsr.io/@cliffy/table/1.1.0/column.d.ts.map +0 -1
  213. package/types/deps/jsr.io/@cliffy/table/1.1.0/consume_words.d.ts +0 -30
  214. package/types/deps/jsr.io/@cliffy/table/1.1.0/consume_words.d.ts.map +0 -1
  215. package/types/deps/jsr.io/@cliffy/table/1.1.0/mod.d.ts +0 -43
  216. package/types/deps/jsr.io/@cliffy/table/1.1.0/mod.d.ts.map +0 -1
  217. package/types/deps/jsr.io/@cliffy/table/1.1.0/row.d.ts +0 -67
  218. package/types/deps/jsr.io/@cliffy/table/1.1.0/row.d.ts.map +0 -1
  219. package/types/deps/jsr.io/@cliffy/table/1.1.0/table.d.ts +0 -235
  220. package/types/deps/jsr.io/@cliffy/table/1.1.0/table.d.ts.map +0 -1
  221. package/types/deps/jsr.io/@cliffy/table/1.1.0/unicode_width.d.ts +0 -40
  222. package/types/deps/jsr.io/@cliffy/table/1.1.0/unicode_width.d.ts.map +0 -1
  223. package/types/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts +0 -9
  224. package/types/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts.map +0 -1
  225. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts +0 -2
  226. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts.map +0 -1
  227. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts +0 -69
  228. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts.map +0 -1
  229. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts +0 -13
  230. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts.map +0 -1
  231. package/types/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts +0 -76
  232. package/types/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts.map +0 -1
  233. package/types/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts +0 -149
  234. package/types/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts.map +0 -1
  235. package/types/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts +0 -22
  236. package/types/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts.map +0 -1
  237. package/types/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +0 -40
  238. package/types/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts.map +0 -1
  239. package/types/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  240. package/types/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  241. package/types/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  242. package/types/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  243. package/types/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  244. package/types/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  245. package/types/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  246. package/types/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  247. package/types/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts +0 -700
  248. package/types/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts.map +0 -1
  249. package/types/deps/jsr.io/@std/text/1.0.18/closest_string.d.ts +0 -42
  250. package/types/deps/jsr.io/@std/text/1.0.18/closest_string.d.ts.map +0 -1
  251. package/types/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.d.ts +0 -23
  252. package/types/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.d.ts.map +0 -1
  253. package/types/errors.d.ts.map +0 -1
  254. package/types/index.d.ts.map +0 -1
  255. package/types/logger.d.ts.map +0 -1
  256. package/types/pack/parser.d.ts.map +0 -1
  257. package/types/transport.d.ts.map +0 -1
  258. package/types/types.d.ts.map +0 -1
  259. /package/{types → dist}/cli.d.ts +0 -0
  260. /package/{types → dist}/cli.d.ts.map +0 -0
  261. /package/{types → dist}/objects/commit.d.ts +0 -0
  262. /package/{types → dist}/objects/commit.d.ts.map +0 -0
  263. /package/{types → dist}/objects/index.d.ts +0 -0
  264. /package/{types → dist}/objects/index.d.ts.map +0 -0
  265. /package/{types → dist}/objects/tree.d.ts +0 -0
  266. /package/{types → dist}/pack/delta.d.ts +0 -0
  267. /package/{types → dist}/pack/delta.d.ts.map +0 -0
  268. /package/{types → dist}/pack/index.d.ts +0 -0
  269. /package/{types → dist}/pack/index.d.ts.map +0 -0
  270. /package/{types → dist}/pack/objects.d.ts +0 -0
  271. /package/{types → dist}/protocol/index.d.ts +0 -0
  272. /package/{types → dist}/protocol/index.d.ts.map +0 -0
  273. /package/{types → dist}/protocol/refs.d.ts +0 -0
  274. /package/{types → dist}/protocol/refs.d.ts.map +0 -0
@@ -1,616 +0,0 @@
1
- import { Cell } from "./cell.js";
2
- import { consumeChars, consumeWords } from "./consume_words.js";
3
- import { Row } from "./row.js";
4
- import { getUnclosedAnsiRuns, longest, strLength } from "./_utils.js";
5
- const sum = (numList) => numList.reduce((a, b) => a + b, 0);
6
- /** Table layout renderer. */
7
- export class TableLayout {
8
- table;
9
- options;
10
- /**
11
- * Table layout constructor.
12
- * @param table Table instance.
13
- * @param options Render options.
14
- */
15
- constructor(table, options) {
16
- this.table = table;
17
- this.options = options;
18
- }
19
- /** Generate table string. */
20
- toString() {
21
- const opts = this.createLayout();
22
- return opts.rows.length ? this.renderRows(opts) : "";
23
- }
24
- /**
25
- * Generates table layout including row and col span, converts all none
26
- * Cell/Row values to Cells and Rows and returns the layout rendering
27
- * settings.
28
- */
29
- createLayout() {
30
- Object.keys(this.options.chars).forEach((key) => {
31
- if (typeof this.options.chars[key] !== "string") {
32
- this.options.chars[key] = "";
33
- }
34
- });
35
- const hasBodyBorder = this.table.getBorder() ||
36
- this.table.hasBodyBorder();
37
- const hasHeaderBorder = this.table.hasHeaderBorder();
38
- const hasBorder = hasHeaderBorder || hasBodyBorder;
39
- const rows = this.#getRows();
40
- const columns = Math.max(...rows.map((row) => row.length));
41
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
42
- const row = rows[rowIndex];
43
- const length = row.length;
44
- if (length < columns) {
45
- const diff = columns - length;
46
- for (let i = 0; i < diff; i++) {
47
- row.push(this.createCell(null, row, rowIndex, length + i));
48
- }
49
- }
50
- }
51
- const { padding, width, minColWidth, maxColWidth, } = this.computeColumnDimensions(columns, rows);
52
- if (isFinite(this.options.maxWidth)) {
53
- const totalPadding = hasBorder
54
- ? sum(padding) * 2 + (columns + 1)
55
- : sum(padding.slice(0, -1));
56
- const maxAllowable = this.options.maxWidth - totalPadding;
57
- if (sum(width) > maxAllowable) {
58
- this.applyFlexShrink(width, minColWidth, maxAllowable);
59
- }
60
- if (sum(width) < maxAllowable) {
61
- this.applyFlexGrow(width, maxColWidth, maxAllowable);
62
- }
63
- }
64
- return {
65
- padding,
66
- width,
67
- rows,
68
- columns,
69
- hasBorder,
70
- hasBodyBorder,
71
- hasHeaderBorder,
72
- };
73
- }
74
- computeColumnDimensions(columns, rows) {
75
- const padding = [];
76
- const width = [];
77
- const minColWidth = [];
78
- const maxColWidth = [];
79
- for (let colIndex = 0; colIndex < columns; colIndex++) {
80
- const column = this.options.columns.at(colIndex);
81
- minColWidth[colIndex] = column?.getMinWidth() ??
82
- (Array.isArray(this.options.minColWidth)
83
- ? this.options.minColWidth[colIndex]
84
- : this.options.minColWidth) ??
85
- 0;
86
- maxColWidth[colIndex] = column?.getMaxWidth() ??
87
- (Array.isArray(this.options.maxColWidth)
88
- ? this.options.maxColWidth[colIndex]
89
- : this.options.maxColWidth) ??
90
- Infinity;
91
- const colWidth = longest(colIndex, rows, maxColWidth[colIndex]);
92
- width[colIndex] = Math.min(maxColWidth[colIndex], Math.max(minColWidth[colIndex], colWidth));
93
- padding[colIndex] = column?.getPadding() ??
94
- (Array.isArray(this.options.padding)
95
- ? this.options.padding[colIndex]
96
- : this.options.padding) ??
97
- 0;
98
- }
99
- return { padding, width, minColWidth, maxColWidth };
100
- }
101
- applyFlexShrink(width, minColWidth, maxAllowable) {
102
- const shrink = width.map((_w, i) => this.resolveColumnWeight("flexShrink", i));
103
- let changed = true;
104
- while (changed) {
105
- changed = false;
106
- if (sum(width) <= maxAllowable) {
107
- break;
108
- }
109
- const overflow = sum(width) - maxAllowable;
110
- // CSS flex-shrink: each column's reduction share is proportional to
111
- // shrink × width, so wider or higher-weighted columns absorb more.
112
- const scaledTotal = sum(width.map((w, i) => shrink[i] > 0 && w > minColWidth[i] ? shrink[i] * w : 0));
113
- if (scaledTotal === 0) {
114
- break;
115
- }
116
- for (let i = 0; i < width.length; i++) {
117
- if (shrink[i] > 0 && width[i] > minColWidth[i]) {
118
- const target = Math.max(Math.max(1, minColWidth[i]), Math.floor(width[i] * (1 - overflow * shrink[i] / scaledTotal)));
119
- if (target !== width[i]) {
120
- width[i] = target;
121
- changed = true;
122
- }
123
- }
124
- }
125
- }
126
- }
127
- applyFlexGrow(width, maxColWidth, maxAllowable) {
128
- const grow = width.map((_w, i) => this.resolveColumnWeight("flexGrow", i));
129
- let changed = true;
130
- while (changed) {
131
- changed = false;
132
- if (sum(width) >= maxAllowable) {
133
- break;
134
- }
135
- const slack = maxAllowable - sum(width);
136
- // CSS flex-grow: available slack is distributed proportionally by weight.
137
- const totalWeight = sum(grow.map((g, i) => width[i] < maxColWidth[i] ? g : 0));
138
- if (totalWeight === 0) {
139
- break;
140
- }
141
- for (let i = 0; i < width.length; i++) {
142
- if (grow[i] > 0 && width[i] < maxColWidth[i]) {
143
- const extra = Math.floor(slack * grow[i] / totalWeight);
144
- const newWidth = Math.min(maxColWidth[i], width[i] + extra);
145
- if (newWidth !== width[i]) {
146
- width[i] = newWidth;
147
- changed = true;
148
- }
149
- }
150
- }
151
- }
152
- }
153
- resolveColumnWeight(prop, i) {
154
- const getter = prop === "flexShrink" ? "getFlexShrink" : "getFlexGrow";
155
- const weight = this.options.columns.at(i)?.[getter]() ??
156
- (Array.isArray(this.options[prop])
157
- ? this.options[prop][i]
158
- : this.options[prop]);
159
- return Number.isFinite(weight) && weight > 0 ? weight : 0;
160
- }
161
- #getRows() {
162
- const header = this.table.getHeader();
163
- const rows = header ? [header, ...this.table] : this.table.slice();
164
- const hasSpan = rows.some((row) => row.some((cell) => cell instanceof Cell && (cell.getColSpan() > 1 || cell.getRowSpan() > 1)));
165
- if (hasSpan) {
166
- return this.spanRows(rows);
167
- }
168
- return rows.map((row, rowIndex) => {
169
- const newRow = this.createRow(row);
170
- for (let colIndex = 0; colIndex < row.length; colIndex++) {
171
- newRow[colIndex] = this.createCell(row[colIndex], newRow, rowIndex, colIndex);
172
- }
173
- return newRow;
174
- });
175
- }
176
- /**
177
- * Fills rows and cols by specified row/col span with a reference of the
178
- * original cell.
179
- */
180
- spanRows(rows) {
181
- const rowSpan = [];
182
- let colSpan = 1;
183
- let rowIndex = -1;
184
- while (true) {
185
- rowIndex++;
186
- if (rowIndex === rows.length && rowSpan.every((span) => span === 1)) {
187
- break;
188
- }
189
- const row = rows[rowIndex] = this.createRow(rows[rowIndex] || []);
190
- let colIndex = -1;
191
- while (true) {
192
- colIndex++;
193
- if (colIndex === row.length &&
194
- colIndex === rowSpan.length && colSpan === 1) {
195
- break;
196
- }
197
- if (colSpan > 1) {
198
- colSpan--;
199
- rowSpan[colIndex] = rowSpan[colIndex - 1];
200
- row.splice(colIndex, this.getDeleteCount(rows, rowIndex, colIndex), row[colIndex - 1]);
201
- continue;
202
- }
203
- if (rowSpan[colIndex] > 1) {
204
- rowSpan[colIndex]--;
205
- rows[rowIndex].splice(colIndex, this.getDeleteCount(rows, rowIndex, colIndex), rows[rowIndex - 1][colIndex]);
206
- continue;
207
- }
208
- const cell = row[colIndex] = this.createCell(row[colIndex] || null, row, rowIndex, colIndex);
209
- colSpan = cell.getColSpan();
210
- rowSpan[colIndex] = cell.getRowSpan();
211
- }
212
- }
213
- return rows;
214
- }
215
- getDeleteCount(rows, rowIndex, colIndex) {
216
- return colIndex <= rows[rowIndex].length - 1 &&
217
- typeof rows[rowIndex][colIndex] === "undefined"
218
- ? 1
219
- : 0;
220
- }
221
- /**
222
- * Create a new row from existing row or cell array.
223
- * @param row Original row.
224
- */
225
- createRow(row) {
226
- return Row.from(row)
227
- .border(this.table.getBorder(), false)
228
- .align(this.table.getAlign(), false);
229
- }
230
- /**
231
- * Create a new cell from existing cell or cell value.
232
- *
233
- * @param cell Original cell.
234
- * @param row Parent row.
235
- * @param rowIndex The row index of the cell.
236
- * @param colIndex The column index of the cell.
237
- */
238
- createCell(cell, row, rowIndex, colIndex) {
239
- const column = this.options.columns.at(colIndex);
240
- const isHeaderRow = this.isHeaderRow(rowIndex);
241
- return Cell.from(cell ?? "")
242
- .border((isHeaderRow ? null : column?.getBorder()) ?? row.getBorder(), false)
243
- .align((isHeaderRow ? null : column?.getAlign()) ?? row.getAlign(), false);
244
- }
245
- isHeaderRow(rowIndex) {
246
- return rowIndex === 0 && this.table.getHeader() !== undefined;
247
- }
248
- /**
249
- * Render table layout.
250
- * @param opts Render options.
251
- */
252
- renderRows(opts) {
253
- let result = "";
254
- const rowSpan = new Array(opts.columns).fill(1);
255
- for (let rowIndex = 0; rowIndex < opts.rows.length; rowIndex++) {
256
- result += this.renderRow(rowSpan, rowIndex, opts);
257
- }
258
- return result.slice(0, -1);
259
- }
260
- /**
261
- * Render row.
262
- * @param rowSpan Current row span.
263
- * @param rowIndex Current row index.
264
- * @param opts Render options.
265
- * @param isMultiline Is multiline row.
266
- */
267
- renderRow(rowSpan, rowIndex, opts, isMultiline) {
268
- const row = opts.rows[rowIndex];
269
- const prevRow = opts.rows[rowIndex - 1];
270
- const nextRow = opts.rows[rowIndex + 1];
271
- let result = "";
272
- let colSpan = 1;
273
- // border top row
274
- if (!isMultiline && rowIndex === 0 && row.hasBorder()) {
275
- result += this.renderBorderRow(undefined, row, rowSpan, opts);
276
- }
277
- let isMultilineRow = false;
278
- result += " ".repeat(this.options.indent || 0);
279
- for (let colIndex = 0; colIndex < opts.columns; colIndex++) {
280
- if (colSpan > 1) {
281
- colSpan--;
282
- rowSpan[colIndex] = rowSpan[colIndex - 1];
283
- continue;
284
- }
285
- result += this.renderCell(colIndex, row, opts);
286
- if (rowSpan[colIndex] > 1) {
287
- if (!isMultiline) {
288
- rowSpan[colIndex]--;
289
- }
290
- }
291
- else if (!prevRow || prevRow[colIndex] !== row[colIndex]) {
292
- rowSpan[colIndex] = row[colIndex].getRowSpan();
293
- }
294
- colSpan = row[colIndex].getColSpan();
295
- if (rowSpan[colIndex] === 1 && row[colIndex].length) {
296
- isMultilineRow = true;
297
- }
298
- }
299
- if (opts.columns > 0) {
300
- if (row[opts.columns - 1].getBorder()) {
301
- result += this.options.chars.right;
302
- }
303
- else if (opts.hasBorder) {
304
- result += " ";
305
- }
306
- }
307
- result += "\n";
308
- if (isMultilineRow) { // skip border
309
- return result + this.renderRow(rowSpan, rowIndex, opts, isMultilineRow);
310
- }
311
- // border mid row
312
- if ((opts.rows.length > 1) &&
313
- ((rowIndex === 0 && opts.hasHeaderBorder) ||
314
- (rowIndex < opts.rows.length - 1 && opts.hasBodyBorder))) {
315
- result += this.renderBorderRow(row, nextRow, rowSpan, opts);
316
- }
317
- // border bottom row
318
- if (rowIndex === opts.rows.length - 1 && row.hasBorder()) {
319
- result += this.renderBorderRow(row, undefined, rowSpan, opts);
320
- }
321
- return result;
322
- }
323
- /**
324
- * Render cell.
325
- * @param colIndex Current col index.
326
- * @param row Current row.
327
- * @param opts Render options.
328
- * @param noBorder Disable border.
329
- */
330
- renderCell(colIndex, row, opts, noBorder) {
331
- let result = "";
332
- const prevCell = row[colIndex - 1];
333
- const cell = row[colIndex];
334
- if (!noBorder) {
335
- if (colIndex === 0) {
336
- if (cell.getBorder()) {
337
- result += this.options.chars.left;
338
- }
339
- else if (opts.hasBorder) {
340
- result += " ";
341
- }
342
- }
343
- else {
344
- if (cell.getBorder() || prevCell?.getBorder()) {
345
- result += this.options.chars.middle;
346
- }
347
- else if (opts.hasBorder) {
348
- result += " ";
349
- }
350
- }
351
- }
352
- let maxLength = opts.width[colIndex];
353
- const colSpan = cell.getColSpan();
354
- if (colSpan > 1) {
355
- for (let o = 1; o < colSpan; o++) {
356
- // add padding and with of next cell
357
- maxLength += opts.width[colIndex + o] + opts.padding[colIndex + o];
358
- if (opts.hasBorder) {
359
- // add padding again and border with
360
- maxLength += opts.padding[colIndex + o] + 1;
361
- }
362
- }
363
- }
364
- const { current, next } = this.renderCellValue(cell, maxLength);
365
- row[colIndex].setValue(next);
366
- if (opts.hasBorder) {
367
- result += " ".repeat(opts.padding[colIndex]);
368
- }
369
- result += current;
370
- if (opts.hasBorder || colIndex < opts.columns - 1) {
371
- result += " ".repeat(opts.padding[colIndex]);
372
- }
373
- return result;
374
- }
375
- /**
376
- * Render specified length of cell. Returns the rendered value and a new cell
377
- * with the rest value.
378
- * @param cell Cell to render.
379
- * @param maxLength Max length of content to render.
380
- */
381
- renderCellValue(cell, maxLength) {
382
- if (maxLength <= 0) {
383
- return { current: "", next: "" };
384
- }
385
- const length = Math.min(maxLength, strLength(cell.toString()));
386
- let words = consumeWords(length, cell.toString());
387
- // break word if word is longer than max length
388
- const breakWord = strLength(words) > length;
389
- if (breakWord) {
390
- words = consumeChars(length, words);
391
- }
392
- // get next content and remove leading space if breakWord is not true
393
- // calculate from words.length _before_ any handling of unclosed ANSI codes
394
- const next = cell.toString().slice(words.length + (breakWord ? 0 : 1));
395
- words = cell.unclosedAnsiRuns + words;
396
- const { currentSuffix, nextPrefix } = getUnclosedAnsiRuns(words);
397
- words += currentSuffix;
398
- cell.unclosedAnsiRuns = nextPrefix;
399
- const fillLength = maxLength - strLength(words);
400
- // Align content
401
- const align = cell.getAlign();
402
- let current;
403
- if (fillLength === 0) {
404
- current = words;
405
- }
406
- else if (align === "left") {
407
- current = words + " ".repeat(fillLength);
408
- }
409
- else if (align === "center") {
410
- current = " ".repeat(Math.floor(fillLength / 2)) + words +
411
- " ".repeat(Math.ceil(fillLength / 2));
412
- }
413
- else if (align === "right") {
414
- current = " ".repeat(fillLength) + words;
415
- }
416
- else {
417
- throw new Error("Unknown direction: " + align);
418
- }
419
- return { current, next };
420
- }
421
- /**
422
- * Render border row.
423
- * @param prevRow Previous row.
424
- * @param nextRow Next row.
425
- * @param rowSpan Current row span.
426
- * @param opts Render options.
427
- */
428
- renderBorderRow(prevRow, nextRow, rowSpan, opts) {
429
- let result = "";
430
- let colSpan = 1;
431
- for (let colIndex = 0; colIndex < opts.columns; colIndex++) {
432
- if (rowSpan[colIndex] > 1) {
433
- if (!nextRow) {
434
- throw new Error("invalid layout");
435
- }
436
- if (colSpan > 1) {
437
- colSpan--;
438
- continue;
439
- }
440
- }
441
- result += this.renderBorderCell(colIndex, prevRow, nextRow, rowSpan, opts);
442
- colSpan = nextRow?.[colIndex].getColSpan() ?? 1;
443
- }
444
- return result.length ? " ".repeat(this.options.indent) + result + "\n" : "";
445
- }
446
- /**
447
- * Render border cell.
448
- * @param colIndex Current index.
449
- * @param prevRow Previous row.
450
- * @param nextRow Next row.
451
- * @param rowSpan Current row span.
452
- * @param opts Render options.
453
- */
454
- renderBorderCell(colIndex, prevRow, nextRow, rowSpan, opts) {
455
- // a1 | b1
456
- // -------
457
- // a2 | b2
458
- const a1 = prevRow?.[colIndex - 1];
459
- const a2 = nextRow?.[colIndex - 1];
460
- const b1 = prevRow?.[colIndex];
461
- const b2 = nextRow?.[colIndex];
462
- const a1Border = !!a1?.getBorder();
463
- const a2Border = !!a2?.getBorder();
464
- const b1Border = !!b1?.getBorder();
465
- const b2Border = !!b2?.getBorder();
466
- const hasColSpan = (cell) => (cell?.getColSpan() ?? 1) > 1;
467
- const hasRowSpan = (cell) => (cell?.getRowSpan() ?? 1) > 1;
468
- let result = "";
469
- if (colIndex === 0) {
470
- if (rowSpan[colIndex] > 1) {
471
- if (b1Border) {
472
- result += this.options.chars.left;
473
- }
474
- else {
475
- result += " ";
476
- }
477
- }
478
- else if (b1Border && b2Border) {
479
- result += this.options.chars.leftMid;
480
- }
481
- else if (b1Border) {
482
- result += this.options.chars.bottomLeft;
483
- }
484
- else if (b2Border) {
485
- result += this.options.chars.topLeft;
486
- }
487
- else {
488
- result += " ";
489
- }
490
- }
491
- else if (colIndex < opts.columns) {
492
- if ((a1Border && b2Border) || (b1Border && a2Border)) {
493
- const a1ColSpan = hasColSpan(a1);
494
- const a2ColSpan = hasColSpan(a2);
495
- const b1ColSpan = hasColSpan(b1);
496
- const b2ColSpan = hasColSpan(b2);
497
- const a1RowSpan = hasRowSpan(a1);
498
- const a2RowSpan = hasRowSpan(a2);
499
- const b1RowSpan = hasRowSpan(b1);
500
- const b2RowSpan = hasRowSpan(b2);
501
- const hasAllBorder = a1Border && b2Border && b1Border && a2Border;
502
- const hasAllRowSpan = a1RowSpan && b1RowSpan && a2RowSpan && b2RowSpan;
503
- const hasAllColSpan = a1ColSpan && b1ColSpan && a2ColSpan && b2ColSpan;
504
- if (hasAllRowSpan && hasAllBorder) {
505
- result += this.options.chars.middle;
506
- }
507
- else if (hasAllColSpan && hasAllBorder && a1 === b1 && a2 === b2) {
508
- result += this.options.chars.mid;
509
- }
510
- else if (a1ColSpan && b1ColSpan && a1 === b1) {
511
- result += this.options.chars.topMid;
512
- }
513
- else if (a2ColSpan && b2ColSpan && a2 === b2) {
514
- result += this.options.chars.bottomMid;
515
- }
516
- else if (a1RowSpan && a2RowSpan && a1 === a2) {
517
- result += this.options.chars.leftMid;
518
- }
519
- else if (b1RowSpan && b2RowSpan && b1 === b2) {
520
- result += this.options.chars.rightMid;
521
- }
522
- else {
523
- result += this.options.chars.midMid;
524
- }
525
- }
526
- else if (a1Border && b1Border) {
527
- if (hasColSpan(a1) && hasColSpan(b1) && a1 === b1) {
528
- result += this.options.chars.bottom;
529
- }
530
- else {
531
- result += this.options.chars.bottomMid;
532
- }
533
- }
534
- else if (b1Border && b2Border) {
535
- if (rowSpan[colIndex] > 1) {
536
- result += this.options.chars.left;
537
- }
538
- else {
539
- result += this.options.chars.leftMid;
540
- }
541
- }
542
- else if (b2Border && a2Border) {
543
- if (hasColSpan(a2) && hasColSpan(b2) && a2 === b2) {
544
- result += this.options.chars.top;
545
- }
546
- else {
547
- result += this.options.chars.topMid;
548
- }
549
- }
550
- else if (a1Border && a2Border) {
551
- if (hasRowSpan(a1) && a1 === a2) {
552
- result += this.options.chars.right;
553
- }
554
- else {
555
- result += this.options.chars.rightMid;
556
- }
557
- }
558
- else if (a1Border) {
559
- result += this.options.chars.bottomRight;
560
- }
561
- else if (b1Border) {
562
- result += this.options.chars.bottomLeft;
563
- }
564
- else if (a2Border) {
565
- result += this.options.chars.topRight;
566
- }
567
- else if (b2Border) {
568
- result += this.options.chars.topLeft;
569
- }
570
- else {
571
- result += " ";
572
- }
573
- }
574
- const length = opts.padding[colIndex] + opts.width[colIndex] +
575
- opts.padding[colIndex];
576
- if (rowSpan[colIndex] > 1 && nextRow) {
577
- result += this.renderCell(colIndex, nextRow, opts, true);
578
- if (nextRow[colIndex] === nextRow[nextRow.length - 1]) {
579
- if (b1Border) {
580
- result += this.options.chars.right;
581
- }
582
- else {
583
- result += " ";
584
- }
585
- return result;
586
- }
587
- }
588
- else if (b1Border && b2Border) {
589
- result += this.options.chars.mid.repeat(length);
590
- }
591
- else if (b1Border) {
592
- result += this.options.chars.bottom.repeat(length);
593
- }
594
- else if (b2Border) {
595
- result += this.options.chars.top.repeat(length);
596
- }
597
- else {
598
- result += " ".repeat(length);
599
- }
600
- if (colIndex === opts.columns - 1) {
601
- if (b1Border && b2Border) {
602
- result += this.options.chars.rightMid;
603
- }
604
- else if (b1Border) {
605
- result += this.options.chars.bottomRight;
606
- }
607
- else if (b2Border) {
608
- result += this.options.chars.topRight;
609
- }
610
- else {
611
- result += " ";
612
- }
613
- }
614
- return result;
615
- }
616
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Get next words from the beginning of [content] until all words have a length lower or equal then [length].
3
- *
4
- * @param length Max length of all words.
5
- * @param content The text content.
6
- */
7
- import { Cell } from "./cell.js";
8
- import { consumeWords } from "./consume_words.js";
9
- import { stripAnsiCode } from "../../../@std/fmt/1.0.10/colors.js";
10
- import { unicodeWidth } from "./unicode_width.js";
11
- // import { unicodeWidth } from "@std/cli/unicode-width";
12
- /**
13
- * Get longest cell from given row index.
14
- */
15
- export function longest(index, rows, maxWidth) {
16
- const cellLengths = rows.map((row) => {
17
- const cell = row[index];
18
- const cellValue = cell instanceof Cell && cell.getColSpan() > 1
19
- ? ""
20
- : cell?.toString() || "";
21
- return cellValue
22
- .split("\n")
23
- .map((line) => {
24
- const str = typeof maxWidth === "undefined"
25
- ? line
26
- : consumeWords(maxWidth, line);
27
- return strLength(str) || 0;
28
- });
29
- }).flat();
30
- return Math.max(...cellLengths);
31
- }
32
- export const strLength = (str) => {
33
- return unicodeWidth(stripAnsiCode(str));
34
- };
35
- /** Regex `source` to match any relevant ANSI code. */
36
- export const ansiRegexSource =
37
- // deno-lint-ignore no-control-regex
38
- /\x1b\[(?:(?<_0>0)|(?<_22>1|2|22)|(?<_23>3|23)|(?<_24>4|24)|(?<_27>7|27)|(?<_28>8|28)|(?<_29>9|29)|(?<_39>30|31|32|33|34|35|36|37|38;2;\d+;\d+;\d+|38;5;\d+|39|90|91|92|93|94|95|96|97)|(?<_49>40|41|42|43|44|45|46|47|48;2;\d+;\d+;\d+|48;5;\d+|49|100|101|102|103|104|105|106|107))m/
39
- .source;
40
- /**
41
- * Get unclosed ANSI runs in a string.
42
- *
43
- * @param text - A string segment possibly containing unclosed ANSI runs.
44
- */
45
- export function getUnclosedAnsiRuns(text) {
46
- const tokens = [];
47
- for (const { groups } of text.matchAll(new RegExp(ansiRegexSource, "g"))) {
48
- if (!groups) {
49
- continue;
50
- }
51
- const entry = Object.entries(groups).find(([_, val]) => val);
52
- if (!entry) {
53
- continue;
54
- }
55
- const [_kind, content] = entry;
56
- tokens.push({ kind: _kind.slice(1), content });
57
- }
58
- let unclosed = [];
59
- for (const token of tokens) {
60
- // Subsequent ANSI codes of a given kind automatically "close" previous
61
- // codes of the same kind, so we remove the previous ones.
62
- // E.g. in the string `${bg_red} A ${bg_yellow} B ${close_bg} C`, "B" only
63
- // has a single background color (yellow), and "C" has no background color.
64
- unclosed = [...unclosed.filter((y) => y.kind !== token.kind), token];
65
- }
66
- unclosed = unclosed.filter(({ content, kind }) => content !== kind);
67
- const currentSuffix = unclosed
68
- .map(({ kind }) => `\x1b[${kind}m`).reverse().join("");
69
- const nextPrefix = unclosed.map(({ content }) => `\x1b[${content}m`).join("");
70
- return {
71
- /** The suffix to be appended to the text to close all unclosed runs. */
72
- currentSuffix,
73
- /**
74
- * The prefix to be appended to the next segment to continue unclosed
75
- * runs if the input text forms the first segment of a multi-line string.
76
- */
77
- nextPrefix,
78
- };
79
- }