command-stream 0.8.2 → 0.9.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.
- package/js/examples/01-basic-streaming.mjs +14 -0
- package/js/examples/02-async-iterator.mjs +9 -0
- package/js/examples/03-file-and-console.mjs +16 -0
- package/js/examples/04-claude-jq-pipe.mjs +16 -0
- package/js/examples/CI-DEBUG-README.md +138 -0
- package/js/examples/README-examples.mjs +111 -0
- package/js/examples/README.md +345 -0
- package/js/examples/STREAMING_INTERFACES_SUMMARY.md +116 -0
- package/js/examples/add-test-timeouts.js +107 -0
- package/js/examples/ansi-default-preserved.mjs +11 -0
- package/js/examples/ansi-global-config.mjs +12 -0
- package/js/examples/ansi-reset-default.mjs +12 -0
- package/js/examples/ansi-strip-utils.mjs +12 -0
- package/js/examples/baseline-child-process.mjs +23 -0
- package/js/examples/baseline-claude-test.mjs +47 -0
- package/js/examples/baseline-working.mjs +34 -0
- package/js/examples/capture-mirror-comparison.mjs +23 -0
- package/js/examples/capture-mirror-default.mjs +11 -0
- package/js/examples/capture-mirror-performance.mjs +16 -0
- package/js/examples/capture-mirror-show-only.mjs +16 -0
- package/js/examples/capture-mirror-silent-processing.mjs +16 -0
- package/js/examples/ci-debug-baseline-vs-library.mjs +265 -0
- package/js/examples/ci-debug-es-module-loading.mjs +184 -0
- package/js/examples/ci-debug-signal-handling.mjs +225 -0
- package/js/examples/ci-debug-stdout-buffering.mjs +94 -0
- package/js/examples/ci-debug-test-timeouts.mjs +259 -0
- package/js/examples/claude-exact-file-output.mjs +20 -0
- package/js/examples/claude-exact-jq.mjs +13 -0
- package/js/examples/claude-exact-streaming.mjs +13 -0
- package/js/examples/claude-jq-pipeline.mjs +13 -0
- package/js/examples/claude-json-stream.mjs +39 -0
- package/js/examples/claude-streaming-basic.mjs +99 -0
- package/js/examples/claude-streaming-demo.mjs +126 -0
- package/js/examples/claude-streaming-final.mjs +20 -0
- package/js/examples/cleanup-verification-test.mjs +115 -0
- package/js/examples/colors-buffer-processing.mjs +14 -0
- package/js/examples/colors-default-preserved.mjs +15 -0
- package/js/examples/colors-per-command-config.mjs +15 -0
- package/js/examples/colors-strip-ansi.mjs +13 -0
- package/js/examples/commandstream-jq.mjs +29 -0
- package/js/examples/commandstream-working.mjs +23 -0
- package/js/examples/comprehensive-streams-demo.mjs +121 -0
- package/js/examples/ctrl-c-concurrent-processes.mjs +20 -0
- package/js/examples/ctrl-c-long-running-command.mjs +20 -0
- package/js/examples/ctrl-c-real-system-command.mjs +17 -0
- package/js/examples/ctrl-c-sleep-command.mjs +17 -0
- package/js/examples/ctrl-c-stdin-forwarding.mjs +20 -0
- package/js/examples/ctrl-c-virtual-command.mjs +17 -0
- package/js/examples/debug-already-started.mjs +20 -0
- package/js/examples/debug-ansi-processing.mjs +42 -0
- package/js/examples/debug-basic-streaming.mjs +44 -0
- package/js/examples/debug-buildshellcommand.mjs +82 -0
- package/js/examples/debug-child-process.mjs +43 -0
- package/js/examples/debug-child-state.mjs +55 -0
- package/js/examples/debug-chunking.mjs +38 -0
- package/js/examples/debug-command-parsing.mjs +61 -0
- package/js/examples/debug-complete-consolidation.mjs +97 -0
- package/js/examples/debug-echo-args.mjs +22 -0
- package/js/examples/debug-emit-timing.mjs +28 -0
- package/js/examples/debug-end-event.mjs +56 -0
- package/js/examples/debug-errexit.mjs +16 -0
- package/js/examples/debug-event-emission.mjs +40 -0
- package/js/examples/debug-event-timing.mjs +67 -0
- package/js/examples/debug-event-vs-result.mjs +30 -0
- package/js/examples/debug-exact-command.mjs +28 -0
- package/js/examples/debug-exact-test-scenario.mjs +44 -0
- package/js/examples/debug-execution-path.mjs +27 -0
- package/js/examples/debug-exit-command.mjs +38 -0
- package/js/examples/debug-exit-virtual.mjs +54 -0
- package/js/examples/debug-finish-consolidation.mjs +44 -0
- package/js/examples/debug-force-cleanup.mjs +47 -0
- package/js/examples/debug-getter-basic.mjs +13 -0
- package/js/examples/debug-getter-direct.mjs +23 -0
- package/js/examples/debug-getter-internals.mjs +61 -0
- package/js/examples/debug-handler-detection.mjs +65 -0
- package/js/examples/debug-idempotent-finish.mjs +54 -0
- package/js/examples/debug-idempotent-kill.mjs +58 -0
- package/js/examples/debug-interpolation-individual.mjs +88 -0
- package/js/examples/debug-interpolation-issue.mjs +101 -0
- package/js/examples/debug-jq-streaming.mjs +57 -0
- package/js/examples/debug-jq-tty-colors.mjs +168 -0
- package/js/examples/debug-kill-cleanup.mjs +56 -0
- package/js/examples/debug-kill-method.mjs +33 -0
- package/js/examples/debug-listener-interference.mjs +38 -0
- package/js/examples/debug-listener-lifecycle.mjs +50 -0
- package/js/examples/debug-listener-timing.mjs +62 -0
- package/js/examples/debug-listeners-property.mjs +34 -0
- package/js/examples/debug-map-methods.mjs +39 -0
- package/js/examples/debug-not-awaited-cleanup.mjs +106 -0
- package/js/examples/debug-off-method.mjs +28 -0
- package/js/examples/debug-option-merging.mjs +17 -0
- package/js/examples/debug-options.mjs +36 -0
- package/js/examples/debug-output.mjs +25 -0
- package/js/examples/debug-pattern-matching.mjs +69 -0
- package/js/examples/debug-pipeline-cat.mjs +28 -0
- package/js/examples/debug-pipeline-cleanup.mjs +71 -0
- package/js/examples/debug-pipeline-error-detailed.mjs +78 -0
- package/js/examples/debug-pipeline-error.mjs +65 -0
- package/js/examples/debug-pipeline-issue.mjs +26 -0
- package/js/examples/debug-pipeline-method.mjs +22 -0
- package/js/examples/debug-pipeline-stream.mjs +66 -0
- package/js/examples/debug-pipeline.mjs +14 -0
- package/js/examples/debug-process-exit-trace.mjs +41 -0
- package/js/examples/debug-process-path.mjs +38 -0
- package/js/examples/debug-property-check.mjs +29 -0
- package/js/examples/debug-resource-cleanup.mjs +83 -0
- package/js/examples/debug-shell-args.mjs +103 -0
- package/js/examples/debug-sigint-child-handler.mjs +44 -0
- package/js/examples/debug-sigint-forwarding.mjs +61 -0
- package/js/examples/debug-sigint-handler-install.mjs +79 -0
- package/js/examples/debug-sigint-handler-order.mjs +85 -0
- package/js/examples/debug-sigint-listeners.mjs +48 -0
- package/js/examples/debug-sigint-start-pattern.mjs +62 -0
- package/js/examples/debug-sigint-timer.mjs +40 -0
- package/js/examples/debug-simple-command.mjs +49 -0
- package/js/examples/debug-simple-getter.mjs +30 -0
- package/js/examples/debug-simple.mjs +39 -0
- package/js/examples/debug-simplified-finished.mjs +102 -0
- package/js/examples/debug-stack-overflow.mjs +25 -0
- package/js/examples/debug-stdin-simple.mjs +28 -0
- package/js/examples/debug-stdin.mjs +28 -0
- package/js/examples/debug-stream-emitter-isolated.mjs +45 -0
- package/js/examples/debug-stream-emitter.mjs +25 -0
- package/js/examples/debug-stream-events.mjs +70 -0
- package/js/examples/debug-stream-generator.mjs +23 -0
- package/js/examples/debug-stream-getter-issue.mjs +37 -0
- package/js/examples/debug-stream-getter.mjs +19 -0
- package/js/examples/debug-stream-internals.mjs +64 -0
- package/js/examples/debug-stream-method.mjs +46 -0
- package/js/examples/debug-stream-object.mjs +58 -0
- package/js/examples/debug-stream-properties.mjs +37 -0
- package/js/examples/debug-stream-timing.mjs +28 -0
- package/js/examples/debug-streaming.mjs +24 -0
- package/js/examples/debug-test-isolation.mjs +54 -0
- package/js/examples/debug-test-state.mjs +27 -0
- package/js/examples/debug-user-sigint.mjs +19 -0
- package/js/examples/debug-virtual-disable.mjs +21 -0
- package/js/examples/debug-virtual-vs-real.mjs +68 -0
- package/js/examples/debug-with-trace.mjs +23 -0
- package/js/examples/debug_parent_stream.mjs +22 -0
- package/js/examples/emulate-claude-stream.mjs +30 -0
- package/js/examples/emulated-streaming-direct.mjs +22 -0
- package/js/examples/emulated-streaming-jq-pipe.mjs +22 -0
- package/js/examples/emulated-streaming-sh-pipe.mjs +23 -0
- package/js/examples/events-build-process.mjs +73 -0
- package/js/examples/events-concurrent-streams.mjs +51 -0
- package/js/examples/events-error-handling.mjs +59 -0
- package/js/examples/events-file-monitoring.mjs +66 -0
- package/js/examples/events-interactive-simulation.mjs +69 -0
- package/js/examples/events-log-processing.mjs +72 -0
- package/js/examples/events-network-monitoring.mjs +68 -0
- package/js/examples/events-ping-basic.mjs +37 -0
- package/js/examples/events-progress-tracking.mjs +55 -0
- package/js/examples/events-stdin-input.mjs +34 -0
- package/js/examples/example-ansi-ls.mjs +39 -0
- package/js/examples/example-top.mjs +27 -0
- package/js/examples/final-ping-stdin-proof.mjs +88 -0
- package/js/examples/final-test-shell-operators.mjs +123 -0
- package/js/examples/final-working-examples.mjs +162 -0
- package/js/examples/gh-auth-test.mjs +103 -0
- package/js/examples/gh-delete-hang-test.mjs +79 -0
- package/js/examples/gh-gist-creation-test.mjs +276 -0
- package/js/examples/gh-gist-minimal-test.mjs +89 -0
- package/js/examples/gh-hang-exact-original.mjs +83 -0
- package/js/examples/gh-hang-reproduction.mjs +151 -0
- package/js/examples/gh-hang-test-with-redirect.mjs +45 -0
- package/js/examples/gh-hang-test-without-redirect.mjs +43 -0
- package/js/examples/gh-minimal-hang-check.mjs +33 -0
- package/js/examples/gh-operations-with-cd.mjs +187 -0
- package/js/examples/gh-output-test.mjs +102 -0
- package/js/examples/gh-reproduce-hang.mjs +41 -0
- package/js/examples/git-operations-with-cd.mjs +186 -0
- package/js/examples/interactive-math-calc.mjs +45 -0
- package/js/examples/interactive-top-fixed.mjs +25 -0
- package/js/examples/interactive-top-improved.mjs +72 -0
- package/js/examples/interactive-top-pty-logging.mjs +69 -0
- package/js/examples/interactive-top-pty.mjs +27 -0
- package/js/examples/interactive-top-with-logging.mjs +56 -0
- package/js/examples/interactive-top.mjs +29 -0
- package/js/examples/jq-color-demo.mjs +53 -0
- package/js/examples/jq-colors-streaming.mjs +42 -0
- package/js/examples/manual-ctrl-c-test.mjs +50 -0
- package/js/examples/methods-multiple-options.mjs +25 -0
- package/js/examples/methods-run-basic.mjs +10 -0
- package/js/examples/methods-start-basic.mjs +10 -0
- package/js/examples/node-compat-data-events.mjs +36 -0
- package/js/examples/node-compat-readable-event.mjs +29 -0
- package/js/examples/node-compat-small-buffer.mjs +33 -0
- package/js/examples/options-capture-false.mjs +12 -0
- package/js/examples/options-combined-settings.mjs +13 -0
- package/js/examples/options-custom-input.mjs +16 -0
- package/js/examples/options-default-behavior.mjs +10 -0
- package/js/examples/options-maximum-performance.mjs +15 -0
- package/js/examples/options-mirror-false.mjs +10 -0
- package/js/examples/options-performance-mode.mjs +13 -0
- package/js/examples/options-performance-optimization.mjs +14 -0
- package/js/examples/options-run-alias-demo.mjs +15 -0
- package/js/examples/options-run-alias.mjs +10 -0
- package/js/examples/options-silent-execution.mjs +14 -0
- package/js/examples/options-streaming-capture.mjs +24 -0
- package/js/examples/options-streaming-multiple.mjs +35 -0
- package/js/examples/options-streaming-silent.mjs +21 -0
- package/js/examples/options-streaming-stdin.mjs +21 -0
- package/js/examples/ping-streaming-filtered.mjs +22 -0
- package/js/examples/ping-streaming-interruptible.mjs +47 -0
- package/js/examples/ping-streaming-silent.mjs +24 -0
- package/js/examples/ping-streaming-simple.mjs +13 -0
- package/js/examples/ping-streaming-statistics.mjs +49 -0
- package/js/examples/ping-streaming-timestamps.mjs +22 -0
- package/js/examples/ping-streaming.mjs +48 -0
- package/js/examples/prove-ping-stdin-limitation.mjs +94 -0
- package/js/examples/readme-example.mjs +39 -0
- package/js/examples/realtime-json-stream.mjs +143 -0
- package/js/examples/reliable-stdin-commands.mjs +135 -0
- package/js/examples/reproduce-issue-135-v2.mjs +15 -0
- package/js/examples/reproduce-issue-135.mjs +17 -0
- package/js/examples/shell-cd-behavior.mjs +88 -0
- package/js/examples/sigint-forwarding-test.mjs +60 -0
- package/js/examples/sigint-handler-test.mjs +72 -0
- package/js/examples/simple-async-test.mjs +49 -0
- package/js/examples/simple-claude-test.mjs +17 -0
- package/js/examples/simple-event-test.mjs +33 -0
- package/js/examples/simple-jq-streaming.mjs +48 -0
- package/js/examples/simple-stream-demo.mjs +35 -0
- package/js/examples/simple-test-sleep.js +30 -0
- package/js/examples/simple-working-stdin.mjs +30 -0
- package/js/examples/streaming-behavior-test.mjs +116 -0
- package/js/examples/streaming-direct-command.mjs +21 -0
- package/js/examples/streaming-filtered-output.mjs +33 -0
- package/js/examples/streaming-grep-pipeline.mjs +21 -0
- package/js/examples/streaming-interactive-stdin.mjs +24 -0
- package/js/examples/streaming-jq-pipeline.mjs +23 -0
- package/js/examples/streaming-multistage-pipeline.mjs +23 -0
- package/js/examples/streaming-pipes-event-pattern.mjs +27 -0
- package/js/examples/streaming-pipes-multistage.mjs +22 -0
- package/js/examples/streaming-pipes-realtime-jq.mjs +23 -0
- package/js/examples/streaming-progress-tracking.mjs +34 -0
- package/js/examples/streaming-reusable-configs.mjs +52 -0
- package/js/examples/streaming-silent-capture.mjs +20 -0
- package/js/examples/streaming-test-simple.mjs +70 -0
- package/js/examples/streaming-virtual-pipeline.mjs +18 -0
- package/js/examples/syntax-basic-comparison.mjs +31 -0
- package/js/examples/syntax-basic-options.mjs +12 -0
- package/js/examples/syntax-combined-options.mjs +19 -0
- package/js/examples/syntax-command-chaining.mjs +12 -0
- package/js/examples/syntax-custom-directory.mjs +10 -0
- package/js/examples/syntax-custom-environment.mjs +13 -0
- package/js/examples/syntax-custom-stdin.mjs +10 -0
- package/js/examples/syntax-mixed-regular.mjs +11 -0
- package/js/examples/syntax-mixed-usage.mjs +15 -0
- package/js/examples/syntax-multiple-listeners.mjs +87 -0
- package/js/examples/syntax-piping-comparison.mjs +32 -0
- package/js/examples/syntax-reusable-config.mjs +16 -0
- package/js/examples/syntax-reusable-configs.mjs +21 -0
- package/js/examples/syntax-silent-operations.mjs +10 -0
- package/js/examples/syntax-stdin-option.mjs +12 -0
- package/js/examples/temp-sigint-test.mjs +21 -0
- package/js/examples/test-actual-buildshell.mjs +44 -0
- package/js/examples/test-async-streams-working.mjs +102 -0
- package/js/examples/test-async-streams.mjs +90 -0
- package/js/examples/test-auth-parse.mjs +74 -0
- package/js/examples/test-auto-quoting.mjs +57 -0
- package/js/examples/test-auto-start-fix.mjs +95 -0
- package/js/examples/test-baseline-sigint.mjs +38 -0
- package/js/examples/test-buffer-behavior.mjs +39 -0
- package/js/examples/test-buffers-simple.mjs +35 -0
- package/js/examples/test-bun-specific-issue.mjs +106 -0
- package/js/examples/test-bun-streaming.mjs +81 -0
- package/js/examples/test-cat-direct.mjs +41 -0
- package/js/examples/test-cat-pipe.mjs +34 -0
- package/js/examples/test-cd-behavior.mjs +42 -0
- package/js/examples/test-child-process-timing.mjs +53 -0
- package/js/examples/test-child-sigint-handler.mjs +62 -0
- package/js/examples/test-cleanup-simple.mjs +21 -0
- package/js/examples/test-comprehensive-tracing.mjs +58 -0
- package/js/examples/test-correct-space-handling.mjs +46 -0
- package/js/examples/test-ctrl-c-debug.mjs +44 -0
- package/js/examples/test-ctrl-c-inherit.mjs +30 -0
- package/js/examples/test-ctrl-c-sleep.mjs +31 -0
- package/js/examples/test-ctrl-c.mjs +17 -0
- package/js/examples/test-debug-new-options.mjs +55 -0
- package/js/examples/test-debug-pty.mjs +49 -0
- package/js/examples/test-debug-tee.mjs +38 -0
- package/js/examples/test-debug.mjs +25 -0
- package/js/examples/test-direct-jq.mjs +47 -0
- package/js/examples/test-direct-pipe-reading.mjs +119 -0
- package/js/examples/test-direct-pipe.sh +28 -0
- package/js/examples/test-double-quoting-prevention.mjs +138 -0
- package/js/examples/test-edge-cases-quoting.mjs +89 -0
- package/js/examples/test-events.mjs +37 -0
- package/js/examples/test-explicit-stdio.mjs +51 -0
- package/js/examples/test-final-streaming.mjs +71 -0
- package/js/examples/test-fix.mjs +71 -0
- package/js/examples/test-incremental-streaming.mjs +46 -0
- package/js/examples/test-individual-spawn.mjs +35 -0
- package/js/examples/test-inherit-stdout-not-stdin.mjs +133 -0
- package/js/examples/test-injection-protection.mjs +77 -0
- package/js/examples/test-interactive-streaming.mjs +140 -0
- package/js/examples/test-interactive-top.md +24 -0
- package/js/examples/test-interactive.mjs +17 -0
- package/js/examples/test-interpolation.mjs +14 -0
- package/js/examples/test-interrupt.mjs +40 -0
- package/js/examples/test-issue-135-comprehensive.mjs +41 -0
- package/js/examples/test-issue12-detailed.mjs +89 -0
- package/js/examples/test-issue12-exact.mjs +33 -0
- package/js/examples/test-jq-color.mjs +57 -0
- package/js/examples/test-jq-colors.mjs +41 -0
- package/js/examples/test-jq-compact.mjs +33 -0
- package/js/examples/test-jq-native.sh +10 -0
- package/js/examples/test-jq-pipeline-behavior.mjs +80 -0
- package/js/examples/test-jq-realtime.mjs +40 -0
- package/js/examples/test-manual-start.mjs +54 -0
- package/js/examples/test-mixed-quoting.mjs +88 -0
- package/js/examples/test-multi-stream.mjs +50 -0
- package/js/examples/test-multistage-debug.mjs +44 -0
- package/js/examples/test-native-spawn-vs-command-stream.mjs +154 -0
- package/js/examples/test-no-parse-pipeline.mjs +33 -0
- package/js/examples/test-non-virtual.mjs +52 -0
- package/js/examples/test-operators.mjs +53 -0
- package/js/examples/test-parent-continues.mjs +44 -0
- package/js/examples/test-path-interpolation.mjs +86 -0
- package/js/examples/test-ping-kill-and-stdin.mjs +98 -0
- package/js/examples/test-ping.mjs +12 -0
- package/js/examples/test-pty-spawn.mjs +101 -0
- package/js/examples/test-pty.mjs +38 -0
- package/js/examples/test-quote-behavior-summary.mjs +110 -0
- package/js/examples/test-quote-edge-cases.mjs +69 -0
- package/js/examples/test-quote-parsing.mjs +23 -0
- package/js/examples/test-raw-function.mjs +153 -0
- package/js/examples/test-raw-streaming.mjs +47 -0
- package/js/examples/test-readme-examples.mjs +142 -0
- package/js/examples/test-real-cat.mjs +28 -0
- package/js/examples/test-real-commands.mjs +21 -0
- package/js/examples/test-real-shell.mjs +31 -0
- package/js/examples/test-real-stdin-commands.mjs +160 -0
- package/js/examples/test-runner-batched.mjs +98 -0
- package/js/examples/test-runner-simple.mjs +80 -0
- package/js/examples/test-runner.mjs +67 -0
- package/js/examples/test-scope-parse.mjs +31 -0
- package/js/examples/test-sh-pipeline.mjs +24 -0
- package/js/examples/test-shell-detection.mjs +71 -0
- package/js/examples/test-shell-parser.mjs +37 -0
- package/js/examples/test-sigint-behavior.mjs +241 -0
- package/js/examples/test-sigint-handling.sh +14 -0
- package/js/examples/test-simple-pipe.mjs +12 -0
- package/js/examples/test-simple-streaming.mjs +32 -0
- package/js/examples/test-sleep-stdin.js +27 -0
- package/js/examples/test-sleep.mjs +56 -0
- package/js/examples/test-smart-quoting.mjs +180 -0
- package/js/examples/test-spaces-in-path.mjs +48 -0
- package/js/examples/test-special-chars-quoting.mjs +54 -0
- package/js/examples/test-stdin-after-start.mjs +39 -0
- package/js/examples/test-stdin-simple.mjs +67 -0
- package/js/examples/test-stdin-timing.mjs +74 -0
- package/js/examples/test-stdio-combinations.mjs +124 -0
- package/js/examples/test-stream-access.mjs +84 -0
- package/js/examples/test-stream-cleanup.mjs +27 -0
- package/js/examples/test-stream-readers.mjs +152 -0
- package/js/examples/test-streaming-final.mjs +57 -0
- package/js/examples/test-streaming-interfaces.mjs +141 -0
- package/js/examples/test-streaming-timing.mjs +27 -0
- package/js/examples/test-streaming.mjs +32 -0
- package/js/examples/test-streams-stdin-comprehensive.mjs +134 -0
- package/js/examples/test-streams-stdin-ctrl-c.mjs +96 -0
- package/js/examples/test-template-literal.mjs +26 -0
- package/js/examples/test-template-vs-interpolation.mjs +49 -0
- package/js/examples/test-timing.mjs +41 -0
- package/js/examples/test-top-inherit-stdout-stdin-control.mjs +123 -0
- package/js/examples/test-top-quit-stdin.mjs +118 -0
- package/js/examples/test-trace-option.mjs +21 -0
- package/js/examples/test-user-double-quotes.mjs +36 -0
- package/js/examples/test-user-single-quotes.mjs +36 -0
- package/js/examples/test-verbose.mjs +18 -0
- package/js/examples/test-verbose2.mjs +32 -0
- package/js/examples/test-virtual-streaming.mjs +125 -0
- package/js/examples/test-waiting-command.mjs +52 -0
- package/js/examples/test-waiting-commands.mjs +83 -0
- package/js/examples/test-watch-mode.mjs +104 -0
- package/js/examples/test-yes-cancellation.mjs +26 -0
- package/js/examples/test-yes-detailed.mjs +58 -0
- package/js/examples/test-yes-trace.mjs +28 -0
- package/js/examples/trace-abort-controller.mjs +30 -0
- package/js/examples/trace-error-handling.mjs +22 -0
- package/js/examples/trace-pipeline-command.mjs +22 -0
- package/js/examples/trace-signal-handling.mjs +35 -0
- package/js/examples/trace-simple-command.mjs +18 -0
- package/js/examples/trace-stderr-output.mjs +22 -0
- package/js/examples/verify-fix-both-runtimes.mjs +73 -0
- package/js/examples/verify-issue12-fixed.mjs +78 -0
- package/js/examples/which-command-common-commands.mjs +19 -0
- package/js/examples/which-command-gh-test.mjs +23 -0
- package/js/examples/which-command-nonexistent.mjs +20 -0
- package/js/examples/which-command-system-comparison.mjs +28 -0
- package/js/examples/working-example.mjs +13 -0
- package/js/examples/working-stdin-examples.mjs +138 -0
- package/js/examples/working-streaming-demo.mjs +49 -0
- package/{src → js/src}/$.mjs +20 -4
- package/{src → js/src}/$.utils.mjs +14 -2
- package/js/tests/$.features.test.mjs +283 -0
- package/js/tests/$.test.mjs +935 -0
- package/js/tests/builtin-commands.test.mjs +387 -0
- package/js/tests/bun-shell-path-fix.test.mjs +115 -0
- package/js/tests/bun.features.test.mjs +189 -0
- package/js/tests/cd-virtual-command.test.mjs +622 -0
- package/js/tests/cleanup-verification.test.mjs +127 -0
- package/js/tests/ctrl-c-baseline.test.mjs +207 -0
- package/js/tests/ctrl-c-basic.test.mjs +220 -0
- package/js/tests/ctrl-c-library.test.mjs +197 -0
- package/js/tests/ctrl-c-signal.test.mjs +915 -0
- package/js/tests/examples.test.mjs +252 -0
- package/js/tests/execa.features.test.mjs +198 -0
- package/js/tests/gh-commands.test.mjs +164 -0
- package/js/tests/gh-gist-operations.test.mjs +221 -0
- package/js/tests/git-gh-cd.test.mjs +466 -0
- package/js/tests/interactive-option.test.mjs +114 -0
- package/js/tests/interactive-streaming.test.mjs +307 -0
- package/js/tests/issue-135-final.test.mjs +58 -0
- package/js/tests/jq-color-behavior.test.mjs +140 -0
- package/js/tests/jq.test.mjs +318 -0
- package/js/tests/options-examples.test.mjs +106 -0
- package/js/tests/options-syntax.test.mjs +112 -0
- package/js/tests/path-interpolation.test.mjs +412 -0
- package/js/tests/pipe.test.mjs +291 -0
- package/js/tests/raw-function.test.mjs +266 -0
- package/js/tests/readme-examples.test.mjs +427 -0
- package/js/tests/resource-cleanup-internals.test.mjs +669 -0
- package/js/tests/shell-settings.test.mjs +279 -0
- package/js/tests/sigint-cleanup-isolated.test.mjs +151 -0
- package/js/tests/sigint-cleanup.test.mjs +118 -0
- package/js/tests/start-run-edge-cases.test.mjs +152 -0
- package/js/tests/start-run-options.test.mjs +181 -0
- package/js/tests/stderr-output-handling.test.mjs +279 -0
- package/js/tests/streaming-interfaces.test.mjs +194 -0
- package/js/tests/sync.test.mjs +297 -0
- package/js/tests/system-pipe.test.mjs +226 -0
- package/js/tests/test-cleanup.mjs +200 -0
- package/js/tests/test-helper-fixed.mjs +148 -0
- package/js/tests/test-helper-v2.mjs +118 -0
- package/js/tests/test-helper.mjs +171 -0
- package/js/tests/test-sigint-child.js +15 -0
- package/js/tests/text-method.test.mjs +225 -0
- package/js/tests/virtual.test.mjs +364 -0
- package/js/tests/yes-command-cleanup.test.mjs +208 -0
- package/js/tests/zx.features.test.mjs +233 -0
- package/package.json +13 -12
- package/rust/Cargo.lock +947 -0
- package/rust/Cargo.toml +47 -0
- package/rust/src/commands/basename.rs +69 -0
- package/rust/src/commands/cat.rs +123 -0
- package/rust/src/commands/cd.rs +67 -0
- package/rust/src/commands/cp.rs +187 -0
- package/rust/src/commands/dirname.rs +57 -0
- package/rust/src/commands/echo.rs +73 -0
- package/rust/src/commands/env.rs +33 -0
- package/rust/src/commands/exit.rs +36 -0
- package/rust/src/commands/false.rs +24 -0
- package/rust/src/commands/ls.rs +182 -0
- package/rust/src/commands/mkdir.rs +98 -0
- package/rust/src/commands/mod.rs +200 -0
- package/rust/src/commands/mv.rs +180 -0
- package/rust/src/commands/pwd.rs +28 -0
- package/rust/src/commands/rm.rs +150 -0
- package/rust/src/commands/seq.rs +179 -0
- package/rust/src/commands/sleep.rs +97 -0
- package/rust/src/commands/test.rs +204 -0
- package/rust/src/commands/touch.rs +99 -0
- package/rust/src/commands/true.rs +24 -0
- package/rust/src/commands/which.rs +87 -0
- package/rust/src/commands/yes.rs +99 -0
- package/rust/src/lib.rs +492 -0
- package/rust/src/main.rs +37 -0
- package/rust/src/shell_parser.rs +565 -0
- package/rust/src/utils.rs +335 -0
- package/rust/tests/builtin_commands.rs +549 -0
- package/rust/tests/process_runner.rs +286 -0
- package/rust/tests/shell_parser.rs +296 -0
- package/rust/tests/utils.rs +282 -0
- package/rust/tests/virtual_commands.rs +199 -0
- /package/{src → js/src}/commands/$.basename.mjs +0 -0
- /package/{src → js/src}/commands/$.cat.mjs +0 -0
- /package/{src → js/src}/commands/$.cd.mjs +0 -0
- /package/{src → js/src}/commands/$.cp.mjs +0 -0
- /package/{src → js/src}/commands/$.dirname.mjs +0 -0
- /package/{src → js/src}/commands/$.echo.mjs +0 -0
- /package/{src → js/src}/commands/$.env.mjs +0 -0
- /package/{src → js/src}/commands/$.exit.mjs +0 -0
- /package/{src → js/src}/commands/$.false.mjs +0 -0
- /package/{src → js/src}/commands/$.ls.mjs +0 -0
- /package/{src → js/src}/commands/$.mkdir.mjs +0 -0
- /package/{src → js/src}/commands/$.mv.mjs +0 -0
- /package/{src → js/src}/commands/$.pwd.mjs +0 -0
- /package/{src → js/src}/commands/$.rm.mjs +0 -0
- /package/{src → js/src}/commands/$.seq.mjs +0 -0
- /package/{src → js/src}/commands/$.sleep.mjs +0 -0
- /package/{src → js/src}/commands/$.test.mjs +0 -0
- /package/{src → js/src}/commands/$.touch.mjs +0 -0
- /package/{src → js/src}/commands/$.true.mjs +0 -0
- /package/{src → js/src}/commands/$.which.mjs +0 -0
- /package/{src → js/src}/commands/$.yes.mjs +0 -0
- /package/{src → js/src}/shell-parser.mjs +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $, shell, enableVirtualCommands } from '../src/$.mjs';
|
|
4
|
+
import { mkdtempSync, rmSync } from 'fs';
|
|
5
|
+
import { tmpdir } from 'os';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
|
|
8
|
+
// Enable virtual commands including cd
|
|
9
|
+
enableVirtualCommands();
|
|
10
|
+
shell.verbose(true);
|
|
11
|
+
|
|
12
|
+
console.log('=== Git Operations with cd Virtual Command Examples ===\n');
|
|
13
|
+
|
|
14
|
+
async function example1_BasicGitWorkflow() {
|
|
15
|
+
console.log('Example 1: Basic Git Workflow with cd\n');
|
|
16
|
+
|
|
17
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'git-example-'));
|
|
18
|
+
const originalCwd = process.cwd();
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
// Navigate to temp directory and initialize git
|
|
22
|
+
await $`cd ${tempDir}`;
|
|
23
|
+
await $`git init`;
|
|
24
|
+
await $`git config user.email "example@test.com"`;
|
|
25
|
+
await $`git config user.name "Example User"`;
|
|
26
|
+
|
|
27
|
+
// Create and commit a file
|
|
28
|
+
await $`echo "# My Project" > README.md`;
|
|
29
|
+
await $`git add README.md`;
|
|
30
|
+
await $`git commit -m "Initial commit"`;
|
|
31
|
+
|
|
32
|
+
// Show the log
|
|
33
|
+
await $`git log --oneline`;
|
|
34
|
+
|
|
35
|
+
// Return to original directory
|
|
36
|
+
await $`cd ${originalCwd}`;
|
|
37
|
+
|
|
38
|
+
console.log(`✓ Successfully created git repo in ${tempDir}\n`);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Error:', error.message);
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function example2_MultipleTempRepos() {
|
|
47
|
+
console.log('Example 2: Working with Multiple Temp Repositories\n');
|
|
48
|
+
|
|
49
|
+
const repo1 = mkdtempSync(join(tmpdir(), 'repo1-'));
|
|
50
|
+
const repo2 = mkdtempSync(join(tmpdir(), 'repo2-'));
|
|
51
|
+
const originalCwd = process.cwd();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// Initialize first repository
|
|
55
|
+
await $`cd ${repo1} && git init && git config user.email "repo1@test.com"`;
|
|
56
|
+
await $`cd ${repo1} && echo "Repo 1 Content" > file.txt`;
|
|
57
|
+
await $`cd ${repo1} && git add . && git commit -m "Repo 1 commit"`;
|
|
58
|
+
|
|
59
|
+
// Initialize second repository
|
|
60
|
+
await $`cd ${repo2} && git init && git config user.email "repo2@test.com"`;
|
|
61
|
+
await $`cd ${repo2} && echo "Repo 2 Content" > file.txt`;
|
|
62
|
+
await $`cd ${repo2} && git add . && git commit -m "Repo 2 commit"`;
|
|
63
|
+
|
|
64
|
+
// Check both repositories
|
|
65
|
+
console.log('Repo 1 log:');
|
|
66
|
+
await $`cd ${repo1} && git log --oneline`;
|
|
67
|
+
|
|
68
|
+
console.log('\nRepo 2 log:');
|
|
69
|
+
await $`cd ${repo2} && git log --oneline`;
|
|
70
|
+
|
|
71
|
+
await $`cd ${originalCwd}`;
|
|
72
|
+
|
|
73
|
+
console.log('✓ Successfully managed multiple repositories\n');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Error:', error.message);
|
|
76
|
+
} finally {
|
|
77
|
+
rmSync(repo1, { recursive: true, force: true });
|
|
78
|
+
rmSync(repo2, { recursive: true, force: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function example3_BranchingWorkflow() {
|
|
83
|
+
console.log('Example 3: Git Branching Workflow\n');
|
|
84
|
+
|
|
85
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'branch-example-'));
|
|
86
|
+
const originalCwd = process.cwd();
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
// Setup repository
|
|
90
|
+
await $`cd ${tempDir}`;
|
|
91
|
+
await $`git init`;
|
|
92
|
+
await $`git config user.email "branch@test.com"`;
|
|
93
|
+
await $`git config user.name "Branch Example"`;
|
|
94
|
+
|
|
95
|
+
// Create initial commit
|
|
96
|
+
await $`echo "Initial content" > main.txt`;
|
|
97
|
+
await $`git add .`;
|
|
98
|
+
await $`git commit -m "Initial commit"`;
|
|
99
|
+
|
|
100
|
+
// Create and switch to feature branch
|
|
101
|
+
await $`git checkout -b feature-branch`;
|
|
102
|
+
await $`echo "Feature content" > feature.txt`;
|
|
103
|
+
await $`git add .`;
|
|
104
|
+
await $`git commit -m "Add feature"`;
|
|
105
|
+
|
|
106
|
+
// Show branch info
|
|
107
|
+
const currentBranch = await $`git branch --show-current`;
|
|
108
|
+
console.log(`Current branch: ${currentBranch.stdout.trim()}`);
|
|
109
|
+
|
|
110
|
+
// List all branches
|
|
111
|
+
await $`git branch -a`;
|
|
112
|
+
|
|
113
|
+
// Switch back to main/master
|
|
114
|
+
const mainBranch =
|
|
115
|
+
await $`git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "master"`;
|
|
116
|
+
await $`git checkout ${mainBranch.stdout.trim() || 'master'}`;
|
|
117
|
+
|
|
118
|
+
await $`cd ${originalCwd}`;
|
|
119
|
+
|
|
120
|
+
console.log('✓ Branching workflow completed\n');
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('Error:', error.message);
|
|
123
|
+
} finally {
|
|
124
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function example4_GitDiffWorkflow() {
|
|
129
|
+
console.log('Example 4: Git Diff and Status Workflow\n');
|
|
130
|
+
|
|
131
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'diff-example-'));
|
|
132
|
+
const originalCwd = process.cwd();
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
// Use cd chains for all operations
|
|
136
|
+
await $`cd ${tempDir} && git init`;
|
|
137
|
+
await $`cd ${tempDir} && git config user.email "diff@test.com"`;
|
|
138
|
+
await $`cd ${tempDir} && git config user.name "Diff Example"`;
|
|
139
|
+
|
|
140
|
+
// Create initial commit
|
|
141
|
+
await $`cd ${tempDir} && echo "Line 1" > file.txt`;
|
|
142
|
+
await $`cd ${tempDir} && git add . && git commit -m "Initial"`;
|
|
143
|
+
|
|
144
|
+
// Make changes
|
|
145
|
+
await $`cd ${tempDir} && echo "Line 2" >> file.txt`;
|
|
146
|
+
|
|
147
|
+
// Show status
|
|
148
|
+
console.log('Git status:');
|
|
149
|
+
await $`cd ${tempDir} && git status --short`;
|
|
150
|
+
|
|
151
|
+
// Show diff
|
|
152
|
+
console.log('\nGit diff:');
|
|
153
|
+
await $`cd ${tempDir} && git diff`;
|
|
154
|
+
|
|
155
|
+
// Stage and commit changes
|
|
156
|
+
await $`cd ${tempDir} && git add . && git commit -m "Add line 2"`;
|
|
157
|
+
|
|
158
|
+
// Show final log
|
|
159
|
+
await $`cd ${tempDir} && git log --oneline`;
|
|
160
|
+
|
|
161
|
+
await $`cd ${originalCwd}`;
|
|
162
|
+
|
|
163
|
+
console.log('✓ Diff workflow completed\n');
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error('Error:', error.message);
|
|
166
|
+
} finally {
|
|
167
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Run all examples
|
|
172
|
+
async function runExamples() {
|
|
173
|
+
try {
|
|
174
|
+
await example1_BasicGitWorkflow();
|
|
175
|
+
await example2_MultipleTempRepos();
|
|
176
|
+
await example3_BranchingWorkflow();
|
|
177
|
+
await example4_GitDiffWorkflow();
|
|
178
|
+
|
|
179
|
+
console.log('=== All Git Examples Completed Successfully ===');
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error('Failed to run examples:', error);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
runExamples();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Interactive math calculator for testing streaming I/O
|
|
4
|
+
// Reads expressions from stdin, evaluates them, and writes results to stdout
|
|
5
|
+
// Send "exit" or "\q" to quit
|
|
6
|
+
|
|
7
|
+
import readline from 'readline';
|
|
8
|
+
|
|
9
|
+
const rl = readline.createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout,
|
|
12
|
+
terminal: false, // Don't treat as TTY
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
console.log('READY'); // Signal that calculator is ready
|
|
16
|
+
|
|
17
|
+
rl.on('line', (line) => {
|
|
18
|
+
const input = line.trim();
|
|
19
|
+
|
|
20
|
+
// Check for exit commands
|
|
21
|
+
if (input === 'exit' || input === '\\q' || input === 'quit') {
|
|
22
|
+
console.log('GOODBYE');
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Try to evaluate the math expression
|
|
27
|
+
try {
|
|
28
|
+
// Parse simple math expressions like "1+2", "3*4", "10/2", "5-3"
|
|
29
|
+
const result = eval(input); // Using eval for simplicity in test
|
|
30
|
+
console.log(`RESULT: ${result}`);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(`ERROR: Invalid expression: ${input}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Handle stdin close
|
|
37
|
+
rl.on('close', () => {
|
|
38
|
+
process.exit(0);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Ensure output is not buffered
|
|
42
|
+
process.stdout.setDefaultEncoding('utf8');
|
|
43
|
+
if (process.stdout._handle && process.stdout._handle.setBlocking) {
|
|
44
|
+
process.stdout._handle.setBlocking(true);
|
|
45
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $ } from '../src/$.mjs';
|
|
4
|
+
|
|
5
|
+
console.log('=== Fixed Interactive top command ===');
|
|
6
|
+
console.log('This version properly handles:');
|
|
7
|
+
console.log('- Interactive keyboard input (q to quit)');
|
|
8
|
+
console.log('- ANSI colors and formatting');
|
|
9
|
+
console.log('- Terminal control sequences');
|
|
10
|
+
console.log('- Proper stdin/stdout forwarding');
|
|
11
|
+
console.log('\nStarting top... Press q to quit when ready.\n');
|
|
12
|
+
|
|
13
|
+
// Use direct spawn with proper TTY settings for true interactivity
|
|
14
|
+
const proc = $`top`.run({
|
|
15
|
+
stdin: 'inherit', // Forward stdin directly
|
|
16
|
+
mirror: false, // Don't mirror - we want direct terminal output
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Handle process completion
|
|
20
|
+
proc.on('end', (result) => {
|
|
21
|
+
console.log(`\n=== top exited with code: ${result.code} ===`);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Start the process and wait for it to complete
|
|
25
|
+
await proc;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { ProcessRunner } from '../src/$.mjs';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
|
|
6
|
+
console.log('=== Improved Interactive top with command-stream ===');
|
|
7
|
+
console.log('This version fixes TTY handling while using command-stream');
|
|
8
|
+
console.log('- Keyboard input works (q to quit)');
|
|
9
|
+
console.log('- ANSI colors preserved');
|
|
10
|
+
console.log('- Proper terminal interaction');
|
|
11
|
+
console.log('\nChoose your preferred method:\n');
|
|
12
|
+
|
|
13
|
+
console.log('Method 1: Direct Node.js spawn (most reliable)');
|
|
14
|
+
console.log('Method 2: Enhanced ProcessRunner with TTY support');
|
|
15
|
+
console.log('Method 3: Command-stream with proper stdin settings\n');
|
|
16
|
+
|
|
17
|
+
const method = process.argv[2] || '1';
|
|
18
|
+
|
|
19
|
+
switch (method) {
|
|
20
|
+
case '1':
|
|
21
|
+
console.log('Using Method 1: Direct spawn...\n');
|
|
22
|
+
const proc = spawn('top', [], {
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
env: process.env,
|
|
25
|
+
});
|
|
26
|
+
proc.on('close', (code) => {
|
|
27
|
+
console.log(`\n=== top exited with code: ${code} ===`);
|
|
28
|
+
});
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case '2':
|
|
32
|
+
console.log('Using Method 2: Enhanced ProcessRunner...\n');
|
|
33
|
+
const runner = new ProcessRunner(
|
|
34
|
+
{ mode: 'shell', command: 'top' },
|
|
35
|
+
{
|
|
36
|
+
stdin: 'inherit',
|
|
37
|
+
mirror: true,
|
|
38
|
+
capture: false,
|
|
39
|
+
tty: true, // Request TTY mode if supported
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
await runner.start();
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case '3':
|
|
47
|
+
console.log('Using Method 3: Command-stream with settings...\n');
|
|
48
|
+
|
|
49
|
+
// Set raw mode on stdin to forward keystrokes immediately
|
|
50
|
+
if (process.stdin.isTTY) {
|
|
51
|
+
process.stdin.setRawMode(true);
|
|
52
|
+
process.stdin.resume();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const proc3 = spawn('top', [], {
|
|
56
|
+
stdio: [process.stdin, process.stdout, process.stderr],
|
|
57
|
+
env: process.env,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
proc3.on('close', (code) => {
|
|
61
|
+
if (process.stdin.isTTY) {
|
|
62
|
+
process.stdin.setRawMode(false);
|
|
63
|
+
}
|
|
64
|
+
console.log(`\n=== top exited with code: ${code} ===`);
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
default:
|
|
69
|
+
console.log(
|
|
70
|
+
'Invalid method. Use: node interactive-top-improved.mjs [1|2|3]'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $ } from '../src/$.mjs';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
// Get the directory where this script is located
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const logPath = path.join(__dirname, 'top-pty-session.log');
|
|
12
|
+
|
|
13
|
+
console.log('=== Interactive top with PTY logging ===');
|
|
14
|
+
console.log('This demonstrates interactive mode with proper output capture');
|
|
15
|
+
console.log('- top runs interactively (q to quit)');
|
|
16
|
+
console.log(`- All output is logged to ${logPath}`);
|
|
17
|
+
console.log('- Uses pseudo-terminal for proper capture');
|
|
18
|
+
console.log('\nStarting top... Press q to quit when ready.\n');
|
|
19
|
+
|
|
20
|
+
const logStream = fs.createWriteStream(logPath, { flags: 'a' });
|
|
21
|
+
logStream.write(
|
|
22
|
+
`\n=== Top PTY session started at ${new Date().toISOString()} ===\n`
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// The issue: automatic interactive detection uses stdio: 'inherit' which prevents output capture
|
|
26
|
+
// For now, we need to use a non-interactive command to demonstrate logging
|
|
27
|
+
// Using 'top -l 3' (3 iterations) instead of interactive top
|
|
28
|
+
console.log(
|
|
29
|
+
'Note: Using top -l 3 (3 iterations) to demonstrate logging capability'
|
|
30
|
+
);
|
|
31
|
+
console.log(
|
|
32
|
+
'Interactive top with logging requires PTY support which is not yet implemented\n'
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const proc = $`top -l 3`;
|
|
36
|
+
|
|
37
|
+
let outputSize = 0;
|
|
38
|
+
|
|
39
|
+
// Log all stdout data to file
|
|
40
|
+
proc.on('stdout', (chunk) => {
|
|
41
|
+
// Log raw data (with ANSI codes) to file
|
|
42
|
+
logStream.write(chunk);
|
|
43
|
+
outputSize += chunk.length;
|
|
44
|
+
|
|
45
|
+
// Log progress
|
|
46
|
+
console.log(
|
|
47
|
+
`[LOG] Captured ${chunk.length} bytes (total: ${outputSize} bytes)`
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Log stderr if any
|
|
52
|
+
proc.on('stderr', (chunk) => {
|
|
53
|
+
logStream.write(`[STDERR] ${chunk}`);
|
|
54
|
+
console.log(`[LOG] Captured ${chunk.length} bytes of stderr`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Handle process completion
|
|
58
|
+
proc.on('end', (result) => {
|
|
59
|
+
logStream.write(
|
|
60
|
+
`\n=== Top PTY session ended with code: ${result.code} at ${new Date().toISOString()} ===\n`
|
|
61
|
+
);
|
|
62
|
+
logStream.end();
|
|
63
|
+
console.log(`\n=== Session logged to ${logPath} ===`);
|
|
64
|
+
console.log(`=== Total output captured: ${outputSize} bytes ===`);
|
|
65
|
+
console.log(`=== top exited with code: ${result.code} ===`);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Start the process
|
|
69
|
+
await proc;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
|
|
5
|
+
console.log('=== Truly Interactive top command ===');
|
|
6
|
+
console.log(
|
|
7
|
+
'This version uses direct spawn with stdio: "inherit" for full TTY support'
|
|
8
|
+
);
|
|
9
|
+
console.log('- Keyboard input works (q to quit, space to refresh, etc.)');
|
|
10
|
+
console.log('- ANSI colors and formatting preserved');
|
|
11
|
+
console.log('- Full terminal interaction');
|
|
12
|
+
console.log('\nStarting top... Press q to quit when ready.\n');
|
|
13
|
+
|
|
14
|
+
// Use Node.js spawn directly with stdio: 'inherit' for true TTY forwarding
|
|
15
|
+
const topProcess = spawn('top', [], {
|
|
16
|
+
stdio: 'inherit', // This forwards stdin, stdout, stderr directly to/from terminal
|
|
17
|
+
cwd: process.cwd(),
|
|
18
|
+
env: process.env,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
topProcess.on('close', (code) => {
|
|
22
|
+
console.log(`\n=== top exited with code: ${code} ===`);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
topProcess.on('error', (error) => {
|
|
26
|
+
console.error('Error starting top:', error.message);
|
|
27
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $ } from '../src/$.mjs';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
// Get the directory where this script is located
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const logPath = path.join(__dirname, 'top-session.log');
|
|
12
|
+
|
|
13
|
+
console.log('=== Interactive top with logging ===');
|
|
14
|
+
console.log(
|
|
15
|
+
'This demonstrates interactive mode while logging all output to files'
|
|
16
|
+
);
|
|
17
|
+
console.log('- top runs interactively (q to quit)');
|
|
18
|
+
console.log(`- All output is logged to ${logPath}`);
|
|
19
|
+
console.log('- All input can be captured too');
|
|
20
|
+
console.log('\nStarting top... Press q to quit when ready.\n');
|
|
21
|
+
|
|
22
|
+
const logStream = fs.createWriteStream(logPath, { flags: 'a' });
|
|
23
|
+
logStream.write(
|
|
24
|
+
`\n=== Top session started at ${new Date().toISOString()} ===\n`
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Start top - it will run interactively
|
|
28
|
+
const proc = $`top`;
|
|
29
|
+
|
|
30
|
+
// Log all stdout data to file while maintaining interactivity
|
|
31
|
+
proc.on('stdout', (chunk) => {
|
|
32
|
+
// Log raw data (with ANSI codes) to file
|
|
33
|
+
logStream.write(chunk);
|
|
34
|
+
|
|
35
|
+
// Also log processed data for debugging
|
|
36
|
+
console.log(`[LOG] Captured ${chunk.length} bytes of stdout`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Log stderr if any
|
|
40
|
+
proc.on('stderr', (chunk) => {
|
|
41
|
+
logStream.write(`[STDERR] ${chunk}`);
|
|
42
|
+
console.log(`[LOG] Captured ${chunk.length} bytes of stderr`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Handle process completion
|
|
46
|
+
proc.on('end', (result) => {
|
|
47
|
+
logStream.write(
|
|
48
|
+
`\n=== Top session ended with code: ${result.code} at ${new Date().toISOString()} ===\n`
|
|
49
|
+
);
|
|
50
|
+
logStream.end();
|
|
51
|
+
console.log(`\n=== Session logged to ${logPath} ===`);
|
|
52
|
+
console.log(`=== top exited with code: ${result.code} ===`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Start the process
|
|
56
|
+
await proc;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $ } from '../src/$.mjs';
|
|
4
|
+
|
|
5
|
+
console.log(
|
|
6
|
+
'=== Interactive top command (preserves ANSI colors and interactive controls) ==='
|
|
7
|
+
);
|
|
8
|
+
console.log('This will run top interactively. Press q to quit when ready.\n');
|
|
9
|
+
|
|
10
|
+
// Start top in interactive mode - it should work automatically
|
|
11
|
+
const proc = $`top`;
|
|
12
|
+
|
|
13
|
+
// Forward all stdout to terminal (preserving colors and formatting)
|
|
14
|
+
proc.on('stdout', (chunk) => {
|
|
15
|
+
process.stdout.write(chunk);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Forward stderr if any
|
|
19
|
+
proc.on('stderr', (chunk) => {
|
|
20
|
+
process.stderr.write(chunk);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Handle process completion
|
|
24
|
+
proc.on('end', (result) => {
|
|
25
|
+
console.log(`\n=== top exited with code: ${result.code} ===`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Start the process
|
|
29
|
+
await proc;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $ } from '../src/$.mjs';
|
|
4
|
+
|
|
5
|
+
console.log('=== jq Color Output Demo ===\n');
|
|
6
|
+
|
|
7
|
+
const testJson =
|
|
8
|
+
'{"message": "Hello World", "number": 42, "active": true, "nested": {"data": [1, 2, 3], "flag": false}}';
|
|
9
|
+
|
|
10
|
+
console.log(
|
|
11
|
+
'This demo shows how to get colored jq output with command-stream.\n'
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
console.log(
|
|
15
|
+
'1. Default behavior (mirror: true means output appears automatically):'
|
|
16
|
+
);
|
|
17
|
+
console.log(' Code: await $`echo ${testJson} | jq .`');
|
|
18
|
+
console.log(' Output:');
|
|
19
|
+
await $`echo ${testJson} | jq .`;
|
|
20
|
+
|
|
21
|
+
console.log('\n2. Force colors even in non-TTY environments with -C flag:');
|
|
22
|
+
console.log(' Code: await $`echo ${testJson} | jq -C .`');
|
|
23
|
+
console.log(' Output (with ANSI color codes):');
|
|
24
|
+
await $`echo ${testJson} | jq -C .`;
|
|
25
|
+
|
|
26
|
+
console.log('\n3. Extract specific field with colors:');
|
|
27
|
+
console.log(' Code: await $`echo ${testJson} | jq -C .nested`');
|
|
28
|
+
console.log(' Output:');
|
|
29
|
+
await $`echo ${testJson} | jq -C .nested`;
|
|
30
|
+
|
|
31
|
+
console.log('\n4. No need for console.log - output is automatically mirrored!');
|
|
32
|
+
console.log(' The beauty of command-stream is that with default settings,');
|
|
33
|
+
console.log(' you get shell-like behavior: output appears immediately.');
|
|
34
|
+
|
|
35
|
+
console.log('\n5. Capture-only mode (no automatic output):');
|
|
36
|
+
console.log(
|
|
37
|
+
' Code: const result = await $({ mirror: false })`echo ${testJson} | jq -C .message`'
|
|
38
|
+
);
|
|
39
|
+
const result = await $({ mirror: false })`echo ${testJson} | jq -C .message`;
|
|
40
|
+
console.log(' Captured result:', JSON.stringify(result.stdout.trim()));
|
|
41
|
+
|
|
42
|
+
console.log('\n6. Best of both worlds (mirror + capture):');
|
|
43
|
+
console.log(
|
|
44
|
+
' Code: const result = await $`echo ${testJson} | jq -C -r .message`'
|
|
45
|
+
);
|
|
46
|
+
const result2 = await $`echo ${testJson} | jq -C -r .message`;
|
|
47
|
+
console.log(' Also captured:', JSON.stringify(result2.stdout.trim()));
|
|
48
|
+
|
|
49
|
+
console.log('\n✅ Summary:');
|
|
50
|
+
console.log('- Use jq -C for forced colors (works in any environment)');
|
|
51
|
+
console.log('- Default mirror:true means no manual console.log needed');
|
|
52
|
+
console.log('- Colors work great with command-stream piping');
|
|
53
|
+
console.log('- In real TTY environments, jq colors automatically!');
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { $ } from '../src/$.mjs';
|
|
4
|
+
|
|
5
|
+
console.log('=== jq Streaming with ANSI Colors ===\n');
|
|
6
|
+
|
|
7
|
+
console.log('Test 1: JSON streaming with colors (using --color-output):');
|
|
8
|
+
const coloredCmd = $`printf '{"name":"Alice","status":"active","score":95}\n{"name":"Bob","status":"inactive","score":87}\n{"name":"Carol","status":"active","score":92}\n' | jq --color-output .`;
|
|
9
|
+
|
|
10
|
+
console.log('Streaming colored JSON:');
|
|
11
|
+
coloredCmd.on('stdout', (chunk) => {
|
|
12
|
+
// Display raw colored output
|
|
13
|
+
process.stdout.write(chunk);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
await coloredCmd;
|
|
17
|
+
|
|
18
|
+
console.log('\nTest 2: Compact colored streaming:');
|
|
19
|
+
const compactCmd = $`printf '{"user":"Alice","data":{"x":1,"y":2}}\n{"user":"Bob","data":{"x":3,"y":4}}\n' | jq --color-output -c '.user + ": " + (.data.x + .data.y | tostring)'`;
|
|
20
|
+
|
|
21
|
+
compactCmd.on('stdout', (chunk) => {
|
|
22
|
+
process.stdout.write('> ');
|
|
23
|
+
process.stdout.write(chunk);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await compactCmd;
|
|
27
|
+
|
|
28
|
+
console.log('\nTest 3: Interactive-style filtering with colors:');
|
|
29
|
+
const filterCmd = $`printf '{"type":"user","name":"Alice"}\n{"type":"admin","name":"Bob"}\n{"type":"user","name":"Carol"}\n' | jq --color-output 'select(.type == "user")'`;
|
|
30
|
+
|
|
31
|
+
console.log('Filtered users (colored):');
|
|
32
|
+
filterCmd.on('stdout', (chunk) => {
|
|
33
|
+
process.stdout.write(chunk);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await filterCmd;
|
|
37
|
+
|
|
38
|
+
console.log('\n=== Results ===');
|
|
39
|
+
console.log('✅ ANSI colors preserved in jq pipelines');
|
|
40
|
+
console.log('✅ Real-time streaming with color support');
|
|
41
|
+
console.log('✅ Use --color-output to force colors in pipelines');
|
|
42
|
+
console.log('✅ Colors work even when not connected to terminal');
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Manual test for CTRL+C handling
|
|
4
|
+
// Run this script and press CTRL+C to test signal propagation
|
|
5
|
+
|
|
6
|
+
import { $ } from '../src/$.mjs';
|
|
7
|
+
|
|
8
|
+
console.log('=== Manual CTRL+C Test ===\n');
|
|
9
|
+
console.log('This script will run ping continuously.');
|
|
10
|
+
console.log('Press CTRL+C to interrupt and see if it properly terminates.\n');
|
|
11
|
+
console.log('Starting ping to 8.8.8.8...');
|
|
12
|
+
console.log('----------------------------------------\n');
|
|
13
|
+
|
|
14
|
+
// Track if we received SIGINT
|
|
15
|
+
let parentGotSigint = false;
|
|
16
|
+
let sigintCount = 0;
|
|
17
|
+
process.on('SIGINT', () => {
|
|
18
|
+
sigintCount++;
|
|
19
|
+
console.log(`\n[PARENT] Received SIGINT signal (count: ${sigintCount})`);
|
|
20
|
+
parentGotSigint = true;
|
|
21
|
+
|
|
22
|
+
// Exit on second CTRL+C (user really wants to quit)
|
|
23
|
+
if (sigintCount >= 2) {
|
|
24
|
+
console.log('[PARENT] Exiting after second CTRL+C');
|
|
25
|
+
process.exit(130);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Clean exit handler
|
|
30
|
+
process.on('exit', (code) => {
|
|
31
|
+
console.log(`\n[PARENT] Exiting with code: ${code}`);
|
|
32
|
+
console.log(`Parent received SIGINT: ${parentGotSigint}`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
// Run ping with default settings (stdin: 'inherit')
|
|
37
|
+
const result = await $`ping 8.8.8.8`;
|
|
38
|
+
console.log('\nPing completed normally (unexpected)');
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.log('\n----------------------------------------');
|
|
41
|
+
console.log('Command was interrupted!');
|
|
42
|
+
console.log(`Exit code: ${error.code}`);
|
|
43
|
+
console.log(`Error message: ${error.message}`);
|
|
44
|
+
|
|
45
|
+
if (error.code === 130 || error.code === -2 || error.code === 2) {
|
|
46
|
+
console.log('✓ SUCCESS: Received expected SIGINT exit code');
|
|
47
|
+
} else {
|
|
48
|
+
console.log(`⚠ WARNING: Unexpected exit code ${error.code}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Both .start() and .run() support all the same options
|
|
4
|
+
|
|
5
|
+
import { $ } from '../src/$.mjs';
|
|
6
|
+
|
|
7
|
+
console.log('Both support all the same options:');
|
|
8
|
+
|
|
9
|
+
// Test with multiple options using .start()
|
|
10
|
+
console.log('.start() with multiple options:');
|
|
11
|
+
const startResult = await $`cat`.start({
|
|
12
|
+
stdin: 'Input for start method',
|
|
13
|
+
capture: true,
|
|
14
|
+
mirror: false,
|
|
15
|
+
});
|
|
16
|
+
console.log(`Output: ${JSON.stringify(startResult.stdout)}`);
|
|
17
|
+
|
|
18
|
+
// Test with multiple options using .run()
|
|
19
|
+
console.log('\n.run() with multiple options:');
|
|
20
|
+
const runResult = await $`cat`.run({
|
|
21
|
+
stdin: 'Input for run method',
|
|
22
|
+
capture: true,
|
|
23
|
+
mirror: false,
|
|
24
|
+
});
|
|
25
|
+
console.log(`Output: ${JSON.stringify(runResult.stdout)}`);
|