@ecmaos/coreutils 0.1.1 → 0.1.3
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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +182 -0
- package/dist/commands/cd.d.ts.map +1 -1
- package/dist/commands/cd.js +1 -7
- package/dist/commands/cd.js.map +1 -1
- package/dist/commands/hex.d.ts +4 -0
- package/dist/commands/hex.d.ts.map +1 -0
- package/dist/commands/hex.js +82 -0
- package/dist/commands/hex.js.map +1 -0
- package/dist/commands/less.d.ts +4 -0
- package/dist/commands/less.d.ts.map +1 -0
- package/dist/commands/less.js +173 -0
- package/dist/commands/less.js.map +1 -0
- package/dist/commands/ln.d.ts +4 -0
- package/dist/commands/ln.d.ts.map +1 -0
- package/dist/commands/ln.js +104 -0
- package/dist/commands/ln.js.map +1 -0
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +91 -11
- package/dist/commands/ls.js.map +1 -1
- package/dist/commands/sed.d.ts +4 -0
- package/dist/commands/sed.d.ts.map +1 -0
- package/dist/commands/sed.js +381 -0
- package/dist/commands/sed.js.map +1 -0
- package/dist/commands/tee.d.ts +4 -0
- package/dist/commands/tee.d.ts.map +1 -0
- package/dist/commands/tee.js +87 -0
- package/dist/commands/tee.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/commands/cd.ts +1 -8
- package/src/commands/hex.ts +92 -0
- package/src/commands/less.ts +192 -0
- package/src/commands/ln.ts +108 -0
- package/src/commands/ls.ts +85 -11
- package/src/commands/sed.ts +436 -0
- package/src/commands/tee.ts +93 -0
- package/src/index.ts +16 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,187 @@
|
|
|
1
1
|
# @ecmaos/coreutils
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ebc97d6: feat: Add hex, less, sed, and tee commands to coreutils
|
|
8
|
+
|
|
9
|
+
- Add hex viewer command for binary file inspection
|
|
10
|
+
- Add less command for file paging with navigation
|
|
11
|
+
- Add sed command for stream editing operations
|
|
12
|
+
- Add tee command for splitting output streams
|
|
13
|
+
- Fix AI app stream handling for better reliability
|
|
14
|
+
- Refactor AI app session storage to use cache directory instead of config directory
|
|
15
|
+
- Update turbo config to include environment variables
|
|
16
|
+
|
|
17
|
+
## 0.1.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- ae8f619: OVERVIEW
|
|
22
|
+
|
|
23
|
+
Total Commits: 5
|
|
24
|
+
Files Changed: 56 files
|
|
25
|
+
Additions: +1,632 lines
|
|
26
|
+
Deletions: -539 lines
|
|
27
|
+
Net Change: +1,093 lines
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
COMMIT DETAILS
|
|
32
|
+
|
|
33
|
+
1. c6f2d9c - docs: Update NEWS and README files; add tilde expansion feature in shell commands
|
|
34
|
+
|
|
35
|
+
Type: Documentation & Enhancement
|
|
36
|
+
Date: Wed Dec 31 11:52:52 2025
|
|
37
|
+
|
|
38
|
+
Changes:
|
|
39
|
+
|
|
40
|
+
- Updated NEWS.md and README.md with new features and improvements
|
|
41
|
+
- Added tilde expansion feature in shell commands (~ expands to home directory)
|
|
42
|
+
- Enhanced filesystem type recognition
|
|
43
|
+
- Improved terminal command handling
|
|
44
|
+
- Removed 292 lines from core/kernel/src/tree/lib/commands/index.ts (edit command moved to separate package)
|
|
45
|
+
- Added shell functionality in core/kernel/src/tree/shell.ts (71 new lines)
|
|
46
|
+
- Enhanced terminal and filesystem modules
|
|
47
|
+
|
|
48
|
+
Files Modified: 9 files (+166, -327)
|
|
49
|
+
|
|
50
|
+
***
|
|
51
|
+
|
|
52
|
+
2. b4454a1 - chore: Bump turbo package version from 2.5.4 to 2.7.2
|
|
53
|
+
|
|
54
|
+
Type: Dependency Update
|
|
55
|
+
|
|
56
|
+
Changes:
|
|
57
|
+
|
|
58
|
+
- Updated Turbo monorepo tool from version 2.5.4 to 2.7.2
|
|
59
|
+
- Updated package.json and pnpm-lock.yaml files
|
|
60
|
+
|
|
61
|
+
Impact: Infrastructure improvement for better monorepo tooling support
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
3. 6660f4c - chore: Update pnpm-lock.yaml files across multiple applications and modules
|
|
66
|
+
|
|
67
|
+
Type: Dependency Maintenance
|
|
68
|
+
|
|
69
|
+
Changes:
|
|
70
|
+
|
|
71
|
+
- Cleaned up outdated checksum entries in pnpm-lock.yaml files
|
|
72
|
+
- Ensured consistency in package versions across the monorepo
|
|
73
|
+
- Updated lockfiles in:
|
|
74
|
+
- Multiple apps (ai, boilerplate, code, news, python, webamp)
|
|
75
|
+
- Core packages (bios, jaffa, kernel, metal, swapi, types, utils)
|
|
76
|
+
- Device packages (audio, battery, bluetooth, echo, gamepad, geo, gpu, hid, midi, presentation, sensors, serial, usb, webgl)
|
|
77
|
+
- Modules and utils
|
|
78
|
+
|
|
79
|
+
Impact: Improved dependency consistency and resolved potential checksum issues
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
4. 01da80e - feat: improve and move edit command to its own package
|
|
84
|
+
|
|
85
|
+
Type: Feature (Major Refactor)
|
|
86
|
+
Date: Wed Dec 31 12:48:45 2025
|
|
87
|
+
|
|
88
|
+
Changes:
|
|
89
|
+
|
|
90
|
+
- Extracted edit command from kernel into standalone apps/edit package
|
|
91
|
+
- Created comprehensive editor implementation with:
|
|
92
|
+
- Multiple editing modes: normal, insert, replace, command
|
|
93
|
+
- File operations support
|
|
94
|
+
- Renderer for terminal-based editing
|
|
95
|
+
- Type definitions for editor state
|
|
96
|
+
- Removed 292 lines of edit command code from core/kernel/src/tree/lib/commands/index.ts
|
|
97
|
+
- Added build configuration (build.cjs)
|
|
98
|
+
- Updated package dependencies
|
|
99
|
+
|
|
100
|
+
Files Modified: 14 files (+1,054, -304)
|
|
101
|
+
|
|
102
|
+
Impact: Better separation of concerns, improved maintainability, and enhanced editor functionality
|
|
103
|
+
|
|
104
|
+
***
|
|
105
|
+
|
|
106
|
+
5. 90072ec - feat: add 'ln' command and enhance 'ls' command to support symbolic and hard link information
|
|
107
|
+
|
|
108
|
+
Type: Feature
|
|
109
|
+
Date: Wed Dec 31 13:11:53 2025
|
|
110
|
+
|
|
111
|
+
Changes:
|
|
112
|
+
|
|
113
|
+
- Added new ln command for creating symbolic and hard links (core/utils/src/commands/ln.ts - 108 lines)
|
|
114
|
+
- Enhanced ls command to display link information:
|
|
115
|
+
- Shows link count for files
|
|
116
|
+
- Displays target path for symbolic links
|
|
117
|
+
- Improved file listing with link details
|
|
118
|
+
- Updated command exports in core/utils/src/index.ts
|
|
119
|
+
|
|
120
|
+
Files Modified: 3 files (+196, -11)
|
|
121
|
+
|
|
122
|
+
Impact: Better filesystem management capabilities, improved visibility into file relationships
|
|
123
|
+
|
|
124
|
+
***
|
|
125
|
+
|
|
126
|
+
SUMMARY BY CATEGORY
|
|
127
|
+
|
|
128
|
+
Features:
|
|
129
|
+
|
|
130
|
+
- Edit Command Package: Extracted and improved editor into standalone package with multiple modes
|
|
131
|
+
- Link Command: New ln command for creating symbolic and hard links
|
|
132
|
+
- Enhanced LS: Improved ls command with link information display
|
|
133
|
+
- Tilde Expansion: Shell command support for ~ home directory expansion
|
|
134
|
+
|
|
135
|
+
Documentation:
|
|
136
|
+
|
|
137
|
+
- Updated NEWS and README files with latest changes
|
|
138
|
+
|
|
139
|
+
Infrastructure:
|
|
140
|
+
|
|
141
|
+
- Turbo version bump (2.5.4 -> 2.7.2)
|
|
142
|
+
- Dependency lockfile cleanup across entire monorepo
|
|
143
|
+
|
|
144
|
+
Code Quality:
|
|
145
|
+
|
|
146
|
+
- Better separation of concerns (edit command extraction)
|
|
147
|
+
- Improved filesystem type recognition
|
|
148
|
+
- Enhanced terminal command handling
|
|
149
|
+
|
|
150
|
+
***
|
|
151
|
+
|
|
152
|
+
AFFECTED PACKAGES
|
|
153
|
+
|
|
154
|
+
Core Packages:
|
|
155
|
+
|
|
156
|
+
- @ecmaos/kernel - Shell, terminal, filesystem enhancements
|
|
157
|
+
- @ecmaos/types - Shell type updates
|
|
158
|
+
- @ecmaos/utils - New ln command, enhanced ls command
|
|
159
|
+
|
|
160
|
+
Applications:
|
|
161
|
+
|
|
162
|
+
- apps/edit - New standalone editor package
|
|
163
|
+
|
|
164
|
+
Dependencies:
|
|
165
|
+
|
|
166
|
+
- All packages: Lockfile updates for consistency
|
|
167
|
+
|
|
168
|
+
***
|
|
169
|
+
|
|
170
|
+
BREAKING CHANGES
|
|
171
|
+
|
|
172
|
+
None identified. All changes appear to be additive or internal refactoring.
|
|
173
|
+
|
|
174
|
+
***
|
|
175
|
+
|
|
176
|
+
MIGRATION NOTES
|
|
177
|
+
|
|
178
|
+
- The edit command has been moved from the kernel to apps/edit package. Any code referencing the edit command in the kernel should be updated to use the new package.
|
|
179
|
+
- The ls command now shows additional link information, which may affect scripts parsing its output.
|
|
180
|
+
- Shell commands now support tilde expansion (~), which may affect scripts that previously handled paths differently.
|
|
181
|
+
|
|
182
|
+
- Updated dependencies [ae8f619]
|
|
183
|
+
- @ecmaos/types@0.4.2
|
|
184
|
+
|
|
3
185
|
## 0.1.1
|
|
4
186
|
|
|
5
187
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cd.d.ts","sourceRoot":"","sources":["../../src/commands/cd.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"cd.d.ts","sourceRoot":"","sources":["../../src/commands/cd.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,CAoB/F"}
|
package/dist/commands/cd.js
CHANGED
|
@@ -12,13 +12,7 @@ export function createCommand(kernel, shell, terminal) {
|
|
|
12
12
|
{ name: 'path', type: String, typeLabel: '{underline path}', defaultOption: true, description: 'The path to the directory to change to' }
|
|
13
13
|
],
|
|
14
14
|
run: async (argv) => {
|
|
15
|
-
|
|
16
|
-
if (destination && destination.startsWith('~')) {
|
|
17
|
-
const home = shell.env.get('HOME');
|
|
18
|
-
if (home) {
|
|
19
|
-
destination = destination.replace(/^~(?=$|\/)/, home);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
15
|
+
const destination = argv.path || shell.cwd;
|
|
22
16
|
const fullPath = destination ? path.resolve(shell.cwd, destination) : shell.cwd;
|
|
23
17
|
await shell.context.fs.promises.access(fullPath);
|
|
24
18
|
shell.cwd = fullPath;
|
package/dist/commands/cd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cd.js","sourceRoot":"","sources":["../../src/commands/cd.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAY,EAAE,QAAkB;IAC5E,OAAO,IAAI,eAAe,CAAC;QACzB,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,oCAAoC;QACjD,MAAM;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C,CAAC,KAAK,CAAC,GAAG,CAAA;YAC/E,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAChD,KAAK,CAAC,GAAG,GAAG,QAAQ,CAAA;YACpB,YAAY,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAA;YAC9D,OAAO,CAAC,CAAA;QACV,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../src/commands/hex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAG/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,CAqF/F"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { TerminalCommand } from '../shared/terminal-command.js';
|
|
3
|
+
import { writelnStdout, writelnStderr } from '../shared/helpers.js';
|
|
4
|
+
export function createCommand(kernel, shell, terminal) {
|
|
5
|
+
return new TerminalCommand({
|
|
6
|
+
command: 'hex',
|
|
7
|
+
description: 'Display file contents in hexadecimal format',
|
|
8
|
+
kernel,
|
|
9
|
+
shell,
|
|
10
|
+
terminal,
|
|
11
|
+
options: [
|
|
12
|
+
{ name: 'help', type: Boolean, description: kernel.i18n.t('Display help') },
|
|
13
|
+
{ name: 'path', type: String, typeLabel: '{underline path}', defaultOption: true, description: 'The path to the file to display' }
|
|
14
|
+
],
|
|
15
|
+
run: async (argv, process) => {
|
|
16
|
+
const filePath = argv.path;
|
|
17
|
+
if (!filePath) {
|
|
18
|
+
await writelnStderr(process, terminal, 'Usage: hex <file>');
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
const fullPath = path.resolve(shell.cwd, filePath);
|
|
22
|
+
try {
|
|
23
|
+
const exists = await shell.context.fs.promises.exists(fullPath);
|
|
24
|
+
if (!exists) {
|
|
25
|
+
await writelnStderr(process, terminal, `hex: ${filePath}: No such file or directory`);
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
const stats = await shell.context.fs.promises.stat(fullPath);
|
|
29
|
+
if (stats.isDirectory()) {
|
|
30
|
+
await writelnStderr(process, terminal, `hex: ${filePath}: Is a directory`);
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
const data = await shell.context.fs.promises.readFile(fullPath);
|
|
34
|
+
const bytesPerLine = 16;
|
|
35
|
+
for (let offset = 0; offset < data.length; offset += bytesPerLine) {
|
|
36
|
+
const lineBytes = data.slice(offset, offset + bytesPerLine);
|
|
37
|
+
const offsetHex = offset.toString(16).padStart(8, '0');
|
|
38
|
+
const hexGroups = [];
|
|
39
|
+
const asciiChars = [];
|
|
40
|
+
for (let i = 0; i < bytesPerLine; i++) {
|
|
41
|
+
if (i < lineBytes.length) {
|
|
42
|
+
const byte = lineBytes[i];
|
|
43
|
+
if (byte === undefined)
|
|
44
|
+
continue;
|
|
45
|
+
const hex = byte.toString(16).padStart(2, '0');
|
|
46
|
+
if (i % 2 === 0) {
|
|
47
|
+
hexGroups.push(hex);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
hexGroups[hexGroups.length - 1] += hex;
|
|
51
|
+
}
|
|
52
|
+
if (byte >= 32 && byte <= 126) {
|
|
53
|
+
asciiChars.push(String.fromCharCode(byte));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
asciiChars.push('.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
if (i % 2 === 0) {
|
|
61
|
+
hexGroups.push(' ');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
hexGroups[hexGroups.length - 1] += ' ';
|
|
65
|
+
}
|
|
66
|
+
asciiChars.push(' ');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const hexString = hexGroups.join(' ').padEnd(47, ' ');
|
|
70
|
+
const asciiString = asciiChars.join('');
|
|
71
|
+
await writelnStdout(process, terminal, `${offsetHex}: ${hexString} ${asciiString}`);
|
|
72
|
+
}
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
await writelnStderr(process, terminal, `hex: ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=hex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../../src/commands/hex.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAGvB,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEnE,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAY,EAAE,QAAkB;IAC5E,OAAO,IAAI,eAAe,CAAC;QACzB,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,6CAA6C;QAC1D,MAAM;QACN,KAAK;QACL,QAAQ;QACR,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE;YAC3E,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,iCAAiC,EAAE;SACnI;QAC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,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,CAAA;4BACzC,CAAC;4BACD,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;wBACtB,CAAC;oBACH,CAAC;oBAED,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;oBACrD,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;oBAEvC,MAAM,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,SAAS,KAAK,SAAS,KAAK,WAAW,EAAE,CAAC,CAAA;gBACtF,CAAC;gBAED,OAAO,CAAC,CAAA;YACV,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,QAAQ,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAA;gBACvH,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"less.d.ts","sourceRoot":"","sources":["../../src/commands/less.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAG/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,CAuL/F"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import ansi from 'ansi-escape-sequences';
|
|
3
|
+
import { TerminalCommand } from '../shared/terminal-command.js';
|
|
4
|
+
import { writelnStderr } from '../shared/helpers.js';
|
|
5
|
+
export function createCommand(kernel, shell, terminal) {
|
|
6
|
+
return new TerminalCommand({
|
|
7
|
+
command: 'less',
|
|
8
|
+
description: 'View file contents interactively',
|
|
9
|
+
kernel,
|
|
10
|
+
shell,
|
|
11
|
+
terminal,
|
|
12
|
+
options: [
|
|
13
|
+
{ name: 'help', type: Boolean, description: kernel.i18n.t('Display help') },
|
|
14
|
+
{ name: 'path', type: String, typeLabel: '{underline path}', defaultOption: true, description: 'The path to the file to view' }
|
|
15
|
+
],
|
|
16
|
+
run: async (argv, process) => {
|
|
17
|
+
if (!process)
|
|
18
|
+
return 1;
|
|
19
|
+
let lines = [];
|
|
20
|
+
let currentLine = 0;
|
|
21
|
+
let keyListener = null;
|
|
22
|
+
let linesRendered = 0;
|
|
23
|
+
try {
|
|
24
|
+
if (argv.path) {
|
|
25
|
+
const filePath = argv.path;
|
|
26
|
+
const expandedPath = shell.expandTilde(filePath);
|
|
27
|
+
const fullPath = path.resolve(shell.cwd, expandedPath);
|
|
28
|
+
const exists = await shell.context.fs.promises.exists(fullPath);
|
|
29
|
+
if (!exists) {
|
|
30
|
+
await writelnStderr(process, terminal, `less: ${filePath}: No such file or directory`);
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
const stats = await shell.context.fs.promises.stat(fullPath);
|
|
34
|
+
if (stats.isDirectory()) {
|
|
35
|
+
await writelnStderr(process, terminal, `less: ${filePath}: Is a directory`);
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
const content = await shell.context.fs.promises.readFile(fullPath, 'utf-8');
|
|
39
|
+
lines = content.split('\n');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (!process.stdin) {
|
|
43
|
+
await writelnStderr(process, terminal, 'less: No input provided');
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
const reader = process.stdin.getReader();
|
|
47
|
+
const decoder = new TextDecoder();
|
|
48
|
+
const chunks = [];
|
|
49
|
+
try {
|
|
50
|
+
while (true) {
|
|
51
|
+
const { done, value } = await reader.read();
|
|
52
|
+
if (done)
|
|
53
|
+
break;
|
|
54
|
+
chunks.push(decoder.decode(value, { stream: true }));
|
|
55
|
+
}
|
|
56
|
+
chunks.push(decoder.decode(new Uint8Array(), { stream: false }));
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
reader.releaseLock();
|
|
60
|
+
}
|
|
61
|
+
const content = chunks.join('');
|
|
62
|
+
lines = content.split('\n');
|
|
63
|
+
}
|
|
64
|
+
if (lines.length === 0) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
terminal.unlisten();
|
|
68
|
+
terminal.write('\n');
|
|
69
|
+
terminal.write(ansi.cursor.hide);
|
|
70
|
+
const rows = terminal.rows;
|
|
71
|
+
const displayRows = rows - 1;
|
|
72
|
+
const render = () => {
|
|
73
|
+
const maxLine = Math.max(0, lines.length - displayRows);
|
|
74
|
+
if (currentLine > maxLine) {
|
|
75
|
+
currentLine = maxLine;
|
|
76
|
+
}
|
|
77
|
+
if (currentLine < 0) {
|
|
78
|
+
currentLine = 0;
|
|
79
|
+
}
|
|
80
|
+
if (linesRendered > 0) {
|
|
81
|
+
terminal.write(ansi.cursor.up(linesRendered));
|
|
82
|
+
}
|
|
83
|
+
const endLine = Math.min(currentLine + displayRows, lines.length);
|
|
84
|
+
linesRendered = 0;
|
|
85
|
+
for (let i = currentLine; i < endLine; i++) {
|
|
86
|
+
terminal.write(ansi.erase.inLine(2));
|
|
87
|
+
const line = lines[i] || '';
|
|
88
|
+
terminal.write(line);
|
|
89
|
+
linesRendered++;
|
|
90
|
+
if (i < endLine - 1) {
|
|
91
|
+
terminal.write('\n');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (let i = endLine - currentLine; i < displayRows; i++) {
|
|
95
|
+
terminal.write('\n');
|
|
96
|
+
terminal.write(ansi.erase.inLine(2));
|
|
97
|
+
linesRendered++;
|
|
98
|
+
}
|
|
99
|
+
const percentage = lines.length > 0 ? Math.round(((endLine / lines.length) * 100)) : 100;
|
|
100
|
+
const statusLine = `-- ${currentLine + 1}-${endLine} / ${lines.length} (${percentage}%)`;
|
|
101
|
+
terminal.write('\n');
|
|
102
|
+
terminal.write(ansi.erase.inLine(2));
|
|
103
|
+
terminal.write(statusLine);
|
|
104
|
+
linesRendered++;
|
|
105
|
+
};
|
|
106
|
+
render();
|
|
107
|
+
await new Promise((resolve) => {
|
|
108
|
+
keyListener = terminal.onKey(async ({ domEvent }) => {
|
|
109
|
+
const keyName = domEvent.key;
|
|
110
|
+
switch (keyName) {
|
|
111
|
+
case 'q':
|
|
112
|
+
case 'Q':
|
|
113
|
+
case 'Escape':
|
|
114
|
+
if (keyListener) {
|
|
115
|
+
keyListener.dispose();
|
|
116
|
+
keyListener = null;
|
|
117
|
+
}
|
|
118
|
+
terminal.write(ansi.cursor.show);
|
|
119
|
+
terminal.write('\n');
|
|
120
|
+
terminal.listen();
|
|
121
|
+
resolve();
|
|
122
|
+
return;
|
|
123
|
+
case 'ArrowUp':
|
|
124
|
+
if (currentLine > 0) {
|
|
125
|
+
currentLine--;
|
|
126
|
+
render();
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case 'ArrowDown':
|
|
130
|
+
case 'Enter':
|
|
131
|
+
currentLine++;
|
|
132
|
+
render();
|
|
133
|
+
break;
|
|
134
|
+
case 'PageDown':
|
|
135
|
+
case ' ':
|
|
136
|
+
currentLine = Math.min(currentLine + displayRows, Math.max(0, lines.length - displayRows));
|
|
137
|
+
render();
|
|
138
|
+
break;
|
|
139
|
+
case 'PageUp':
|
|
140
|
+
case 'b':
|
|
141
|
+
case 'B':
|
|
142
|
+
currentLine = Math.max(0, currentLine - displayRows);
|
|
143
|
+
render();
|
|
144
|
+
break;
|
|
145
|
+
case 'Home':
|
|
146
|
+
case 'g':
|
|
147
|
+
currentLine = 0;
|
|
148
|
+
render();
|
|
149
|
+
break;
|
|
150
|
+
case 'End':
|
|
151
|
+
case 'G':
|
|
152
|
+
currentLine = Math.max(0, lines.length - displayRows);
|
|
153
|
+
render();
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (keyListener) {
|
|
162
|
+
keyListener.dispose();
|
|
163
|
+
}
|
|
164
|
+
terminal.write(ansi.cursor.show);
|
|
165
|
+
terminal.write('\n');
|
|
166
|
+
terminal.listen();
|
|
167
|
+
await writelnStderr(process, terminal, `less: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=less.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"less.js","sourceRoot":"","sources":["../../src/commands/less.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,IAAI,MAAM,uBAAuB,CAAA;AAIxC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAY,EAAE,QAAkB;IAC5E,OAAO,IAAI,eAAe,CAAC;QACzB,OAAO,EAAE,MAAM;QACf,WAAW,EAAE,kCAAkC;QAC/C,MAAM;QACN,KAAK;QACL,QAAQ;QACR,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE;YAC3E,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,8BAA8B,EAAE;SAChI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AAA;YACV,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,WAAW,EAAE,CAAC;oBACf,WAA2B,CAAC,OAAO,EAAE,CAAA;gBACxC,CAAC;gBACD,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBAChC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACpB,QAAQ,CAAC,MAAM,EAAE,CAAA;gBACjB,MAAM,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAA;gBAC3G,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ln.d.ts","sourceRoot":"","sources":["../../src/commands/ln.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAG/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,CAoG/F"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { TerminalCommand } from '../shared/terminal-command.js';
|
|
4
|
+
import { writelnStdout, writelnStderr } from '../shared/helpers.js';
|
|
5
|
+
export function createCommand(kernel, shell, terminal) {
|
|
6
|
+
return new TerminalCommand({
|
|
7
|
+
command: 'ln',
|
|
8
|
+
description: 'Create links between files',
|
|
9
|
+
kernel,
|
|
10
|
+
shell,
|
|
11
|
+
terminal,
|
|
12
|
+
options: [
|
|
13
|
+
{ name: 'help', type: Boolean, description: kernel.i18n.t('Display help') },
|
|
14
|
+
{ name: 'symbolic', type: Boolean, alias: 's', description: 'Create symbolic links instead of hard links' },
|
|
15
|
+
{ name: 'force', type: Boolean, alias: 'f', description: 'Remove existing destination files' },
|
|
16
|
+
{ name: 'verbose', type: Boolean, alias: 'v', description: 'Print name of each linked file' },
|
|
17
|
+
{ name: 'args', type: String, multiple: true, defaultOption: true, description: 'The target and optional link name' }
|
|
18
|
+
],
|
|
19
|
+
run: async (argv, process) => {
|
|
20
|
+
const args = argv.args || [];
|
|
21
|
+
const symbolic = argv.symbolic || false;
|
|
22
|
+
const force = argv.force || false;
|
|
23
|
+
const verbose = argv.verbose || false;
|
|
24
|
+
if (args.length === 0) {
|
|
25
|
+
await writelnStderr(process, terminal, chalk.red('ln: missing file operand'));
|
|
26
|
+
await writelnStderr(process, terminal, 'Try \'ln --help\' for more information.');
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
const target = args[0];
|
|
30
|
+
if (!target) {
|
|
31
|
+
await writelnStderr(process, terminal, chalk.red('ln: missing file operand'));
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
34
|
+
const targetPath = path.resolve(shell.cwd, target);
|
|
35
|
+
let targetStats;
|
|
36
|
+
try {
|
|
37
|
+
targetStats = await shell.context.fs.promises.stat(targetPath);
|
|
38
|
+
if (!targetStats.isFile() && !targetStats.isDirectory()) {
|
|
39
|
+
await writelnStderr(process, terminal, chalk.red(`ln: ${target}: invalid target`));
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
if (!symbolic && targetStats.isDirectory()) {
|
|
43
|
+
await writelnStderr(process, terminal, chalk.red(`ln: ${target}: hard link not allowed for directory`));
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
await writelnStderr(process, terminal, chalk.red(`ln: ${target}: No such file or directory`));
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
let linkName;
|
|
52
|
+
if (args.length === 1) {
|
|
53
|
+
linkName = path.join(shell.cwd, path.basename(target));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const linkNameInput = args[1];
|
|
57
|
+
if (!linkNameInput) {
|
|
58
|
+
await writelnStderr(process, terminal, chalk.red('ln: missing link name'));
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
const linkNamePath = path.resolve(shell.cwd, linkNameInput);
|
|
62
|
+
const linkNameStats = await shell.context.fs.promises.stat(linkNamePath).catch(() => null);
|
|
63
|
+
if (linkNameStats?.isDirectory()) {
|
|
64
|
+
linkName = path.join(linkNamePath, path.basename(target));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
linkName = linkNamePath;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const linkExists = await shell.context.fs.promises.stat(linkName).catch(() => null);
|
|
72
|
+
if (linkExists) {
|
|
73
|
+
if (force) {
|
|
74
|
+
if (linkExists.isDirectory()) {
|
|
75
|
+
await shell.context.fs.promises.rmdir(linkName);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
await shell.context.fs.promises.unlink(linkName);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
await writelnStderr(process, terminal, chalk.red(`ln: ${linkName}: File exists`));
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (symbolic) {
|
|
87
|
+
await shell.context.fs.promises.symlink(targetPath, linkName);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
await shell.context.fs.promises.link(targetPath, linkName);
|
|
91
|
+
}
|
|
92
|
+
if (verbose) {
|
|
93
|
+
await writelnStdout(process, terminal, linkName);
|
|
94
|
+
}
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
await writelnStderr(process, terminal, chalk.red(`ln: ${error.message}`));
|
|
99
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AC,CAAA;YACV,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,OAAQ,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;gBACpF,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../src/commands/ls.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAG/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../src/commands/ls.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAG/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,eAAe,CA6N/F"}
|