@shell-shock/preset-script 0.6.3 → 0.6.5

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 (80) hide show
  1. package/README.md +1 -1
  2. package/dist/components/banner-function-declaration.cjs +13 -7
  3. package/dist/components/banner-function-declaration.cjs.map +1 -1
  4. package/dist/components/banner-function-declaration.d.cts +2 -0
  5. package/dist/components/banner-function-declaration.d.cts.map +1 -1
  6. package/dist/components/banner-function-declaration.d.mts +2 -0
  7. package/dist/components/banner-function-declaration.d.mts.map +1 -1
  8. package/dist/components/banner-function-declaration.mjs +15 -9
  9. package/dist/components/banner-function-declaration.mjs.map +1 -1
  10. package/dist/components/bin-entry.cjs +4 -10
  11. package/dist/components/bin-entry.cjs.map +1 -1
  12. package/dist/components/bin-entry.d.cts.map +1 -1
  13. package/dist/components/bin-entry.d.mts.map +1 -1
  14. package/dist/components/bin-entry.mjs +4 -10
  15. package/dist/components/bin-entry.mjs.map +1 -1
  16. package/dist/components/command-entry.cjs +13 -12
  17. package/dist/components/command-entry.cjs.map +1 -1
  18. package/dist/components/command-entry.d.cts +1 -0
  19. package/dist/components/command-entry.d.cts.map +1 -1
  20. package/dist/components/command-entry.d.mts +1 -0
  21. package/dist/components/command-entry.d.mts.map +1 -1
  22. package/dist/components/command-entry.mjs +13 -12
  23. package/dist/components/command-entry.mjs.map +1 -1
  24. package/dist/components/command-router.cjs +2 -2
  25. package/dist/components/command-router.cjs.map +1 -1
  26. package/dist/components/command-router.d.cts.map +1 -1
  27. package/dist/components/command-router.d.mts.map +1 -1
  28. package/dist/components/command-router.mjs +2 -2
  29. package/dist/components/command-router.mjs.map +1 -1
  30. package/dist/components/console-builtin.cjs +773 -102
  31. package/dist/components/console-builtin.cjs.map +1 -1
  32. package/dist/components/console-builtin.d.cts +2 -2
  33. package/dist/components/console-builtin.d.cts.map +1 -1
  34. package/dist/components/console-builtin.d.mts +2 -2
  35. package/dist/components/console-builtin.d.mts.map +1 -1
  36. package/dist/components/console-builtin.mjs +774 -104
  37. package/dist/components/console-builtin.mjs.map +1 -1
  38. package/dist/components/help.cjs +6 -9
  39. package/dist/components/help.cjs.map +1 -1
  40. package/dist/components/help.d.cts +7 -7
  41. package/dist/components/help.d.cts.map +1 -1
  42. package/dist/components/help.d.mts +7 -7
  43. package/dist/components/help.d.mts.map +1 -1
  44. package/dist/components/help.mjs +6 -9
  45. package/dist/components/help.mjs.map +1 -1
  46. package/dist/components/helpers.d.cts +5 -5
  47. package/dist/components/helpers.d.mts +5 -5
  48. package/dist/components/index.cjs +1 -0
  49. package/dist/components/index.d.cts +2 -2
  50. package/dist/components/index.d.mts +2 -2
  51. package/dist/components/index.mjs +2 -2
  52. package/dist/components/utils-builtin.cjs +19 -36
  53. package/dist/components/utils-builtin.cjs.map +1 -1
  54. package/dist/components/utils-builtin.d.cts.map +1 -1
  55. package/dist/components/utils-builtin.d.mts +8 -8
  56. package/dist/components/utils-builtin.d.mts.map +1 -1
  57. package/dist/components/utils-builtin.mjs +19 -36
  58. package/dist/components/utils-builtin.mjs.map +1 -1
  59. package/dist/components/virtual-command-entry.cjs +8 -3
  60. package/dist/components/virtual-command-entry.cjs.map +1 -1
  61. package/dist/components/virtual-command-entry.d.cts +1 -0
  62. package/dist/components/virtual-command-entry.d.cts.map +1 -1
  63. package/dist/components/virtual-command-entry.d.mts +1 -0
  64. package/dist/components/virtual-command-entry.d.mts.map +1 -1
  65. package/dist/components/virtual-command-entry.mjs +8 -3
  66. package/dist/components/virtual-command-entry.mjs.map +1 -1
  67. package/dist/helpers/ansi-utils.cjs +117 -3
  68. package/dist/helpers/ansi-utils.cjs.map +1 -1
  69. package/dist/helpers/ansi-utils.d.cts.map +1 -1
  70. package/dist/helpers/ansi-utils.d.mts.map +1 -1
  71. package/dist/helpers/ansi-utils.mjs +117 -3
  72. package/dist/helpers/ansi-utils.mjs.map +1 -1
  73. package/dist/index.cjs +1 -2
  74. package/dist/index.cjs.map +1 -1
  75. package/dist/index.d.cts.map +1 -1
  76. package/dist/index.d.mts.map +1 -1
  77. package/dist/index.mjs +1 -2
  78. package/dist/index.mjs.map +1 -1
  79. package/dist/types/plugin.d.cts.map +1 -1
  80. package/package.json +12 -12
@@ -2,7 +2,8 @@ import { useColors, useTheme } from "../contexts/theme.mjs";
2
2
  import { IsNotDebug, IsNotVerbose } from "./helpers.mjs";
3
3
  import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
4
4
  import { For, Show, code } from "@alloy-js/core";
5
- import { ElseClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, InterfaceMember, TypeDeclaration, VarDeclaration } from "@alloy-js/typescript";
5
+ import { ElseClause, ElseIfClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, InterfaceMember, TypeDeclaration, VarDeclaration } from "@alloy-js/typescript";
6
+ import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
6
7
  import { TSDoc, TSDocDefaultValue, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
7
8
  import { defu as defu$1 } from "defu";
8
9
  import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
@@ -10,6 +11,126 @@ import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/buil
10
11
  import { getIndefiniteArticle } from "@stryke/string-format/vowels";
11
12
 
12
13
  //#region src/components/console-builtin.tsx
14
+ function AnsiHelpersDeclarations() {
15
+ return [
16
+ createComponent(VarDeclaration, {
17
+ "const": true,
18
+ "export": true,
19
+ name: "beep",
20
+ doc: "The ASCII Bell character, which can be used to trigger a beep sound in the console.",
21
+ children: code` "\\u0007"; `
22
+ }),
23
+ createComponent(Spacing, {}),
24
+ createComponent(VarDeclaration, {
25
+ "const": true,
26
+ "export": true,
27
+ name: "cursor",
28
+ doc: "An object containing ANSI escape codes for controlling the console cursor.",
29
+ children: code` {
30
+ to(x, y) {
31
+ if (!y) {
32
+ return \`\\x1B[\${x + 1}G\`;
33
+ }
34
+
35
+ return \`\\x1B[\${y + 1};\${x + 1}H\`;
36
+ },
37
+ move(x, y) {
38
+ let ret = '';
39
+
40
+ if (x < 0) {
41
+ ret += \`\\x1B[\${-x}D\`;
42
+ } else if (x > 0) {
43
+ ret += \`\\x1B[\${x}C\`;
44
+ }
45
+
46
+ if (y < 0) {
47
+ ret += \`\\x1B[\${-y}A\`;
48
+ } else if (y > 0) {
49
+ ret += \`\\x1B[\${y}B\`;
50
+ }
51
+
52
+ return ret;
53
+ },
54
+ up: (count = 1) => \`\\x1B[\${count}A\`,
55
+ down: (count = 1) => \`\\x1B[\${count}B\`,
56
+ forward: (count = 1) => \`\\x1B[\${count}C\`,
57
+ backward: (count = 1) => \`\\x1B[\${count}D\`,
58
+ nextLine: (count = 1) => "\\x1B[E".repeat(count),
59
+ prevLine: (count = 1) => "\\x1B[F".repeat(count),
60
+ left: "\\x1B[G",
61
+ hide: "\\x1B[?25l",
62
+ show: "\\x1B[?25h",
63
+ save: "\\x1B7",
64
+ restore: "\\x1B8"
65
+ } `
66
+ }),
67
+ createComponent(Spacing, {}),
68
+ createComponent(VarDeclaration, {
69
+ "const": true,
70
+ "export": true,
71
+ name: "erase",
72
+ doc: "An object containing ANSI escape codes for erasing parts of the console.",
73
+ children: code` {
74
+ screen: "\\x1B[2J",
75
+ up: (count = 1) => "\\x1B[1J".repeat(count),
76
+ down: (count = 1) => "\\x1B[J".repeat(count),
77
+ line: "\\x1B[2K",
78
+ lineEnd: "\\x1B[K",
79
+ lineStart: "\\x1B[1K",
80
+ lines(count) {
81
+ let lineClear = "";
82
+ for (let i = 0; i < count; i++) {
83
+ lineClear += this.line + (i < count - 1 ? cursor.up() : "");
84
+ }
85
+
86
+ if (count) {
87
+ lineClear += cursor.left;
88
+ }
89
+
90
+ return lineClear;
91
+ }
92
+ } `
93
+ }),
94
+ createComponent(Spacing, {}),
95
+ createComponent(VarDeclaration, {
96
+ "const": true,
97
+ "export": true,
98
+ name: "scroll",
99
+ doc: "An object containing ANSI escape codes for scrolling the console.",
100
+ children: code` {
101
+ up: (count = 1) => "\\x1B[S".repeat(count),
102
+ down: (count = 1) => "\\x1B[T".repeat(count)
103
+ } `
104
+ }),
105
+ createComponent(Spacing, {}),
106
+ createComponent(FunctionDeclaration, {
107
+ "export": true,
108
+ name: "clear",
109
+ doc: "A helper function to clear the console based on a count of lines",
110
+ parameters: [{
111
+ name: "current",
112
+ type: "string",
113
+ doc: "The current console output to be cleared"
114
+ }, {
115
+ name: "consoleWidth",
116
+ type: "number",
117
+ doc: "The number of characters per line in the console"
118
+ }],
119
+ children: code`if (!consoleWidth) {
120
+ return erase.line + cursor.to(0);
121
+ }
122
+
123
+ let rows = 0;
124
+ const lines = current.split(/\\r?\\n/);
125
+ for (let line of lines) {
126
+ rows += 1 + Math.floor(Math.max([...stripAnsi(line)].length - 1, 0) / consoleWidth);
127
+ }
128
+
129
+ return erase.lines(rows); `
130
+ }),
131
+ createComponent(Spacing, {})
132
+ ];
133
+ }
13
134
  /**
14
135
  * A component to generate a console message function in a Shell Shock project.
15
136
  */
@@ -52,8 +173,7 @@ function ColorsDeclaration() {
52
173
  });
53
174
  }
54
175
  }),
55
- createIntrinsic("hbr", {}),
56
- createIntrinsic("hbr", {}),
176
+ createComponent(Spacing, {}),
57
177
  createIntrinsic("hbr", {}),
58
178
  code`
59
179
  /**
@@ -63,16 +183,14 @@ function ColorsDeclaration() {
63
183
  * This type allows for nested theme color definitions, enabling complex theming structures for console applications.
64
184
  */
65
185
  export type ThemeColors<T> = T extends object ? { [K in keyof T]: ThemeColors<T[K]>; } : ((text: string) => string); `,
66
- createIntrinsic("hbr", {}),
67
- createIntrinsic("hbr", {}),
186
+ createComponent(Spacing, {}),
68
187
  createComponent(TypeDeclaration, {
69
188
  "export": true,
70
189
  name: "Colors",
71
190
  doc: "An object containing functions for coloring console applications. Each function corresponds to a terminal color. See {@link AnsiColor} for available colors.",
72
191
  children: code`Record<AnsiColor, (text: string) => string> & ThemeColors<ThemeColorsResolvedConfig>`
73
192
  }),
74
- createIntrinsic("hbr", {}),
75
- createIntrinsic("hbr", {}),
193
+ createComponent(Spacing, {}),
76
194
  createComponent(TSDoc, { heading: "An object containing functions for coloring console applications. Each function corresponds to a terminal color. See {@link Colors} for available colors." }),
77
195
  createComponent(VarDeclaration, {
78
196
  "const": true,
@@ -783,6 +901,302 @@ function ColorsDeclaration() {
783
901
  return colors.ansi16m.theme.text.usage.description;
784
902
  }
785
903
  })}
904
+ },
905
+ prompt: {
906
+ icon: {
907
+ active: ${createComponent(ColorFunction, {
908
+ get ansi16() {
909
+ return colors.ansi16.theme.text.prompt.icon.active;
910
+ },
911
+ get ansi256() {
912
+ return colors.ansi256.theme.text.prompt.icon.active;
913
+ },
914
+ get ansi16m() {
915
+ return colors.ansi16m.theme.text.prompt.icon.active;
916
+ }
917
+ })},
918
+ warning: ${createComponent(ColorFunction, {
919
+ get ansi16() {
920
+ return colors.ansi16.theme.text.prompt.icon.warning;
921
+ },
922
+ get ansi256() {
923
+ return colors.ansi256.theme.text.prompt.icon.warning;
924
+ },
925
+ get ansi16m() {
926
+ return colors.ansi16m.theme.text.prompt.icon.warning;
927
+ }
928
+ })},
929
+ error: ${createComponent(ColorFunction, {
930
+ get ansi16() {
931
+ return colors.ansi16.theme.text.prompt.icon.error;
932
+ },
933
+ get ansi256() {
934
+ return colors.ansi256.theme.text.prompt.icon.error;
935
+ },
936
+ get ansi16m() {
937
+ return colors.ansi16m.theme.text.prompt.icon.error;
938
+ }
939
+ })},
940
+ submitted: ${createComponent(ColorFunction, {
941
+ get ansi16() {
942
+ return colors.ansi16.theme.text.prompt.icon.submitted;
943
+ },
944
+ get ansi256() {
945
+ return colors.ansi256.theme.text.prompt.icon.submitted;
946
+ },
947
+ get ansi16m() {
948
+ return colors.ansi16m.theme.text.prompt.icon.submitted;
949
+ }
950
+ })},
951
+ cancelled: ${createComponent(ColorFunction, {
952
+ get ansi16() {
953
+ return colors.ansi16.theme.text.prompt.icon.cancelled;
954
+ },
955
+ get ansi256() {
956
+ return colors.ansi256.theme.text.prompt.icon.cancelled;
957
+ },
958
+ get ansi16m() {
959
+ return colors.ansi16m.theme.text.prompt.icon.cancelled;
960
+ }
961
+ })},
962
+ disabled: ${createComponent(ColorFunction, {
963
+ get ansi16() {
964
+ return colors.ansi16.theme.text.prompt.icon.disabled;
965
+ },
966
+ get ansi256() {
967
+ return colors.ansi256.theme.text.prompt.icon.disabled;
968
+ },
969
+ get ansi16m() {
970
+ return colors.ansi16m.theme.text.prompt.icon.disabled;
971
+ }
972
+ })}
973
+ },
974
+ message: {
975
+ active: ${createComponent(ColorFunction, {
976
+ get ansi16() {
977
+ return colors.ansi16.theme.text.prompt.message.active;
978
+ },
979
+ get ansi256() {
980
+ return colors.ansi256.theme.text.prompt.message.active;
981
+ },
982
+ get ansi16m() {
983
+ return colors.ansi16m.theme.text.prompt.message.active;
984
+ }
985
+ })},
986
+ warning: ${createComponent(ColorFunction, {
987
+ get ansi16() {
988
+ return colors.ansi16.theme.text.prompt.message.warning;
989
+ },
990
+ get ansi256() {
991
+ return colors.ansi256.theme.text.prompt.message.warning;
992
+ },
993
+ get ansi16m() {
994
+ return colors.ansi16m.theme.text.prompt.message.warning;
995
+ }
996
+ })},
997
+ error: ${createComponent(ColorFunction, {
998
+ get ansi16() {
999
+ return colors.ansi16.theme.text.prompt.message.error;
1000
+ },
1001
+ get ansi256() {
1002
+ return colors.ansi256.theme.text.prompt.message.error;
1003
+ },
1004
+ get ansi16m() {
1005
+ return colors.ansi16m.theme.text.prompt.message.error;
1006
+ }
1007
+ })},
1008
+ submitted: ${createComponent(ColorFunction, {
1009
+ get ansi16() {
1010
+ return colors.ansi16.theme.text.prompt.message.submitted;
1011
+ },
1012
+ get ansi256() {
1013
+ return colors.ansi256.theme.text.prompt.message.submitted;
1014
+ },
1015
+ get ansi16m() {
1016
+ return colors.ansi16m.theme.text.prompt.message.submitted;
1017
+ }
1018
+ })},
1019
+ cancelled: ${createComponent(ColorFunction, {
1020
+ get ansi16() {
1021
+ return colors.ansi16.theme.text.prompt.message.cancelled;
1022
+ },
1023
+ get ansi256() {
1024
+ return colors.ansi256.theme.text.prompt.message.cancelled;
1025
+ },
1026
+ get ansi16m() {
1027
+ return colors.ansi16m.theme.text.prompt.message.cancelled;
1028
+ }
1029
+ })},
1030
+ disabled: ${createComponent(ColorFunction, {
1031
+ get ansi16() {
1032
+ return colors.ansi16.theme.text.prompt.message.disabled;
1033
+ },
1034
+ get ansi256() {
1035
+ return colors.ansi256.theme.text.prompt.message.disabled;
1036
+ },
1037
+ get ansi16m() {
1038
+ return colors.ansi16m.theme.text.prompt.message.disabled;
1039
+ }
1040
+ })}
1041
+ },
1042
+ input: {
1043
+ active: ${createComponent(ColorFunction, {
1044
+ get ansi16() {
1045
+ return colors.ansi16.theme.text.prompt.input.active;
1046
+ },
1047
+ get ansi256() {
1048
+ return colors.ansi256.theme.text.prompt.input.active;
1049
+ },
1050
+ get ansi16m() {
1051
+ return colors.ansi16m.theme.text.prompt.input.active;
1052
+ }
1053
+ })},
1054
+ inactive: ${createComponent(ColorFunction, {
1055
+ get ansi16() {
1056
+ return colors.ansi16.theme.text.prompt.input.inactive;
1057
+ },
1058
+ get ansi256() {
1059
+ return colors.ansi256.theme.text.prompt.input.inactive;
1060
+ },
1061
+ get ansi16m() {
1062
+ return colors.ansi16m.theme.text.prompt.input.inactive;
1063
+ }
1064
+ })},
1065
+ warning: ${createComponent(ColorFunction, {
1066
+ get ansi16() {
1067
+ return colors.ansi16.theme.text.prompt.input.warning;
1068
+ },
1069
+ get ansi256() {
1070
+ return colors.ansi256.theme.text.prompt.input.warning;
1071
+ },
1072
+ get ansi16m() {
1073
+ return colors.ansi16m.theme.text.prompt.input.warning;
1074
+ }
1075
+ })},
1076
+ error: ${createComponent(ColorFunction, {
1077
+ get ansi16() {
1078
+ return colors.ansi16.theme.text.prompt.input.error;
1079
+ },
1080
+ get ansi256() {
1081
+ return colors.ansi256.theme.text.prompt.input.error;
1082
+ },
1083
+ get ansi16m() {
1084
+ return colors.ansi16m.theme.text.prompt.input.error;
1085
+ }
1086
+ })},
1087
+ submitted: ${createComponent(ColorFunction, {
1088
+ get ansi16() {
1089
+ return colors.ansi16.theme.text.prompt.input.submitted;
1090
+ },
1091
+ get ansi256() {
1092
+ return colors.ansi256.theme.text.prompt.input.submitted;
1093
+ },
1094
+ get ansi16m() {
1095
+ return colors.ansi16m.theme.text.prompt.input.submitted;
1096
+ }
1097
+ })},
1098
+ cancelled: ${createComponent(ColorFunction, {
1099
+ get ansi16() {
1100
+ return colors.ansi16.theme.text.prompt.input.cancelled;
1101
+ },
1102
+ get ansi256() {
1103
+ return colors.ansi256.theme.text.prompt.input.cancelled;
1104
+ },
1105
+ get ansi16m() {
1106
+ return colors.ansi16m.theme.text.prompt.input.cancelled;
1107
+ }
1108
+ })},
1109
+ disabled: ${createComponent(ColorFunction, {
1110
+ get ansi16() {
1111
+ return colors.ansi16.theme.text.prompt.input.disabled;
1112
+ },
1113
+ get ansi256() {
1114
+ return colors.ansi256.theme.text.prompt.input.disabled;
1115
+ },
1116
+ get ansi16m() {
1117
+ return colors.ansi16m.theme.text.prompt.input.disabled;
1118
+ }
1119
+ })}
1120
+ },
1121
+ description: {
1122
+ active: ${createComponent(ColorFunction, {
1123
+ get ansi16() {
1124
+ return colors.ansi16.theme.text.prompt.description.active;
1125
+ },
1126
+ get ansi256() {
1127
+ return colors.ansi256.theme.text.prompt.description.active;
1128
+ },
1129
+ get ansi16m() {
1130
+ return colors.ansi16m.theme.text.prompt.description.active;
1131
+ }
1132
+ })},
1133
+ inactive: ${createComponent(ColorFunction, {
1134
+ get ansi16() {
1135
+ return colors.ansi16.theme.text.prompt.description.inactive;
1136
+ },
1137
+ get ansi256() {
1138
+ return colors.ansi256.theme.text.prompt.description.inactive;
1139
+ },
1140
+ get ansi16m() {
1141
+ return colors.ansi16m.theme.text.prompt.description.inactive;
1142
+ }
1143
+ })},
1144
+ warning: ${createComponent(ColorFunction, {
1145
+ get ansi16() {
1146
+ return colors.ansi16.theme.text.prompt.description.warning;
1147
+ },
1148
+ get ansi256() {
1149
+ return colors.ansi256.theme.text.prompt.description.warning;
1150
+ },
1151
+ get ansi16m() {
1152
+ return colors.ansi16m.theme.text.prompt.description.warning;
1153
+ }
1154
+ })},
1155
+ error: ${createComponent(ColorFunction, {
1156
+ get ansi16() {
1157
+ return colors.ansi16.theme.text.prompt.description.error;
1158
+ },
1159
+ get ansi256() {
1160
+ return colors.ansi256.theme.text.prompt.description.error;
1161
+ },
1162
+ get ansi16m() {
1163
+ return colors.ansi16m.theme.text.prompt.description.error;
1164
+ }
1165
+ })},
1166
+ submitted: ${createComponent(ColorFunction, {
1167
+ get ansi16() {
1168
+ return colors.ansi16.theme.text.prompt.description.submitted;
1169
+ },
1170
+ get ansi256() {
1171
+ return colors.ansi256.theme.text.prompt.description.submitted;
1172
+ },
1173
+ get ansi16m() {
1174
+ return colors.ansi16m.theme.text.prompt.description.submitted;
1175
+ }
1176
+ })},
1177
+ cancelled: ${createComponent(ColorFunction, {
1178
+ get ansi16() {
1179
+ return colors.ansi16.theme.text.prompt.description.cancelled;
1180
+ },
1181
+ get ansi256() {
1182
+ return colors.ansi256.theme.text.prompt.description.cancelled;
1183
+ },
1184
+ get ansi16m() {
1185
+ return colors.ansi16m.theme.text.prompt.description.cancelled;
1186
+ }
1187
+ })},
1188
+ disabled: ${createComponent(ColorFunction, {
1189
+ get ansi16() {
1190
+ return colors.ansi16.theme.text.prompt.description.disabled;
1191
+ },
1192
+ get ansi256() {
1193
+ return colors.ansi256.theme.text.prompt.description.disabled;
1194
+ },
1195
+ get ansi16m() {
1196
+ return colors.ansi16m.theme.text.prompt.description.disabled;
1197
+ }
1198
+ })}
1199
+ }
786
1200
  }
787
1201
  },
788
1202
  border: {
@@ -1104,6 +1518,102 @@ function ColorsDeclaration() {
1104
1518
  function WriteLineFunctionDeclaration() {
1105
1519
  const theme = useTheme();
1106
1520
  return [
1521
+ createComponent(FunctionDeclaration, {
1522
+ name: "adjustIndex",
1523
+ parameters: [{
1524
+ name: "line",
1525
+ type: "string"
1526
+ }, {
1527
+ name: "index",
1528
+ type: "number"
1529
+ }],
1530
+ returnType: "number",
1531
+ children: code`let adjustedIndex = 0;
1532
+
1533
+ const segments = line.match(/\\x1b\\[(\\d|;)+m.*\\x1b\\[(\\d|;)+m/gi);
1534
+ if (segments && segments.length > 0) {
1535
+ segments.reduce((count, matched) => {
1536
+ if (count < index) {
1537
+ const stripped = stripAnsi(matched);
1538
+ if (count + stripped.length < index) {
1539
+ count += stripped.length;
1540
+ adjustedIndex += matched.length;
1541
+ } else {
1542
+ adjustedIndex += index - count + (matched.slice(0, index - count).match(/\\x1b\\[(\\d|;)+m/g)?.join("")?.length ?? 0);
1543
+ count = index;
1544
+ }
1545
+ }
1546
+
1547
+ return count;
1548
+ }, 0);
1549
+ } else {
1550
+ adjustedIndex = index;
1551
+ }
1552
+
1553
+ return adjustedIndex - (line.slice(0, adjustedIndex).match(/\\x1b\\[/g)?.length ?? 0); `
1554
+ }),
1555
+ createComponent(Spacing, {}),
1556
+ createComponent(FunctionDeclaration, {
1557
+ name: "breakLine",
1558
+ parameters: [{
1559
+ name: "line",
1560
+ type: "string"
1561
+ }, {
1562
+ name: "index",
1563
+ type: "number"
1564
+ }],
1565
+ returnType: "[string, string]",
1566
+ children: code`const first = line.slice(0, index);
1567
+ const second = line.slice(index);
1568
+
1569
+ // Match all ANSI escape sequences in the first string
1570
+ const ansiRegex = /[\\x1b\\u009b][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))/g;
1571
+
1572
+ const openCodes: string[] = [];
1573
+ const closeCodes: string[] = [];
1574
+ let match: RegExpExecArray | null;
1575
+
1576
+ while ((match = ansiRegex.exec(first)) !== null) {
1577
+ const code = match[0];
1578
+ // Check if this is a reset/close code (e.g., \\x1b[0m, \\x1b[39m, \\x1b[49m, etc.)
1579
+ if (/\\x1b\\[(?:0|22|23|24|27|28|29|39|49)m/.test(code)) {
1580
+ // A close/reset code cancels the last open code
1581
+ openCodes.pop();
1582
+ closeCodes.pop();
1583
+ } else {
1584
+ openCodes.push(code);
1585
+ // Derive a close code: map SGR open codes to their reset counterparts
1586
+ const sgrMatch = code.match(/\\x1b\\[(\\d+)m/);
1587
+ if (sgrMatch) {
1588
+ const n = parseInt(sgrMatch[1]!, 10);
1589
+ let closeCode: string;
1590
+ if (n >= 30 && n <= 37) closeCode = "\\x1b[39m";
1591
+ else if (n >= 40 && n <= 47) closeCode = "\\x1b[49m";
1592
+ else if (n >= 90 && n <= 97) closeCode = "\\x1b[39m";
1593
+ else if (n >= 100 && n <= 107) closeCode = "\\x1b[49m";
1594
+ else if (n === 1) closeCode = "\\x1b[22m";
1595
+ else if (n === 2) closeCode = "\\x1b[22m";
1596
+ else if (n === 3) closeCode = "\\x1b[23m";
1597
+ else if (n === 4) closeCode = "\\x1b[24m";
1598
+ else if (n === 7) closeCode = "\\x1b[27m";
1599
+ else if (n === 8) closeCode = "\\x1b[28m";
1600
+ else if (n === 9) closeCode = "\\x1b[29m";
1601
+ else closeCode = "\\x1b[0m";
1602
+ closeCodes.push(closeCode);
1603
+ } else {
1604
+ closeCodes.push("\\x1b[0m");
1605
+ }
1606
+ }
1607
+ }
1608
+
1609
+ // Append close codes to the end of "first" (in reverse order)
1610
+ const closeSequence = closeCodes.slice().reverse().join("");
1611
+ // Prepend open codes to the start of "second"
1612
+ const openSequence = openCodes.join("");
1613
+
1614
+ return [first.replace(/^\\s+/, "").replace(/\\s+$/, "") + closeSequence, openSequence + second.replace(/^\\s+/, "").replace(/\\s+$/, "")]; `
1615
+ }),
1616
+ createComponent(Spacing, {}),
1107
1617
  createComponent(TSDoc, {
1108
1618
  heading: "Split text into multiple lines based on a maximum length.",
1109
1619
  get children() {
@@ -1129,23 +1639,24 @@ function WriteLineFunctionDeclaration() {
1129
1639
  type: "string"
1130
1640
  }, {
1131
1641
  name: "maxLength",
1132
- type: "number"
1642
+ type: "number | SizeToken"
1133
1643
  }],
1134
1644
  children: code`
1135
1645
  let line = text;
1136
1646
  let result = [] as string[];
1137
1647
 
1138
- while (stripAnsi(line).length > maxLength || line.indexOf("\\n") !== -1) {
1648
+ const calculatedMaxLength = isSizeToken(maxLength) ? calculateWidth(maxLength) : maxLength;
1649
+ while (stripAnsi(line).length > calculatedMaxLength || line.indexOf("\\n") !== -1) {
1139
1650
  if (line.indexOf("\\n") !== -1) {
1140
- result.push(...splitText(line.slice(0, line.indexOf("\\n")).replace(/\\n/, ""), maxLength));
1651
+ result.push(...splitText(line.slice(0, line.indexOf("\\n")).replace(/(\\r)?\\n/, ""), calculatedMaxLength));
1141
1652
  line = line.indexOf("\\n") + 1 < line.length
1142
1653
  ? line.slice(line.indexOf("\\n") + 1)
1143
1654
  : "";
1144
1655
  } else {
1145
- const index = [" ", "/", "\\\\", ".", ",", "-", ":", "|", "@", "+"].reduce((ret, split) => {
1656
+ const index = [" ", "/", ".", ",", "-", ":", "|", "@", "+"].reduce((ret, split) => {
1146
1657
  let current = ret;
1147
- while (stripAnsi(line).indexOf(split, current + 1) !== -1 && stripAnsi(line).indexOf(split, current + 1) <= maxLength && (!/.*\\([^)]*$/.test(stripAnsi(line).slice(0, line.indexOf(split, current + 1))) || !/^[^(]*\\).*/.test(stripAnsi(line).slice(line.indexOf(split, current + 1) + 1)) || stripAnsi(line).slice(line.indexOf(split, current + 1) + 1).replace(/^.*\\)/, "").indexOf(split) !== -1)) {
1148
- current = line.indexOf(split, current + 1);
1658
+ while (stripAnsi(line).indexOf(split, current + 1) !== -1 && stripAnsi(line).indexOf(split, current + 1) <= calculatedMaxLength) {
1659
+ current = line.indexOf(split, adjustIndex(line, current + 1));
1149
1660
  }
1150
1661
 
1151
1662
  return current;
@@ -1154,22 +1665,23 @@ function WriteLineFunctionDeclaration() {
1154
1665
  break;
1155
1666
  }
1156
1667
 
1157
- result.push(line.slice(0, index));
1158
- line = line.slice(index + 1);
1668
+ const lines = breakLine(line, index);
1669
+ result.push(lines[0]);
1670
+ line = lines[1];
1159
1671
  }
1160
1672
  }
1161
1673
 
1162
- while (stripAnsi(line).length > maxLength) {
1163
- result.push(line.slice(0, maxLength));
1164
- line = line.slice(maxLength + 1);
1674
+ while (stripAnsi(line).length > calculatedMaxLength) {
1675
+ const lines = breakLine(line, calculatedMaxLength);
1676
+ result.push(lines[0]);
1677
+ line = lines[1];
1165
1678
  }
1166
1679
 
1167
1680
  result.push(line);
1168
1681
  return result;
1169
1682
  `
1170
1683
  }),
1171
- createIntrinsic("hbr", {}),
1172
- createIntrinsic("hbr", {}),
1684
+ createComponent(Spacing, {}),
1173
1685
  createComponent(InterfaceDeclaration, {
1174
1686
  "export": true,
1175
1687
  name: "WriteLineOptions",
@@ -1223,8 +1735,7 @@ function WriteLineFunctionDeclaration() {
1223
1735
  ];
1224
1736
  }
1225
1737
  }),
1226
- createIntrinsic("hbr", {}),
1227
- createIntrinsic("hbr", {}),
1738
+ createComponent(Spacing, {}),
1228
1739
  createComponent(TSDoc, {
1229
1740
  heading: "Write a line to the console.",
1230
1741
  get children() {
@@ -1314,6 +1825,8 @@ function MessageFunctionDeclaration(props) {
1314
1825
  }
1315
1826
 
1316
1827
  ${!theme.labels.message.footer[variant] && timestamp ? `const timestamp = \`\${colors.text.message.footer.${color}(new Date().toLocaleDateString())} \${colors.border.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottom}")} \${colors.text.message.footer.${color}(new Date().toLocaleTimeString())}\`; ` : ""}
1828
+
1829
+ writeLine("");
1317
1830
  writeLine(colors.border.message.outline.${color}("${theme.borderStyles.message.outline[variant].topLeft}") + ${theme.labels.message.header[variant] || theme.icons.message.header[variant] ? `colors.border.message.outline.${color}("${theme.borderStyles.message.outline[variant].top}".repeat(4)) + " " + ${theme.icons.message.header[variant] ? `colors.border.message.outline.${color}("${theme.icons.message.header[variant]}") + " " +` : ""} colors.bold(colors.text.message.header.${color}("${theme.labels.message.header[variant]}")) + " " + colors.border.message.outline.${color}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].topLeft.length + 4 + (theme.icons.message.header[variant] ? 2 + (theme.labels.message.header[variant] ? 0 : 1) : 0) + (theme.labels.message.header[variant] ? theme.labels.message.header[variant].length + 2 : 0) + theme.borderStyles.message.outline[variant].topRight.length}, 0)))` : `colors.border.message.outline.${color}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].topLeft.length + theme.borderStyles.message.outline[variant].topRight.length}, 0)))`} + colors.border.message.outline.${color}("${theme.borderStyles.message.outline[variant].topRight}"), { consoleFn: console.${consoleFnName} });
1318
1831
  splitText(
1319
1832
  message,
@@ -1334,8 +1847,8 @@ function WrapAnsiFunction() {
1334
1847
  heading: "Applies ANSI escape codes to a string.",
1335
1848
  get children() {
1336
1849
  return [
1337
- createComponent(TSDocRemarks, { children: `Split text by /\\\\u001b[\\[|\\]][0-9;]*m/ and wrap non-ANSI parts with open/closeing tags.` }),
1338
- createComponent(TSDocExample, { children: `const result = wrapAnsi("Hello\\\\u001b[31mWorld\\\\u001b[0mAgain", "\\\\u001b[36m", "\\\\u001b[39");\nconsole.log(result); // "\\\\u001b[36mHello\\\\u001b[39\\\\u001b[31mWorld\\\\u001b[0m\\\\u001b[36mAgain\\\\u001b[39"` }),
1850
+ createComponent(TSDocRemarks, { children: `Split text by /\\\\x1b[\\[|\\]][0-9;]*m/ and wrap non-ANSI parts with open/closeing tags.` }),
1851
+ createComponent(TSDocExample, { children: `const result = wrapAnsi("Hello\\\\x1b[31mWorld\\\\x1b[0mAgain", "\\\\x1b[36m", "\\\\x1b[39");\nconsole.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\\x1b[36mAgain\\\\x1b[39"` }),
1339
1852
  createComponent(TSDocParam, {
1340
1853
  name: "text",
1341
1854
  children: `The text to apply ANSI codes to.`
@@ -1375,7 +1888,7 @@ function WrapAnsiFunction() {
1375
1888
 
1376
1889
  let last = 0;
1377
1890
  let match: RegExpExecArray | null;
1378
- while ((match = /\\\\u001b[\\[|\\]][0-9;]*m/g.exec(str)) !== null) {
1891
+ while ((match = /\\\\x1b[\\[|\\]][0-9;]*m/g.exec(str)) !== null) {
1379
1892
  if (match.index > last) tokens.push(str.slice(last, match.index));
1380
1893
  tokens.push(match[0]);
1381
1894
  last = match.index + match[0].length;
@@ -1388,7 +1901,7 @@ function WrapAnsiFunction() {
1388
1901
  let result = "";
1389
1902
  for (let i = 0; i < tokens.length; i++) {
1390
1903
  const seg = tokens[i]!;
1391
- if (/^\\\\u001b[\\[|\\]][0-9;]*m$/.test(seg)) {
1904
+ if (/^\\\\x1b[\\[|\\]][0-9;]*m$/.test(seg)) {
1392
1905
  result += seg;
1393
1906
  continue;
1394
1907
  }
@@ -1397,7 +1910,7 @@ function WrapAnsiFunction() {
1397
1910
  continue;
1398
1911
  }
1399
1912
 
1400
- result += i > 0 && /^\\\\u001b[\\[|\\]][0-9;]*m$/.test(tokens[i - 1]!) && i + 1 < tokens.length && /^\\\\u001b[\\[|\\]][0-9;]*m$/.test(tokens[i + 1]!)
1913
+ result += i > 0 && /^\\\\x1b[\\[|\\]][0-9;]*m$/.test(tokens[i - 1]!) && i + 1 < tokens.length && /^\\\\x1b[\\[|\\]][0-9;]*m$/.test(tokens[i + 1]!)
1401
1914
  ? seg
1402
1915
  : \`\${open}\${seg}\${close}\`;
1403
1916
  }
@@ -1414,7 +1927,7 @@ function StripAnsiFunctionDeclaration() {
1414
1927
  heading: "Removes ANSI escape codes from a string.",
1415
1928
  get children() {
1416
1929
  return [
1417
- createComponent(TSDocExample, { children: `const result = stripAnsi("Hello\\\\u001b[31mWorld\\\\u001b[0mAgain"); // "HelloWorldAgain"` }),
1930
+ createComponent(TSDocExample, { children: `const result = stripAnsi("Hello\\\\x1b[31mWorld\\\\x1b[0mAgain"); // "HelloWorldAgain"` }),
1418
1931
  createComponent(TSDocParam, {
1419
1932
  name: "text",
1420
1933
  children: `The text to strip ANSI codes from.`
@@ -1494,8 +2007,7 @@ function DividerFunctionDeclaration() {
1494
2007
  ];
1495
2008
  }
1496
2009
  }),
1497
- createIntrinsic("hbr", {}),
1498
- createIntrinsic("hbr", {}),
2010
+ createComponent(Spacing, {}),
1499
2011
  createComponent(TSDoc, {
1500
2012
  heading: "Write a divider line to the console.",
1501
2013
  get children() {
@@ -1559,7 +2071,7 @@ function LinkFunctionDeclaration() {
1559
2071
  return [
1560
2072
  createComponent(IfStatement, {
1561
2073
  condition: code`isHyperlinkSupported()`,
1562
- children: code`return \`\\u001b]8;;\${url}\\u0007\${text ?? url}\\u001b]8;;\\u0007\`;`
2074
+ children: code`return \`\\x1b]8;;\${url}\\u0007\${text ?? url}\\x1b]8;;\\u0007\`;`
1563
2075
  }),
1564
2076
  createIntrinsic("hbr", {}),
1565
2077
  createComponent(IfStatement, {
@@ -1587,14 +2099,119 @@ function extractBorderOptionsString(direction, theme) {
1587
2099
  function TableFunctionDeclaration(props) {
1588
2100
  const theme = useTheme();
1589
2101
  return [
2102
+ createComponent(TypeDeclaration, {
2103
+ "export": true,
2104
+ name: "SizeToken",
2105
+ doc: "A type representing the width size of an item in the console.",
2106
+ children: code`"full" | "1/1" | "1/2" | "1/3" | "1/4" | "1/5" | "1/6" | "1/12" | "1/24" | "100%" | "50%" | "33.33%" | "25%" | "20%" | "10%" | "5%" | "2.5%"`
2107
+ }),
2108
+ createComponent(Spacing, {}),
2109
+ createComponent(TSDoc, {
2110
+ heading: "Determine if a value is a valid size token.",
2111
+ get children() {
2112
+ return [
2113
+ createComponent(TSDocRemarks, { children: `This function checks if the provided value is a valid size token, which can be one of the predefined strings representing common width sizes (e.g., "full", "1/2", "1/3", etc.) or percentage strings (e.g., "50%").` }),
2114
+ createComponent(TSDocParam, {
2115
+ name: "value",
2116
+ children: `The value to check for being a valid size token.`
2117
+ }),
2118
+ createComponent(TSDocReturns, { children: `True if the value is a valid size token, false otherwise.` })
2119
+ ];
2120
+ }
2121
+ }),
2122
+ createComponent(FunctionDeclaration, {
2123
+ "export": true,
2124
+ doc: "Determines if the provided value is a valid size token.",
2125
+ name: "isSizeToken",
2126
+ parameters: [{
2127
+ name: "value",
2128
+ type: "any"
2129
+ }],
2130
+ returnType: "value is SizeToken",
2131
+ get children() {
2132
+ return [createComponent(IfStatement, {
2133
+ condition: code`["full", "1/1", "1/2", "1/3", "1/4", "1/5", "1/6", "1/12", "1/24", "100%", "50%", "33.33%", "25%", "20%", "10%", "5%", "2.5%"].includes(value)`,
2134
+ children: code`return true; `
2135
+ }), code`return false; `];
2136
+ }
2137
+ }),
2138
+ createComponent(Spacing, {}),
2139
+ createComponent(TSDoc, {
2140
+ heading: "Calculate the width in characters based on the provided width size.",
2141
+ get children() {
2142
+ return [
2143
+ createComponent(TSDocRemarks, { children: `This function calculates the width in characters based on the provided width size, which can be a predefined string (e.g., "full", "1/2", "1/3", etc.) or a percentage string (e.g., "50%"). The calculation is based on the current width of the console (process.stdout.columns).` }),
2144
+ createComponent(TSDocParam, {
2145
+ name: "size",
2146
+ children: `The width size to calculate. This can be a predefined string (e.g., "full", "1/2", "1/3", etc.) or a percentage string (e.g., "50%").`
2147
+ }),
2148
+ createComponent(TSDocReturns, { children: `The calculated width in characters.` })
2149
+ ];
2150
+ }
2151
+ }),
2152
+ createComponent(FunctionDeclaration, {
2153
+ "export": true,
2154
+ name: "calculateWidth",
2155
+ parameters: [{
2156
+ name: "size",
2157
+ type: "SizeToken",
2158
+ optional: false
2159
+ }],
2160
+ returnType: "number",
2161
+ get children() {
2162
+ return [
2163
+ createComponent(IfStatement, {
2164
+ condition: code`["full", "100%", "1/1"]. includes(size)`,
2165
+ children: code`return process.stdout.columns;`
2166
+ }),
2167
+ createComponent(ElseIfClause, {
2168
+ condition: code`["1/2", "50%"].includes(size)`,
2169
+ children: code`return Math.round(process.stdout.columns / 2);`
2170
+ }),
2171
+ createComponent(ElseIfClause, {
2172
+ condition: code`["1/3", "33.33%"].includes(size)`,
2173
+ children: code`return Math.round(process.stdout.columns / 3);`
2174
+ }),
2175
+ createComponent(ElseIfClause, {
2176
+ condition: code`["1/4", "25%"].includes(size)`,
2177
+ children: code`return Math.round(process.stdout.columns / 4);`
2178
+ }),
2179
+ createComponent(ElseIfClause, {
2180
+ condition: code`["1/5", "20%"].includes(size)`,
2181
+ children: code`return Math.round(process.stdout.columns / 5);`
2182
+ }),
2183
+ createComponent(ElseIfClause, {
2184
+ condition: code`["1/6", "10%"].includes(size)`,
2185
+ children: code`return Math.round(process.stdout.columns / 6);`
2186
+ }),
2187
+ createComponent(ElseIfClause, {
2188
+ condition: code`["1/12", "5%"].includes(size)`,
2189
+ children: code`return Math.round(process.stdout.columns / 12);`
2190
+ }),
2191
+ createComponent(ElseIfClause, {
2192
+ condition: code`["1/24", "2.5%"].includes(size)`,
2193
+ children: code`return Math.round(process.stdout.columns / 24);`
2194
+ }),
2195
+ createComponent(ElseClause, { children: code`
2196
+ const match = size.match(/(\\d+(\\.\\d+)?)%/);
2197
+ if (match) {
2198
+ return Math.round((process.stdout.columns * parseFloat(match[1])) / 100);
2199
+ }
2200
+
2201
+ throw new Error(\`Invalid width size: \${size}\`);
2202
+ ` }),
2203
+ createIntrinsic("hbr", {}),
2204
+ createIntrinsic("hbr", {})
2205
+ ];
2206
+ }
2207
+ }),
1590
2208
  createComponent(TypeDeclaration, {
1591
2209
  "export": true,
1592
2210
  name: "BorderOption",
1593
2211
  doc: "The border options applied to table cells.",
1594
2212
  children: code`"primary" | "secondary" | "tertiary" | "none" | string; `
1595
2213
  }),
1596
- createIntrinsic("hbr", {}),
1597
- createIntrinsic("hbr", {}),
2214
+ createComponent(Spacing, {}),
1598
2215
  createComponent(InterfaceDeclaration, {
1599
2216
  "export": true,
1600
2217
  name: "TableOutputOptions",
@@ -1669,24 +2286,36 @@ function TableFunctionDeclaration(props) {
1669
2286
  ];
1670
2287
  }
1671
2288
  }),
1672
- createIntrinsic("hbr", {}),
1673
- createIntrinsic("hbr", {}),
2289
+ createComponent(Spacing, {}),
1674
2290
  createComponent(InterfaceDeclaration, {
1675
2291
  "export": true,
1676
2292
  name: "TableCellOptions",
1677
2293
  "extends": "TableOutputOptions",
1678
2294
  doc: "Options for a specific table cell provided to the {@link table} function.",
1679
2295
  get children() {
1680
- return [createComponent(InterfaceMember, {
1681
- name: "value",
1682
- optional: true,
1683
- type: "string",
1684
- doc: "The actual string value of the table cell."
1685
- }), createIntrinsic("hbr", {})];
2296
+ return [
2297
+ createComponent(InterfaceMember, {
2298
+ name: "value",
2299
+ optional: true,
2300
+ type: "string",
2301
+ doc: "The actual string value of the table cell."
2302
+ }),
2303
+ createIntrinsic("hbr", {}),
2304
+ createComponent(TSDoc, {
2305
+ heading: "Width of the table cell.",
2306
+ get children() {
2307
+ return createComponent(TSDocRemarks, { children: `The width of the table cell (where 1 is a single character in the terminal). If not specified, the width will be determined based on the content of the cell and the available space in the console.` });
2308
+ }
2309
+ }),
2310
+ createComponent(InterfaceMember, {
2311
+ name: "maxWidth",
2312
+ type: "number | SizeToken | undefined"
2313
+ }),
2314
+ createIntrinsic("hbr", {})
2315
+ ];
1686
2316
  }
1687
2317
  }),
1688
- createIntrinsic("hbr", {}),
1689
- createIntrinsic("hbr", {}),
2318
+ createComponent(Spacing, {}),
1690
2319
  createComponent(InterfaceDeclaration, {
1691
2320
  "export": true,
1692
2321
  name: "TableRowOptions",
@@ -1701,8 +2330,7 @@ function TableFunctionDeclaration(props) {
1701
2330
  }), createIntrinsic("hbr", {})];
1702
2331
  }
1703
2332
  }),
1704
- createIntrinsic("hbr", {}),
1705
- createIntrinsic("hbr", {}),
2333
+ createComponent(Spacing, {}),
1706
2334
  createComponent(InterfaceDeclaration, {
1707
2335
  "export": true,
1708
2336
  name: "TableOptions",
@@ -1717,8 +2345,7 @@ function TableFunctionDeclaration(props) {
1717
2345
  }), createIntrinsic("hbr", {})];
1718
2346
  }
1719
2347
  }),
1720
- createIntrinsic("hbr", {}),
1721
- createIntrinsic("hbr", {}),
2348
+ createComponent(Spacing, {}),
1722
2349
  createComponent(InterfaceDeclaration, {
1723
2350
  name: "Dimensions",
1724
2351
  doc: "The height and width for a specific table/cell used internally in the {@link table} function.",
@@ -1739,8 +2366,7 @@ function TableFunctionDeclaration(props) {
1739
2366
  ];
1740
2367
  }
1741
2368
  }),
1742
- createIntrinsic("hbr", {}),
1743
- createIntrinsic("hbr", {}),
2369
+ createComponent(Spacing, {}),
1744
2370
  createComponent(InterfaceDeclaration, {
1745
2371
  name: "TableCellBorder",
1746
2372
  doc: "The resolved complete border styles for a table cell.",
@@ -1797,18 +2423,17 @@ function TableFunctionDeclaration(props) {
1797
2423
  ];
1798
2424
  }
1799
2425
  }),
1800
- createIntrinsic("hbr", {}),
1801
- createIntrinsic("hbr", {}),
2426
+ createComponent(Spacing, {}),
1802
2427
  createComponent(TypeDeclaration, {
1803
2428
  name: "TableCell",
1804
2429
  doc: "The internal state of a formatted table cell in the {@link table} function.",
1805
- children: code`Required<Omit<TableCellOptions, "border">> & Dimensions & {
2430
+ children: code`Required<Omit<TableCellOptions, "maxWidth" | "border">> & Dimensions & {
1806
2431
  border: TableCellBorder;
2432
+ maxWidth?: number;
1807
2433
  };
1808
2434
  `
1809
2435
  }),
1810
- createIntrinsic("hbr", {}),
1811
- createIntrinsic("hbr", {}),
2436
+ createComponent(Spacing, {}),
1812
2437
  createComponent(TSDoc, {
1813
2438
  heading: "Write a table to the console.",
1814
2439
  get children() {
@@ -1847,7 +2472,7 @@ function TableFunctionDeclaration(props) {
1847
2472
  }),
1848
2473
  createIntrinsic("hbr", {}),
1849
2474
  memo(() => code`
1850
- const extractTableCell = (cell: string | TableCellOptions, opts?: TableOutputOptions): TableCell => {
2475
+ const extractTableCell = (cell: string | TableCellOptions, columnIndex: number, rowLength: number, opts?: TableOutputOptions): TableCell => {
1851
2476
  if (typeof cell === "string") {
1852
2477
  const borderOptions = opts?.border || "primary";
1853
2478
 
@@ -1874,7 +2499,7 @@ function TableFunctionDeclaration(props) {
1874
2499
  border.bottomRight = ${extractBorderOptionsString("bottomRight", theme)};
1875
2500
  }
1876
2501
 
1877
- const padding = Math.max(0, opts?.padding ?? ${theme.padding.table});
2502
+ const padding = Math.max(0, opts?.padding ?? ${theme.padding.table}) * (columnIndex === 0 || columnIndex === rowLength - 1 ? 2 : 1);
1878
2503
  const value = cell ?? "";
1879
2504
  const width = stripAnsi(value).length + padding * 2;
1880
2505
 
@@ -1915,17 +2540,21 @@ function TableFunctionDeclaration(props) {
1915
2540
  const padding = Math.max(0, cell.padding ?? opts?.padding ?? ${theme.padding.table});
1916
2541
  const value = cell.value ?? "";
1917
2542
  const width = stripAnsi(value).length + padding * 2;
2543
+ const maxWidth = cell.maxWidth ? typeof cell.maxWidth === "number" ? cell.maxWidth : calculateWidth(cell.maxWidth) : undefined;
1918
2544
 
1919
2545
  return {
1920
2546
  value,
1921
2547
  height: 1,
1922
2548
  width,
2549
+ maxWidth,
1923
2550
  border,
1924
2551
  padding,
1925
2552
  align: cell.align || opts?.align || "left",
1926
2553
  };
1927
2554
  }
1928
2555
  };
2556
+
2557
+ let colMaxWidths = [] as (number | undefined)[];
1929
2558
  `),
1930
2559
  createIntrinsic("hbr", {}),
1931
2560
  createComponent(IfStatement, {
@@ -1933,16 +2562,30 @@ function TableFunctionDeclaration(props) {
1933
2562
  get children() {
1934
2563
  return [createComponent(IfStatement, {
1935
2564
  condition: code`options.every(row => typeof row === "string" || (typeof row === "object" && !Array.isArray(row) && !("values" in row)))`,
1936
- children: code`cells.push(options.map(cell => extractTableCell(cell as string | TableCellOptions)));`
2565
+ children: code`cells.push(options.map((cell, index) => extractTableCell(cell as string | TableCellOptions, index, options.length)));`
1937
2566
  }), createComponent(ElseClause, { children: code`
1938
2567
  cells.push(
1939
2568
  ...options.map(row => Array.isArray(row)
1940
- ? row.reduce((cellRow, cell) => {
1941
- cellRow.push(extractTableCell(cell));
2569
+ ? row.reduce((cellRow, cell, index) => {
2570
+ if (colMaxWidths.length <= index) {
2571
+ colMaxWidths.push(undefined);
2572
+ }
2573
+ const newCell = extractTableCell(cell, index, row.length);
2574
+ if (newCell.maxWidth && (!colMaxWidths[index] || newCell.maxWidth < colMaxWidths[index]!)) {
2575
+ colMaxWidths[index] = newCell.maxWidth;
2576
+ }
2577
+ cellRow.push(newCell);
1942
2578
  return cellRow;
1943
2579
  }, [] as TableCell[])
1944
- : (row as TableRowOptions).values?.reduce((cellRow, cell) => {
1945
- cellRow.push(extractTableCell(cell, row as TableRowOptions));
2580
+ : (row as TableRowOptions).values?.reduce((cellRow, cell, index) => {
2581
+ if (colMaxWidths.length <= index) {
2582
+ colMaxWidths.push(undefined);
2583
+ }
2584
+ const newCell = extractTableCell(cell, index, (row as TableRowOptions).values?.length ?? 1, row as TableRowOptions);
2585
+ if (newCell.maxWidth && (!colMaxWidths[index] || newCell.maxWidth < colMaxWidths[index]!)) {
2586
+ colMaxWidths[index] = newCell.maxWidth;
2587
+ }
2588
+ cellRow.push(newCell);
1946
2589
  return cellRow;
1947
2590
  }, [] as TableCell[]) ?? []
1948
2591
  )
@@ -1953,12 +2596,26 @@ function TableFunctionDeclaration(props) {
1953
2596
  createComponent(ElseClause, { children: code`
1954
2597
  cells.push(
1955
2598
  ...options.values!.map(row => Array.isArray(row)
1956
- ? row.reduce((cellRow, cell) => {
1957
- cellRow.push(extractTableCell(cell));
2599
+ ? row.reduce((cellRow, cell, index) => {
2600
+ if (colMaxWidths.length <= index) {
2601
+ colMaxWidths.push(undefined);
2602
+ }
2603
+ const newCell = extractTableCell(cell, index, row.length);
2604
+ if (newCell.maxWidth && (!colMaxWidths[index] || newCell.maxWidth < colMaxWidths[index]!)) {
2605
+ colMaxWidths[index] = newCell.maxWidth;
2606
+ }
2607
+ cellRow.push(newCell);
1958
2608
  return cellRow;
1959
2609
  }, [] as TableCell[])
1960
- : (row as TableRowOptions).values?.reduce((cellRow, cell) => {
1961
- cellRow.push(extractTableCell(cell, options));
2610
+ : (row as TableRowOptions).values?.reduce((cellRow, cell, index) => {
2611
+ if (colMaxWidths.length <= index) {
2612
+ colMaxWidths.push(undefined);
2613
+ }
2614
+ const newCell = extractTableCell(cell, index, (row as TableRowOptions).values?.length ?? 1, options);
2615
+ if (newCell.maxWidth && (!colMaxWidths[index] || newCell.maxWidth < colMaxWidths[index]!)) {
2616
+ colMaxWidths[index] = newCell.maxWidth;
2617
+ }
2618
+ cellRow.push(newCell);
1962
2619
  return cellRow;
1963
2620
  }, [] as TableCell[]) ?? []
1964
2621
  )
@@ -1972,6 +2629,12 @@ if (cells.length === 0) {
1972
2629
  return;
1973
2630
  }
1974
2631
 
2632
+ cells.forEach(row => row.forEach((cell, index) => {
2633
+ if (colMaxWidths[index] && cell.maxWidth !== colMaxWidths[index]!) {
2634
+ cell.maxWidth = colMaxWidths[index]!;
2635
+ }
2636
+ }));
2637
+
1975
2638
  // Calculate table dimensions
1976
2639
  let colWidths = [] as number[];
1977
2640
  let rowDims = [] as Dimensions[];
@@ -2000,6 +2663,26 @@ do {
2000
2663
  recalculate = false;
2001
2664
  rowDims = calculateRowDimensions();
2002
2665
 
2666
+ if (!recalculate && colWidths.some((colWidth, index) => colMaxWidths[index] && colWidth > colMaxWidths[index]!)) {
2667
+ (colWidths.map((colWidth, index) => colMaxWidths[index] && colWidth > colMaxWidths[index]! ? index : undefined).filter(colWidth => colWidth !== undefined) as number[]).forEach(index => {
2668
+ cells.forEach(row => {
2669
+ const cell = row[index]!;
2670
+ if (colMaxWidths[index] && cell.width > colMaxWidths[index]) {
2671
+ const lines = splitText(
2672
+ cell.value,
2673
+ colMaxWidths[index] - cell.padding * 2,
2674
+ );
2675
+
2676
+ cell.value = lines.join("\\n");
2677
+ cell.height = lines.length;
2678
+ cell.width = Math.max(...lines.map(line => stripAnsi(line).length)) + cell.padding * 2;
2679
+
2680
+ recalculate = true;
2681
+ }
2682
+ });
2683
+ });
2684
+ }
2685
+
2003
2686
  rowDims.forEach((row, rowIndex) => {
2004
2687
  if (!recalculate && row.width > Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
2005
2688
  const cell = cells[rowIndex]!.reduce((largestCell, cell) => {
@@ -2011,7 +2694,8 @@ do {
2011
2694
 
2012
2695
  const lines = splitText(
2013
2696
  cell.value,
2014
- Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2} - (row.width - (cell.width - cell.padding * 2)), 0)
2697
+ Math.min(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2} - (row.width - (cell.width - cell.padding * 2)), 0),
2698
+ cell.maxWidth ?? Number.POSITIVE_INFINITY)
2015
2699
  );
2016
2700
 
2017
2701
  cell.value = lines.join("\\n");
@@ -2025,9 +2709,9 @@ do {
2025
2709
  if (!recalculate && colWidths.reduce((a, b) => a + b, 0) > Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
2026
2710
  let colIndex = 0;
2027
2711
  const cell = cells.reduce((ret, row) => {
2028
- return row.reduce((largest, current, i) => {
2712
+ return row.reduce((largest, current, index) => {
2029
2713
  if (largest.width < current.width) {
2030
- colIndex = i;
2714
+ colIndex = index;
2031
2715
  return current;
2032
2716
  }
2033
2717
  return largest;
@@ -2036,7 +2720,8 @@ do {
2036
2720
 
2037
2721
  const lines = splitText(
2038
2722
  cell.value,
2039
- Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2} - (colWidths.filter((_, i) => i !== colIndex).reduce((a, b) => a + b, 0)) - cell.padding * 2, 0)
2723
+ Math.min(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2} - (colWidths.filter((_, i) => i !== colIndex).reduce((a, b) => a + b, 0)) - cell.padding * 2, 0),
2724
+ cell.maxWidth ?? Number.POSITIVE_INFINITY)
2040
2725
  );
2041
2726
 
2042
2727
  cell.value = lines.join("\\n");
@@ -2123,48 +2808,41 @@ function ConsoleBuiltin(props) {
2123
2808
  },
2124
2809
  get children() {
2125
2810
  return [
2811
+ createComponent(AnsiHelpersDeclarations, {}),
2812
+ createComponent(Spacing, {}),
2126
2813
  createComponent(StripAnsiFunctionDeclaration, {}),
2127
- createIntrinsic("hbr", {}),
2128
- createIntrinsic("hbr", {}),
2814
+ createComponent(Spacing, {}),
2129
2815
  createComponent(WrapAnsiFunction, {}),
2130
- createIntrinsic("hbr", {}),
2131
- createIntrinsic("hbr", {}),
2816
+ createComponent(Spacing, {}),
2132
2817
  createComponent(ColorsDeclaration, {}),
2133
- createIntrinsic("hbr", {}),
2134
- createIntrinsic("hbr", {}),
2818
+ createComponent(Spacing, {}),
2135
2819
  createComponent(WriteLineFunctionDeclaration, {}),
2136
- createIntrinsic("hbr", {}),
2137
- createIntrinsic("hbr", {}),
2820
+ createComponent(Spacing, {}),
2138
2821
  createComponent(LinkFunctionDeclaration, {}),
2139
- createIntrinsic("hbr", {}),
2140
- createIntrinsic("hbr", {}),
2822
+ createComponent(Spacing, {}),
2141
2823
  createComponent(DividerFunctionDeclaration, {}),
2142
- createIntrinsic("hbr", {}),
2143
- createIntrinsic("hbr", {}),
2824
+ createComponent(Spacing, {}),
2144
2825
  createComponent(MessageFunctionDeclaration, {
2145
2826
  type: "help",
2146
2827
  variant: "help",
2147
2828
  consoleFnName: "log",
2148
2829
  description: "help"
2149
2830
  }),
2150
- createIntrinsic("hbr", {}),
2151
- createIntrinsic("hbr", {}),
2831
+ createComponent(Spacing, {}),
2152
2832
  createComponent(MessageFunctionDeclaration, {
2153
2833
  type: "success",
2154
2834
  variant: "success",
2155
2835
  consoleFnName: "info",
2156
2836
  description: "success"
2157
2837
  }),
2158
- createIntrinsic("hbr", {}),
2159
- createIntrinsic("hbr", {}),
2838
+ createComponent(Spacing, {}),
2160
2839
  createComponent(MessageFunctionDeclaration, {
2161
2840
  type: "info",
2162
2841
  variant: "info",
2163
2842
  consoleFnName: "info",
2164
2843
  description: "informational"
2165
2844
  }),
2166
- createIntrinsic("hbr", {}),
2167
- createIntrinsic("hbr", {}),
2845
+ createComponent(Spacing, {}),
2168
2846
  createComponent(MessageFunctionDeclaration, {
2169
2847
  type: "debug",
2170
2848
  variant: "debug",
@@ -2180,8 +2858,7 @@ function ConsoleBuiltin(props) {
2180
2858
  });
2181
2859
  }
2182
2860
  }),
2183
- createIntrinsic("hbr", {}),
2184
- createIntrinsic("hbr", {}),
2861
+ createComponent(Spacing, {}),
2185
2862
  createComponent(MessageFunctionDeclaration, {
2186
2863
  type: "verbose",
2187
2864
  variant: "info",
@@ -2198,24 +2875,21 @@ function ConsoleBuiltin(props) {
2198
2875
  });
2199
2876
  }
2200
2877
  }),
2201
- createIntrinsic("hbr", {}),
2202
- createIntrinsic("hbr", {}),
2878
+ createComponent(Spacing, {}),
2203
2879
  createComponent(MessageFunctionDeclaration, {
2204
2880
  type: "warn",
2205
2881
  variant: "warning",
2206
2882
  consoleFnName: "warn",
2207
2883
  description: "warning"
2208
2884
  }),
2209
- createIntrinsic("hbr", {}),
2210
- createIntrinsic("hbr", {}),
2885
+ createComponent(Spacing, {}),
2211
2886
  createComponent(MessageFunctionDeclaration, {
2212
2887
  type: "danger",
2213
2888
  variant: "danger",
2214
2889
  consoleFnName: "error",
2215
2890
  description: "destructive/danger"
2216
2891
  }),
2217
- createIntrinsic("hbr", {}),
2218
- createIntrinsic("hbr", {}),
2892
+ createComponent(Spacing, {}),
2219
2893
  createComponent(MessageFunctionDeclaration, {
2220
2894
  type: "error",
2221
2895
  variant: "error",
@@ -2234,8 +2908,7 @@ function ConsoleBuiltin(props) {
2234
2908
  name: "message",
2235
2909
  type: "string | undefined"
2236
2910
  }),
2237
- createIntrinsic("hbr", {}),
2238
- createIntrinsic("hbr", {}),
2911
+ createComponent(Spacing, {}),
2239
2912
  createComponent(IfStatement, {
2240
2913
  condition: code`(err as Error)?.message`,
2241
2914
  get children() {
@@ -2249,19 +2922,16 @@ function ConsoleBuiltin(props) {
2249
2922
  ];
2250
2923
  }
2251
2924
  }),
2252
- createIntrinsic("hbr", {}),
2253
- createIntrinsic("hbr", {}),
2925
+ createComponent(Spacing, {}),
2254
2926
  createComponent(TableFunctionDeclaration, {}),
2255
- createIntrinsic("hbr", {}),
2256
- createIntrinsic("hbr", {}),
2927
+ createComponent(Spacing, {}),
2257
2928
  children,
2258
- createIntrinsic("hbr", {}),
2259
- createIntrinsic("hbr", {})
2929
+ createComponent(Spacing, {})
2260
2930
  ];
2261
2931
  }
2262
2932
  });
2263
2933
  }
2264
2934
 
2265
2935
  //#endregion
2266
- export { ColorsDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, WrapAnsiFunction, WriteLineFunctionDeclaration };
2936
+ export { AnsiHelpersDeclarations, ColorsDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, WrapAnsiFunction, WriteLineFunctionDeclaration };
2267
2937
  //# sourceMappingURL=console-builtin.mjs.map