picosh 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +12 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -49,8 +49,10 @@ const ANSI_RE = /\x1b\[[0-9;]*[A-Za-z]|\x1b\][^\x07]*\x07|\x07/g;
|
|
|
49
49
|
const PROMPT_RE = /❯\s*\?/;
|
|
50
50
|
const timers = {};
|
|
51
51
|
const waitingState = {};
|
|
52
|
+
let activeUid = null;
|
|
52
53
|
|
|
53
54
|
function setWaiting(uid, waiting) {
|
|
55
|
+
if (!uid) return;
|
|
54
56
|
waitingState[uid] = waiting;
|
|
55
57
|
if (typeof window !== 'undefined') {
|
|
56
58
|
window.dispatchEvent(new CustomEvent('picosh-ai-waiting', {detail: {uid, waiting}}));
|
|
@@ -58,28 +60,27 @@ function setWaiting(uid, waiting) {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
exports.middleware = () => (next) => (action) => {
|
|
61
|
-
if (action.type
|
|
62
|
-
|
|
63
|
+
if (action.type === 'SESSION_ADD' || action.type === 'SESSION_SET_ACTIVE') {
|
|
64
|
+
if (action.uid) activeUid = action.uid;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
if (action.type === 'SESSION_ADD_DATA') {
|
|
66
|
-
const
|
|
68
|
+
const uid = action.uid || activeUid;
|
|
69
|
+
const {data} = action;
|
|
67
70
|
const clean = data.replace(ANSI_RE, '');
|
|
68
|
-
console.log('[picosh] data:', JSON.stringify(clean.slice(-50)));
|
|
69
71
|
|
|
70
72
|
clearTimeout(timers[uid]);
|
|
71
73
|
setWaiting(uid, false);
|
|
72
74
|
|
|
73
75
|
timers[uid] = setTimeout(() => {
|
|
74
|
-
|
|
75
|
-
console.log('[picosh] prompt match:', matched);
|
|
76
|
-
if (matched) setWaiting(uid, true);
|
|
76
|
+
if (PROMPT_RE.test(clean)) setWaiting(uid, true);
|
|
77
77
|
}, 500);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (action.type === 'SESSION_PTY_DATA') {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const uid = action.uid || activeUid;
|
|
82
|
+
clearTimeout(timers[uid]);
|
|
83
|
+
setWaiting(uid, false);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
return next(action);
|
|
@@ -88,9 +89,11 @@ exports.middleware = () => (next) => (action) => {
|
|
|
88
89
|
exports.decorateTab = (Tab, {React}) => {
|
|
89
90
|
return function PicoshTab(props) {
|
|
90
91
|
const [waiting, setWaitingState] = React.useState(!!waitingState[props.uid]);
|
|
92
|
+
console.log('[picosh] decorateTab render uid:', props.uid && props.uid.slice(0, 8), 'waiting:', waiting);
|
|
91
93
|
|
|
92
94
|
React.useEffect(() => {
|
|
93
95
|
function onWaiting(e) {
|
|
96
|
+
console.log('[picosh] tab event received', e.detail.uid.slice(0, 8), 'this:', props.uid && props.uid.slice(0, 8));
|
|
94
97
|
if (e.detail.uid === props.uid) setWaitingState(e.detail.waiting);
|
|
95
98
|
}
|
|
96
99
|
window.addEventListener('picosh-ai-waiting', onWaiting);
|