@peteanderson/ansi 0.2.3 → 0.3.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 (51) hide show
  1. package/README.md +70 -19
  2. package/dist/ansi.d.ts +41 -8
  3. package/dist/ansi.js +44 -18
  4. package/dist/caret.d.ts +28 -25
  5. package/dist/caret.js +31 -1
  6. package/dist/erase.d.ts +13 -14
  7. package/dist/erase.js +16 -1
  8. package/dist/features/build.d.ts +11 -0
  9. package/dist/features/build.js +50 -0
  10. package/dist/features/detect.d.ts +4 -0
  11. package/dist/features/detect.js +33 -0
  12. package/dist/features/features.d.ts +5 -0
  13. package/dist/features/features.js +39 -0
  14. package/dist/features/index.d.ts +2 -0
  15. package/dist/features/index.js +2 -0
  16. package/dist/index.d.ts +12 -62
  17. package/dist/scroll.d.ts +6 -2
  18. package/dist/scroll.js +7 -1
  19. package/dist/sgr/color/color.d.ts +9 -0
  20. package/dist/sgr/color/color.js +76 -0
  21. package/dist/sgr/color/index.d.ts +2 -0
  22. package/dist/sgr/color/index.js +2 -0
  23. package/dist/sgr/color/utils.d.ts +27 -0
  24. package/dist/sgr/color/utils.js +67 -0
  25. package/dist/sgr/index.d.ts +5 -55
  26. package/dist/sgr/reset.d.ts +1 -1
  27. package/dist/sgr/reset.js +2 -2
  28. package/dist/sgr/sgr.d.ts +3 -3
  29. package/dist/sgr/sgr.js +18 -8
  30. package/dist/sgr/style.d.ts +13 -13
  31. package/dist/sgr/style.js +18 -15
  32. package/package.json +1 -1
  33. package/src/ansi.js +54 -24
  34. package/src/caret.js +40 -3
  35. package/src/erase.js +18 -1
  36. package/src/features/build.js +60 -0
  37. package/src/features/detect.js +39 -0
  38. package/src/features/features.js +53 -0
  39. package/src/features/index.js +1 -0
  40. package/src/features/types.d.ts +9 -0
  41. package/src/scroll.js +9 -1
  42. package/src/sgr/color/color.js +104 -0
  43. package/src/sgr/color/index.js +1 -0
  44. package/src/sgr/color/types.d.ts +28 -0
  45. package/src/sgr/color/utils.js +81 -0
  46. package/src/sgr/reset.js +2 -2
  47. package/src/sgr/sgr.js +25 -14
  48. package/src/sgr/style.js +19 -15
  49. package/dist/sgr/color.d.ts +0 -62
  50. package/dist/sgr/color.js +0 -111
  51. package/src/sgr/color.js +0 -130
package/dist/sgr/color.js DELETED
@@ -1,111 +0,0 @@
1
- "use strict";
2
- const { sgr } = require("./sgr");
3
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
4
- const rgb = (r, g, b, open, close) => sgr([open, 2, r, g, b], close);
5
- /**
6
- * @overload
7
- * @param {number} code
8
- * @param {number} open
9
- * @param {number} close
10
- * @returns {(text: string) => string}
11
- */ /**
12
- * @overload
13
- * @param {number} r
14
- * @param {number} g
15
- * @param {number} b
16
- * @param {number} open
17
- * @param {number} close
18
- * @returns {(text: string) => string}
19
- */ /**
20
- @type {
21
- (
22
- ...args: [number, number, number] | [number, number, number, number, number]
23
- ) => (text: string) => string}
24
- */
25
- function x256(...args) {
26
- if (args.length === 3)
27
- return sgr([args[1], 5, args[0]], args[2]);
28
- const [r, g, b, open, close] = args;
29
- if (r === g && g === b) {
30
- // grayscale
31
- return sgr([open, 5, 232 + Math.floor(r * 24 / 256)], close);
32
- }
33
- // 6x6x6 color cube
34
- return sgr([
35
- open,
36
- 5,
37
- 16 +
38
- Math.floor(r * 6 / 256) * 36 +
39
- Math.floor(g * 6 / 256) * 6 +
40
- Math.floor(b * 6 / 256)
41
- ], close);
42
- }
43
- const fg = {
44
- black: sgr(30, 39),
45
- red: sgr(31, 39),
46
- green: sgr(32, 39),
47
- yellow: sgr(33, 39),
48
- blue: sgr(34, 39),
49
- magenta: sgr(35, 39),
50
- cyan: sgr(36, 39),
51
- white: sgr(37, 39),
52
- brightBlack: sgr(90, 39),
53
- brightRed: sgr(91, 39),
54
- brightGreen: sgr(92, 39),
55
- brightYellow: sgr(93, 39),
56
- brightBlue: sgr(94, 39),
57
- brightMagenta: sgr(95, 39),
58
- brightCyan: sgr(96, 39),
59
- brightWhite: sgr(97, 39),
60
- default: "\x1b[39m",
61
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
62
- rgb: (r, g, b) => rgb(r, g, b, 38, 39),
63
- /**
64
- * @overload
65
- * @param {number} code
66
- * @returns {(text: string) => string}
67
- */ /**
68
- * @param {number} r
69
- * @param {number} g
70
- * @param {number} b
71
- * @returns {(text: string) => string}
72
- */ /** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
73
- x256: (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
74
- ? x256(arg0, 38, 39)
75
- : x256(arg0, arg1, arg2, 38, 39),
76
- };
77
- const bg = {
78
- black: sgr(40, 49),
79
- red: sgr(41, 49),
80
- green: sgr(42, 49),
81
- yellow: sgr(43, 49),
82
- blue: sgr(44, 49),
83
- magenta: sgr(45, 49),
84
- cyan: sgr(46, 49),
85
- white: sgr(47, 49),
86
- brightBlack: sgr(100, 49),
87
- brightRed: sgr(101, 49),
88
- brightGreen: sgr(102, 49),
89
- brightYellow: sgr(103, 49),
90
- brightBlue: sgr(104, 49),
91
- brightMagenta: sgr(105, 49),
92
- brightCyan: sgr(106, 49),
93
- brightWhite: sgr(107, 49),
94
- default: "\x1b[49m",
95
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
96
- rgb: (r, g, b) => rgb(r, g, b, 48, 49),
97
- /**
98
- * @overload
99
- * @param {number} code
100
- * @returns {(text: string) => string}
101
- */ /**
102
- * @param {number} r
103
- * @param {number} g
104
- * @param {number} b
105
- * @returns {(text: string) => string}
106
- */ /** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
107
- x256: (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
108
- ? x256(arg0, 48, 49)
109
- : x256(arg0, arg1, arg2, 48, 49),
110
- };
111
- module.exports = { fg, bg };
package/src/sgr/color.js DELETED
@@ -1,130 +0,0 @@
1
- "use strict";
2
-
3
- const {sgr} = require("./sgr");
4
-
5
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
6
- const rgb = (r, g, b, open, close) => sgr([open, 2, r, g, b], close);
7
-
8
- /**
9
- * @overload
10
- * @param {number} code
11
- * @param {number} open
12
- * @param {number} close
13
- * @returns {(text: string) => string}
14
- *//**
15
- * @overload
16
- * @param {number} r
17
- * @param {number} g
18
- * @param {number} b
19
- * @param {number} open
20
- * @param {number} close
21
- * @returns {(text: string) => string}
22
- *//**
23
- @type {
24
- (
25
- ...args: [number, number, number] | [number, number, number, number, number]
26
- ) => (text: string) => string}
27
- */
28
- function x256(...args) {
29
- if (args.length === 3)
30
- return sgr([args[1], 5, args[0]], args[2]);
31
-
32
- const [r, g, b, open, close] = args;
33
- if (r === g && g === b) {
34
- // grayscale
35
- return sgr([open, 5, 232 + Math.floor(r * 24 / 256)], close);
36
- }
37
-
38
- // 6x6x6 color cube
39
- return sgr(
40
- [
41
- open,
42
- 5,
43
- 16 +
44
- Math.floor(r * 6 / 256) * 36 +
45
- Math.floor(g * 6 / 256) * 6 +
46
- Math.floor(b * 6 / 256)
47
- ],
48
- close,
49
- );
50
- }
51
-
52
- const fg = {
53
- black : sgr(30, 39),
54
- red : sgr(31, 39),
55
- green : sgr(32, 39),
56
- yellow : sgr(33, 39),
57
- blue : sgr(34, 39),
58
- magenta : sgr(35, 39),
59
- cyan : sgr(36, 39),
60
- white : sgr(37, 39),
61
-
62
- brightBlack : sgr(90, 39),
63
- brightRed : sgr(91, 39),
64
- brightGreen : sgr(92, 39),
65
- brightYellow : sgr(93, 39),
66
- brightBlue : sgr(94, 39),
67
- brightMagenta : sgr(95, 39),
68
- brightCyan : sgr(96, 39),
69
- brightWhite : sgr(97, 39),
70
-
71
- default : "\x1b[39m",
72
-
73
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
74
- rgb : (r, g, b) => rgb(r, g, b, 38, 39),
75
-
76
- /**
77
- * @overload
78
- * @param {number} code
79
- * @returns {(text: string) => string}
80
- *//**
81
- * @param {number} r
82
- * @param {number} g
83
- * @param {number} b
84
- * @returns {(text: string) => string}
85
- *//** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
86
- x256 : (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
87
- ? x256(arg0 , 38, 39)
88
- : x256(arg0, arg1, arg2, 38, 39),
89
- };
90
-
91
- const bg = {
92
- black : sgr(40, 49),
93
- red : sgr(41, 49),
94
- green : sgr(42, 49),
95
- yellow : sgr(43, 49),
96
- blue : sgr(44, 49),
97
- magenta : sgr(45, 49),
98
- cyan : sgr(46, 49),
99
- white : sgr(47, 49),
100
-
101
- brightBlack : sgr(100, 49),
102
- brightRed : sgr(101, 49),
103
- brightGreen : sgr(102, 49),
104
- brightYellow : sgr(103, 49),
105
- brightBlue : sgr(104, 49),
106
- brightMagenta : sgr(105, 49),
107
- brightCyan : sgr(106, 49),
108
- brightWhite : sgr(107, 49),
109
-
110
- default : "\x1b[49m",
111
-
112
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
113
- rgb : (r, g, b) => rgb(r, g, b, 48, 49),
114
-
115
- /**
116
- * @overload
117
- * @param {number} code
118
- * @returns {(text: string) => string}
119
- *//**
120
- * @param {number} r
121
- * @param {number} g
122
- * @param {number} b
123
- * @returns {(text: string) => string}
124
- *//** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
125
- x256 : (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
126
- ? x256(arg0 , 48, 49)
127
- : x256(arg0, arg1, arg2, 48, 49),
128
- };
129
-
130
- module.exports = {fg, bg};