@homelib/terminal 0.0.0-wip.01265bf1cc90
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/LICENSE +19 -0
- package/README.md +11 -0
- package/bld/library/@bootstrap-arguments.d.ts +1 -0
- package/bld/library/@bootstrap-arguments.js +12 -0
- package/bld/library/@bootstrap-arguments.js.map +1 -0
- package/bld/library/@log-format.d.ts +3 -0
- package/bld/library/@log-format.js +8 -0
- package/bld/library/@log-format.js.map +1 -0
- package/bld/library/@tui/bindings-page.d.ts +90 -0
- package/bld/library/@tui/bindings-page.js +414 -0
- package/bld/library/@tui/bindings-page.js.map +1 -0
- package/bld/library/@tui/provider-page.d.ts +10 -0
- package/bld/library/@tui/provider-page.js +6 -0
- package/bld/library/@tui/provider-page.js.map +1 -0
- package/bld/library/@tui/providers-page.d.ts +14 -0
- package/bld/library/@tui/providers-page.js +31 -0
- package/bld/library/@tui/providers-page.js.map +1 -0
- package/bld/library/@tui/startup-page.d.ts +14 -0
- package/bld/library/@tui/startup-page.js +39 -0
- package/bld/library/@tui/startup-page.js.map +1 -0
- package/bld/library/@tui/startup.d.ts +9 -0
- package/bld/library/@tui/startup.js +371 -0
- package/bld/library/@tui/startup.js.map +1 -0
- package/bld/library/index.d.ts +2 -0
- package/bld/library/index.js +22 -0
- package/bld/library/index.js.map +1 -0
- package/bld/library/log.d.ts +2 -0
- package/bld/library/log.js +74 -0
- package/bld/library/log.js.map +1 -0
- package/bld/library/tui.d.ts +30 -0
- package/bld/library/tui.js +72 -0
- package/bld/library/tui.js.map +1 -0
- package/package.json +25 -0
- package/src/library/@bootstrap-arguments.ts +13 -0
- package/src/library/@log-format.ts +19 -0
- package/src/library/@tui/bindings-page.tsx +987 -0
- package/src/library/@tui/provider-page.tsx +36 -0
- package/src/library/@tui/providers-page.tsx +97 -0
- package/src/library/@tui/startup-page.tsx +113 -0
- package/src/library/@tui/startup.tsx +679 -0
- package/src/library/index.ts +30 -0
- package/src/library/log.ts +127 -0
- package/src/library/tui.tsx +201 -0
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
import type {EndpointPath, ProviderReference} from '@homelib/core';
|
|
2
|
+
import {Box, Text, useInput} from 'ink';
|
|
3
|
+
import {useState} from 'react';
|
|
4
|
+
|
|
5
|
+
export type BindingEndpointItem = {
|
|
6
|
+
readonly path: EndpointPath;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly provider: ProviderReference | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type BindingDeviceItem = {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly endpoints: readonly BindingEndpointItem[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type BindingScopeItem = {
|
|
17
|
+
readonly path: readonly string[];
|
|
18
|
+
readonly scopes: readonly BindingScopeItem[];
|
|
19
|
+
readonly devices: readonly BindingDeviceItem[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type BindingsPageModel = {
|
|
23
|
+
readonly scriptName: string;
|
|
24
|
+
readonly scopes: readonly BindingScopeItem[];
|
|
25
|
+
readonly staleBindingCount: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type BindingsPageProps = {
|
|
29
|
+
readonly model: BindingsPageModel;
|
|
30
|
+
readonly onBack: () => void;
|
|
31
|
+
readonly onSelect: (scope: BindingScopeItem) => void;
|
|
32
|
+
readonly onSelectStaleBindings: () => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function BindingsPage({
|
|
36
|
+
model,
|
|
37
|
+
onBack,
|
|
38
|
+
onSelect,
|
|
39
|
+
onSelectStaleBindings,
|
|
40
|
+
}: BindingsPageProps): React.JSX.Element {
|
|
41
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
42
|
+
const hasScopes = model.scopes.length > 0;
|
|
43
|
+
|
|
44
|
+
useInput((input, key) => {
|
|
45
|
+
if (key.escape) {
|
|
46
|
+
onBack();
|
|
47
|
+
} else if (key.upArrow && hasScopes) {
|
|
48
|
+
setSelectedIndex(index =>
|
|
49
|
+
index === 0 ? model.scopes.length - 1 : index - 1,
|
|
50
|
+
);
|
|
51
|
+
} else if (key.downArrow && hasScopes) {
|
|
52
|
+
setSelectedIndex(index =>
|
|
53
|
+
index === model.scopes.length - 1 ? 0 : index + 1,
|
|
54
|
+
);
|
|
55
|
+
} else if (key.return) {
|
|
56
|
+
const scope = model.scopes.at(selectedIndex);
|
|
57
|
+
|
|
58
|
+
if (scope !== undefined) {
|
|
59
|
+
onSelect(scope);
|
|
60
|
+
}
|
|
61
|
+
} else if (input === 'u' && model.staleBindingCount > 0) {
|
|
62
|
+
onSelectStaleBindings();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Page scriptName={model.scriptName} title="bindings">
|
|
68
|
+
<Box flexDirection="column" marginTop={1}>
|
|
69
|
+
<Text dimColor>{model.staleBindingCount} stale bindings</Text>
|
|
70
|
+
</Box>
|
|
71
|
+
|
|
72
|
+
<Box flexDirection="column" marginTop={1}>
|
|
73
|
+
{hasScopes ? (
|
|
74
|
+
model.scopes.map((scope, index) => (
|
|
75
|
+
<ScopeItem
|
|
76
|
+
key={getScopeKey(scope)}
|
|
77
|
+
scope={scope}
|
|
78
|
+
selected={index === selectedIndex}
|
|
79
|
+
/>
|
|
80
|
+
))
|
|
81
|
+
) : (
|
|
82
|
+
<Text dimColor>no root scopes declared.</Text>
|
|
83
|
+
)}
|
|
84
|
+
</Box>
|
|
85
|
+
|
|
86
|
+
<Hint>{getBindingsPageHint(hasScopes, model.staleBindingCount > 0)}</Hint>
|
|
87
|
+
</Page>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type StaleBindingItem = {
|
|
92
|
+
readonly path: EndpointPath;
|
|
93
|
+
readonly provider: ProviderReference;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type StaleBindingsPageProps = {
|
|
97
|
+
readonly model: {
|
|
98
|
+
readonly scriptName: string;
|
|
99
|
+
readonly bindings: readonly StaleBindingItem[];
|
|
100
|
+
};
|
|
101
|
+
readonly onBack: () => void;
|
|
102
|
+
readonly onRemove: (binding: StaleBindingItem) => Promise<void>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export function StaleBindingsPage({
|
|
106
|
+
model,
|
|
107
|
+
onBack,
|
|
108
|
+
onRemove,
|
|
109
|
+
}: StaleBindingsPageProps): React.JSX.Element {
|
|
110
|
+
const [state, setState] = useState<StaleBindingsPageState>({
|
|
111
|
+
type: 'bindings',
|
|
112
|
+
cursor: 0,
|
|
113
|
+
});
|
|
114
|
+
const hasBindings = model.bindings.length > 0;
|
|
115
|
+
|
|
116
|
+
useInput((input, key) => {
|
|
117
|
+
if (state.type === 'bindings') {
|
|
118
|
+
const cursor = normalizeCursor(state.cursor, model.bindings.length);
|
|
119
|
+
|
|
120
|
+
if (key.escape) {
|
|
121
|
+
onBack();
|
|
122
|
+
} else if (key.upArrow && hasBindings) {
|
|
123
|
+
setState({
|
|
124
|
+
...state,
|
|
125
|
+
cursor: cursor === 0 ? model.bindings.length - 1 : cursor - 1,
|
|
126
|
+
});
|
|
127
|
+
} else if (key.downArrow && hasBindings) {
|
|
128
|
+
setState({
|
|
129
|
+
...state,
|
|
130
|
+
cursor: cursor === model.bindings.length - 1 ? 0 : cursor + 1,
|
|
131
|
+
});
|
|
132
|
+
} else if (key.return) {
|
|
133
|
+
const binding = model.bindings.at(cursor);
|
|
134
|
+
|
|
135
|
+
if (binding !== undefined) {
|
|
136
|
+
setState({type: 'confirm-remove', source: state, binding});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else if (state.type === 'confirm-remove') {
|
|
140
|
+
if (key.escape) {
|
|
141
|
+
setState(state.source);
|
|
142
|
+
} else if (key.return || input === 'y') {
|
|
143
|
+
saveRemoval(state.source, state.binding);
|
|
144
|
+
}
|
|
145
|
+
} else if (state.type === 'removing') {
|
|
146
|
+
return;
|
|
147
|
+
} else if (key.escape) {
|
|
148
|
+
setState(state.source);
|
|
149
|
+
} else if (key.return || input === 'r') {
|
|
150
|
+
saveRemoval(state.source, state.binding);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const saveRemoval = (
|
|
155
|
+
source: StaleBindingsState,
|
|
156
|
+
binding: StaleBindingItem,
|
|
157
|
+
): void => {
|
|
158
|
+
setState({type: 'removing', source, binding});
|
|
159
|
+
void onRemove(binding).then(
|
|
160
|
+
() => {
|
|
161
|
+
setState({
|
|
162
|
+
type: 'bindings',
|
|
163
|
+
cursor: source.cursor,
|
|
164
|
+
notice: 'stale binding removed.',
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
error => {
|
|
168
|
+
setState({
|
|
169
|
+
type: 'remove-error',
|
|
170
|
+
source,
|
|
171
|
+
binding,
|
|
172
|
+
message: getErrorMessage(error),
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const matchingBindingCount =
|
|
179
|
+
state.type === 'confirm-remove' ||
|
|
180
|
+
state.type === 'removing' ||
|
|
181
|
+
state.type === 'remove-error'
|
|
182
|
+
? countBindingsForPath(model.bindings, state.binding.path)
|
|
183
|
+
: 0;
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<Page scriptName={model.scriptName} title="bindings › stale">
|
|
187
|
+
<StaleBindingsView
|
|
188
|
+
bindings={model.bindings}
|
|
189
|
+
matchingBindingCount={matchingBindingCount}
|
|
190
|
+
state={state}
|
|
191
|
+
/>
|
|
192
|
+
</Page>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
type StaleBindingsPageState =
|
|
197
|
+
| StaleBindingsState
|
|
198
|
+
| ConfirmRemoveStaleBindingState
|
|
199
|
+
| RemovingStaleBindingState
|
|
200
|
+
| RemoveStaleBindingErrorState;
|
|
201
|
+
|
|
202
|
+
type StaleBindingsState = {
|
|
203
|
+
readonly type: 'bindings';
|
|
204
|
+
readonly cursor: number;
|
|
205
|
+
readonly notice?: string;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
type ConfirmRemoveStaleBindingState = {
|
|
209
|
+
readonly type: 'confirm-remove';
|
|
210
|
+
readonly source: StaleBindingsState;
|
|
211
|
+
readonly binding: StaleBindingItem;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
type RemovingStaleBindingState = {
|
|
215
|
+
readonly type: 'removing';
|
|
216
|
+
readonly source: StaleBindingsState;
|
|
217
|
+
readonly binding: StaleBindingItem;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
type RemoveStaleBindingErrorState = {
|
|
221
|
+
readonly type: 'remove-error';
|
|
222
|
+
readonly source: StaleBindingsState;
|
|
223
|
+
readonly binding: StaleBindingItem;
|
|
224
|
+
readonly message: string;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
type StaleBindingsViewProps = {
|
|
228
|
+
readonly bindings: readonly StaleBindingItem[];
|
|
229
|
+
readonly matchingBindingCount: number;
|
|
230
|
+
readonly state: StaleBindingsPageState;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
function StaleBindingsView({
|
|
234
|
+
bindings,
|
|
235
|
+
matchingBindingCount,
|
|
236
|
+
state,
|
|
237
|
+
}: StaleBindingsViewProps): React.JSX.Element {
|
|
238
|
+
if (state.type === 'confirm-remove') {
|
|
239
|
+
return (
|
|
240
|
+
<Box flexDirection="column" marginTop={1}>
|
|
241
|
+
<Text>
|
|
242
|
+
{matchingBindingCount === 1
|
|
243
|
+
? 'remove the stale binding for'
|
|
244
|
+
: `remove all ${matchingBindingCount} stale bindings for`}{' '}
|
|
245
|
+
{formatEndpointPath(state.binding.path)}?
|
|
246
|
+
</Text>
|
|
247
|
+
<Text dimColor>
|
|
248
|
+
{state.binding.provider.namespace} · {state.binding.provider.name}
|
|
249
|
+
</Text>
|
|
250
|
+
<Hint>enter/y confirm · esc cancel · q menu · ctrl+c exit</Hint>
|
|
251
|
+
</Box>
|
|
252
|
+
);
|
|
253
|
+
} else if (state.type === 'removing') {
|
|
254
|
+
return (
|
|
255
|
+
<Box flexDirection="column" marginTop={1}>
|
|
256
|
+
<Text>removing stale binding…</Text>
|
|
257
|
+
<Hint>q menu · ctrl+c exit</Hint>
|
|
258
|
+
</Box>
|
|
259
|
+
);
|
|
260
|
+
} else if (state.type === 'remove-error') {
|
|
261
|
+
return (
|
|
262
|
+
<Box flexDirection="column" marginTop={1}>
|
|
263
|
+
<Text color="red">{state.message}</Text>
|
|
264
|
+
<Hint>enter/r retry · esc back · q menu · ctrl+c exit</Hint>
|
|
265
|
+
</Box>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const cursor = normalizeCursor(state.cursor, bindings.length);
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<>
|
|
273
|
+
<Box flexDirection="column" marginTop={1}>
|
|
274
|
+
<Text dimColor>{bindings.length} stale bindings</Text>
|
|
275
|
+
</Box>
|
|
276
|
+
|
|
277
|
+
<Box flexDirection="column" marginTop={1}>
|
|
278
|
+
{bindings.length === 0 ? (
|
|
279
|
+
<Text dimColor>no stale bindings.</Text>
|
|
280
|
+
) : (
|
|
281
|
+
bindings.map((binding, index) => (
|
|
282
|
+
<ListItem
|
|
283
|
+
key={getStaleBindingKey(binding, index)}
|
|
284
|
+
details={`${binding.provider.namespace} · ${binding.provider.name}`}
|
|
285
|
+
label={formatEndpointPath(binding.path)}
|
|
286
|
+
selected={index === cursor}
|
|
287
|
+
/>
|
|
288
|
+
))
|
|
289
|
+
)}
|
|
290
|
+
</Box>
|
|
291
|
+
|
|
292
|
+
{state.notice === undefined ? null : (
|
|
293
|
+
<Text color="green">{state.notice}</Text>
|
|
294
|
+
)}
|
|
295
|
+
|
|
296
|
+
<Hint>
|
|
297
|
+
{bindings.length === 0
|
|
298
|
+
? 'esc back · q menu · ctrl+c exit'
|
|
299
|
+
: '↑↓ select · enter · esc back · q menu · ctrl+c exit'}
|
|
300
|
+
</Hint>
|
|
301
|
+
</>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export type BindingScopePageProps = {
|
|
306
|
+
readonly model: {
|
|
307
|
+
readonly scriptName: string;
|
|
308
|
+
readonly scope: BindingScopeItem;
|
|
309
|
+
};
|
|
310
|
+
readonly onBack: () => void;
|
|
311
|
+
readonly onSelectScope: (scope: BindingScopeItem) => void;
|
|
312
|
+
readonly onSelectDevice: (device: BindingDeviceItem) => void;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export function BindingScopePage({
|
|
316
|
+
model,
|
|
317
|
+
onBack,
|
|
318
|
+
onSelectScope,
|
|
319
|
+
onSelectDevice,
|
|
320
|
+
}: BindingScopePageProps): React.JSX.Element {
|
|
321
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
322
|
+
const items: readonly BindingScopePageItem[] = [
|
|
323
|
+
...model.scope.scopes.map(scope => ({type: 'scope' as const, scope})),
|
|
324
|
+
...model.scope.devices.map(device => ({type: 'device' as const, device})),
|
|
325
|
+
];
|
|
326
|
+
const hasItems = items.length > 0;
|
|
327
|
+
|
|
328
|
+
useInput((_input, key) => {
|
|
329
|
+
if (key.escape) {
|
|
330
|
+
onBack();
|
|
331
|
+
} else if (key.upArrow && hasItems) {
|
|
332
|
+
setSelectedIndex(index => (index === 0 ? items.length - 1 : index - 1));
|
|
333
|
+
} else if (key.downArrow && hasItems) {
|
|
334
|
+
setSelectedIndex(index => (index === items.length - 1 ? 0 : index + 1));
|
|
335
|
+
} else if (key.return) {
|
|
336
|
+
const item = items.at(selectedIndex);
|
|
337
|
+
|
|
338
|
+
if (item?.type === 'scope') {
|
|
339
|
+
onSelectScope(item.scope);
|
|
340
|
+
} else if (item?.type === 'device') {
|
|
341
|
+
onSelectDevice(item.device);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<Page
|
|
348
|
+
scriptName={model.scriptName}
|
|
349
|
+
title={`bindings › ${model.scope.path.join(' › ')}`}
|
|
350
|
+
>
|
|
351
|
+
<Box flexDirection="column" marginTop={1}>
|
|
352
|
+
{hasItems ? (
|
|
353
|
+
items.map((item, index) => (
|
|
354
|
+
<BindingScopePageItemView
|
|
355
|
+
key={getBindingScopePageItemKey(item)}
|
|
356
|
+
item={item}
|
|
357
|
+
selected={index === selectedIndex}
|
|
358
|
+
/>
|
|
359
|
+
))
|
|
360
|
+
) : (
|
|
361
|
+
<Text dimColor>no logical devices declared.</Text>
|
|
362
|
+
)}
|
|
363
|
+
</Box>
|
|
364
|
+
|
|
365
|
+
<Hint>
|
|
366
|
+
{hasItems
|
|
367
|
+
? '↑↓ select · enter · esc back · q menu · ctrl+c exit'
|
|
368
|
+
: 'esc back · q menu · ctrl+c exit'}
|
|
369
|
+
</Hint>
|
|
370
|
+
</Page>
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export type BindingProviderItem = {
|
|
375
|
+
readonly namespace: string;
|
|
376
|
+
readonly name: string;
|
|
377
|
+
readonly boundEndpointCount: number;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
export type BindingDevicePageProps = {
|
|
381
|
+
readonly model: {
|
|
382
|
+
readonly scriptName: string;
|
|
383
|
+
readonly scopePath: readonly string[];
|
|
384
|
+
readonly device: BindingDeviceItem;
|
|
385
|
+
readonly providers: readonly BindingProviderItem[];
|
|
386
|
+
};
|
|
387
|
+
readonly onBack: () => void;
|
|
388
|
+
readonly onSelectProvider: (provider: BindingProviderItem) => void;
|
|
389
|
+
readonly onUnbind: (endpoint: BoundBindingEndpointItem) => Promise<void>;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export function BindingDevicePage({
|
|
393
|
+
model,
|
|
394
|
+
onBack,
|
|
395
|
+
onSelectProvider,
|
|
396
|
+
onUnbind,
|
|
397
|
+
}: BindingDevicePageProps): React.JSX.Element {
|
|
398
|
+
const [state, setState] = useState<BindingDevicePageState>({
|
|
399
|
+
type: 'providers',
|
|
400
|
+
cursor: 0,
|
|
401
|
+
});
|
|
402
|
+
const hasProviders = model.providers.length > 0;
|
|
403
|
+
const boundEndpoints = getBoundEndpoints(model.device);
|
|
404
|
+
const title = getDevicePageTitle(model.scopePath, model.device.name);
|
|
405
|
+
|
|
406
|
+
useInput((input, key) => {
|
|
407
|
+
if (state.type === 'providers') {
|
|
408
|
+
if (key.escape) {
|
|
409
|
+
onBack();
|
|
410
|
+
} else if (key.upArrow && hasProviders) {
|
|
411
|
+
setState({
|
|
412
|
+
...state,
|
|
413
|
+
cursor:
|
|
414
|
+
state.cursor === 0 ? model.providers.length - 1 : state.cursor - 1,
|
|
415
|
+
});
|
|
416
|
+
} else if (key.downArrow && hasProviders) {
|
|
417
|
+
setState({
|
|
418
|
+
...state,
|
|
419
|
+
cursor:
|
|
420
|
+
state.cursor === model.providers.length - 1 ? 0 : state.cursor + 1,
|
|
421
|
+
});
|
|
422
|
+
} else if (key.return) {
|
|
423
|
+
const provider = model.providers.at(state.cursor);
|
|
424
|
+
|
|
425
|
+
if (provider !== undefined) {
|
|
426
|
+
onSelectProvider(provider);
|
|
427
|
+
}
|
|
428
|
+
} else if (input === 'u' && boundEndpoints.length > 0) {
|
|
429
|
+
setState({
|
|
430
|
+
type: 'bound-endpoints',
|
|
431
|
+
source: state,
|
|
432
|
+
cursor: 0,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
} else if (state.type === 'bound-endpoints') {
|
|
436
|
+
if (key.escape) {
|
|
437
|
+
setState(state.source);
|
|
438
|
+
} else if (key.upArrow && boundEndpoints.length > 0) {
|
|
439
|
+
setState({
|
|
440
|
+
...state,
|
|
441
|
+
cursor:
|
|
442
|
+
state.cursor === 0 ? boundEndpoints.length - 1 : state.cursor - 1,
|
|
443
|
+
});
|
|
444
|
+
} else if (key.downArrow && boundEndpoints.length > 0) {
|
|
445
|
+
setState({
|
|
446
|
+
...state,
|
|
447
|
+
cursor:
|
|
448
|
+
state.cursor === boundEndpoints.length - 1 ? 0 : state.cursor + 1,
|
|
449
|
+
});
|
|
450
|
+
} else if (key.return) {
|
|
451
|
+
const endpoint = boundEndpoints.at(state.cursor);
|
|
452
|
+
|
|
453
|
+
if (endpoint !== undefined) {
|
|
454
|
+
setState({type: 'confirm-unbind', source: state, endpoint});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
} else if (state.type === 'confirm-unbind') {
|
|
458
|
+
if (key.escape) {
|
|
459
|
+
setState(state.source);
|
|
460
|
+
} else if (key.return || input === 'y') {
|
|
461
|
+
saveUnbinding(state.source, state.endpoint);
|
|
462
|
+
}
|
|
463
|
+
} else if (state.type === 'unbinding') {
|
|
464
|
+
return;
|
|
465
|
+
} else if (key.escape) {
|
|
466
|
+
setState(state.source);
|
|
467
|
+
} else if (key.return || input === 'r') {
|
|
468
|
+
saveUnbinding(state.source, state.endpoint);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const saveUnbinding = (
|
|
473
|
+
source: BoundEndpointsState,
|
|
474
|
+
endpoint: BoundBindingEndpointItem,
|
|
475
|
+
): void => {
|
|
476
|
+
setState({type: 'unbinding', source, endpoint});
|
|
477
|
+
void onUnbind(endpoint).then(
|
|
478
|
+
() => {
|
|
479
|
+
setState({
|
|
480
|
+
type: 'providers',
|
|
481
|
+
cursor: source.source.cursor,
|
|
482
|
+
notice: 'binding removed.',
|
|
483
|
+
});
|
|
484
|
+
},
|
|
485
|
+
error => {
|
|
486
|
+
setState({
|
|
487
|
+
type: 'unbind-error',
|
|
488
|
+
source,
|
|
489
|
+
endpoint,
|
|
490
|
+
message: getErrorMessage(error),
|
|
491
|
+
});
|
|
492
|
+
},
|
|
493
|
+
);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
return (
|
|
497
|
+
<Page scriptName={model.scriptName} title={title}>
|
|
498
|
+
<BindingDeviceView
|
|
499
|
+
boundEndpoints={boundEndpoints}
|
|
500
|
+
device={model.device}
|
|
501
|
+
providers={model.providers}
|
|
502
|
+
state={state}
|
|
503
|
+
/>
|
|
504
|
+
</Page>
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
type BoundBindingEndpointItem = BindingEndpointItem & {
|
|
509
|
+
readonly provider: ProviderReference;
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
type BindingDevicePageState =
|
|
513
|
+
| ProvidersState
|
|
514
|
+
| BoundEndpointsState
|
|
515
|
+
| ConfirmUnbindState
|
|
516
|
+
| UnbindingState
|
|
517
|
+
| UnbindErrorState;
|
|
518
|
+
|
|
519
|
+
type ProvidersState = {
|
|
520
|
+
readonly type: 'providers';
|
|
521
|
+
readonly cursor: number;
|
|
522
|
+
readonly notice?: string;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
type BoundEndpointsState = {
|
|
526
|
+
readonly type: 'bound-endpoints';
|
|
527
|
+
readonly source: ProvidersState;
|
|
528
|
+
readonly cursor: number;
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
type ConfirmUnbindState = {
|
|
532
|
+
readonly type: 'confirm-unbind';
|
|
533
|
+
readonly source: BoundEndpointsState;
|
|
534
|
+
readonly endpoint: BoundBindingEndpointItem;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
type UnbindingState = {
|
|
538
|
+
readonly type: 'unbinding';
|
|
539
|
+
readonly source: BoundEndpointsState;
|
|
540
|
+
readonly endpoint: BoundBindingEndpointItem;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
type UnbindErrorState = {
|
|
544
|
+
readonly type: 'unbind-error';
|
|
545
|
+
readonly source: BoundEndpointsState;
|
|
546
|
+
readonly endpoint: BoundBindingEndpointItem;
|
|
547
|
+
readonly message: string;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
type BindingDeviceViewProps = {
|
|
551
|
+
readonly state: BindingDevicePageState;
|
|
552
|
+
readonly device: BindingDeviceItem;
|
|
553
|
+
readonly providers: readonly BindingProviderItem[];
|
|
554
|
+
readonly boundEndpoints: readonly BoundBindingEndpointItem[];
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
function BindingDeviceView({
|
|
558
|
+
state,
|
|
559
|
+
device,
|
|
560
|
+
providers,
|
|
561
|
+
boundEndpoints,
|
|
562
|
+
}: BindingDeviceViewProps): React.JSX.Element {
|
|
563
|
+
if (state.type === 'bound-endpoints') {
|
|
564
|
+
return (
|
|
565
|
+
<Box flexDirection="column" marginTop={1}>
|
|
566
|
+
<Text>bound endpoints</Text>
|
|
567
|
+
|
|
568
|
+
<Box flexDirection="column" marginTop={1}>
|
|
569
|
+
{boundEndpoints.map((endpoint, index) => (
|
|
570
|
+
<ListItem
|
|
571
|
+
key={endpoint.name}
|
|
572
|
+
details={`${endpoint.provider.namespace} · ${endpoint.provider.name}`}
|
|
573
|
+
label={getDisplayName(endpoint.name, '(default endpoint)')}
|
|
574
|
+
selected={index === state.cursor}
|
|
575
|
+
/>
|
|
576
|
+
))}
|
|
577
|
+
</Box>
|
|
578
|
+
|
|
579
|
+
<Hint>↑↓ select · enter · esc back · q menu · ctrl+c exit</Hint>
|
|
580
|
+
</Box>
|
|
581
|
+
);
|
|
582
|
+
} else if (state.type === 'confirm-unbind') {
|
|
583
|
+
return (
|
|
584
|
+
<Box flexDirection="column" marginTop={1}>
|
|
585
|
+
<Text>
|
|
586
|
+
remove the binding for{' '}
|
|
587
|
+
{getDisplayName(state.endpoint.name, '(default endpoint)')}?
|
|
588
|
+
</Text>
|
|
589
|
+
<Text dimColor>
|
|
590
|
+
{state.endpoint.provider.namespace} · {state.endpoint.provider.name}
|
|
591
|
+
</Text>
|
|
592
|
+
<Hint>enter/y confirm · esc cancel · q menu · ctrl+c exit</Hint>
|
|
593
|
+
</Box>
|
|
594
|
+
);
|
|
595
|
+
} else if (state.type === 'unbinding') {
|
|
596
|
+
return (
|
|
597
|
+
<Box flexDirection="column" marginTop={1}>
|
|
598
|
+
<Text>removing binding…</Text>
|
|
599
|
+
<Hint>q menu · ctrl+c exit</Hint>
|
|
600
|
+
</Box>
|
|
601
|
+
);
|
|
602
|
+
} else if (state.type === 'unbind-error') {
|
|
603
|
+
return (
|
|
604
|
+
<Box flexDirection="column" marginTop={1}>
|
|
605
|
+
<Text color="red">{state.message}</Text>
|
|
606
|
+
<Hint>enter/r retry · esc back · q menu · ctrl+c exit</Hint>
|
|
607
|
+
</Box>
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const summary = getDeviceSummary(device);
|
|
612
|
+
const hasProviders = providers.length > 0;
|
|
613
|
+
const hasBoundEndpoints = boundEndpoints.length > 0;
|
|
614
|
+
|
|
615
|
+
return (
|
|
616
|
+
<>
|
|
617
|
+
<Box flexDirection="column" marginTop={1}>
|
|
618
|
+
<Text dimColor>
|
|
619
|
+
{summary.configuredEndpointCount} bound ·{' '}
|
|
620
|
+
{summary.unconfiguredEndpointCount} unbound
|
|
621
|
+
</Text>
|
|
622
|
+
</Box>
|
|
623
|
+
|
|
624
|
+
<Box flexDirection="column" marginTop={1}>
|
|
625
|
+
{hasProviders ? (
|
|
626
|
+
providers.map((provider, index) => (
|
|
627
|
+
<BindingProviderItemView
|
|
628
|
+
key={getProviderKey(provider)}
|
|
629
|
+
provider={provider}
|
|
630
|
+
selected={index === state.cursor}
|
|
631
|
+
/>
|
|
632
|
+
))
|
|
633
|
+
) : (
|
|
634
|
+
<Text dimColor>no providers declared.</Text>
|
|
635
|
+
)}
|
|
636
|
+
</Box>
|
|
637
|
+
|
|
638
|
+
{state.notice === undefined ? null : (
|
|
639
|
+
<Text color="green">{state.notice}</Text>
|
|
640
|
+
)}
|
|
641
|
+
|
|
642
|
+
<Hint>{getBindingDeviceHint(hasProviders, hasBoundEndpoints)}</Hint>
|
|
643
|
+
</>
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export type BindingProviderPageProps = {
|
|
648
|
+
readonly model: {
|
|
649
|
+
readonly scriptName: string;
|
|
650
|
+
readonly scopePath: readonly string[];
|
|
651
|
+
readonly deviceName: string;
|
|
652
|
+
readonly provider: {
|
|
653
|
+
readonly namespace: string;
|
|
654
|
+
readonly name: string;
|
|
655
|
+
};
|
|
656
|
+
};
|
|
657
|
+
readonly children: React.ReactNode;
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
export function BindingProviderPage({
|
|
661
|
+
model,
|
|
662
|
+
children,
|
|
663
|
+
}: BindingProviderPageProps): React.JSX.Element {
|
|
664
|
+
const deviceTitle = getDevicePageTitle(model.scopePath, model.deviceName);
|
|
665
|
+
|
|
666
|
+
return (
|
|
667
|
+
<Page scriptName={model.scriptName} title={deviceTitle}>
|
|
668
|
+
<Box flexDirection="column" marginTop={1}>
|
|
669
|
+
<Text dimColor>
|
|
670
|
+
match with {model.provider.namespace} · {model.provider.name}
|
|
671
|
+
</Text>
|
|
672
|
+
|
|
673
|
+
<Box flexDirection="column" marginTop={1}>
|
|
674
|
+
{children}
|
|
675
|
+
</Box>
|
|
676
|
+
|
|
677
|
+
<Hint>q menu · ctrl+c exit</Hint>
|
|
678
|
+
</Box>
|
|
679
|
+
</Page>
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export type BindingSummary = {
|
|
684
|
+
readonly deviceCount: number;
|
|
685
|
+
readonly configuredEndpointCount: number;
|
|
686
|
+
readonly unconfiguredEndpointCount: number;
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
export function getBindingSummary(
|
|
690
|
+
scopes: readonly BindingScopeItem[],
|
|
691
|
+
): BindingSummary {
|
|
692
|
+
let deviceCount = 0;
|
|
693
|
+
let configuredEndpointCount = 0;
|
|
694
|
+
let unconfiguredEndpointCount = 0;
|
|
695
|
+
|
|
696
|
+
for (const scope of scopes) {
|
|
697
|
+
deviceCount += scope.devices.length;
|
|
698
|
+
|
|
699
|
+
for (const device of scope.devices) {
|
|
700
|
+
const deviceSummary = getDeviceSummary(device);
|
|
701
|
+
|
|
702
|
+
configuredEndpointCount += deviceSummary.configuredEndpointCount;
|
|
703
|
+
unconfiguredEndpointCount += deviceSummary.unconfiguredEndpointCount;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const childSummary = getBindingSummary(scope.scopes);
|
|
707
|
+
|
|
708
|
+
deviceCount += childSummary.deviceCount;
|
|
709
|
+
configuredEndpointCount += childSummary.configuredEndpointCount;
|
|
710
|
+
unconfiguredEndpointCount += childSummary.unconfiguredEndpointCount;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
return {
|
|
714
|
+
deviceCount,
|
|
715
|
+
configuredEndpointCount,
|
|
716
|
+
unconfiguredEndpointCount,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
type BindingScopePageItem =
|
|
721
|
+
| {readonly type: 'scope'; readonly scope: BindingScopeItem}
|
|
722
|
+
| {readonly type: 'device'; readonly device: BindingDeviceItem};
|
|
723
|
+
|
|
724
|
+
type PageProps = {
|
|
725
|
+
readonly scriptName: string;
|
|
726
|
+
readonly title: string;
|
|
727
|
+
readonly children: React.ReactNode;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
function Page({scriptName, title, children}: PageProps): React.JSX.Element {
|
|
731
|
+
return (
|
|
732
|
+
<Box flexDirection="column" paddingX={1}>
|
|
733
|
+
<Text bold>homelib · {scriptName}</Text>
|
|
734
|
+
|
|
735
|
+
<Box marginTop={1}>
|
|
736
|
+
<Text bold>{title}</Text>
|
|
737
|
+
</Box>
|
|
738
|
+
|
|
739
|
+
{children}
|
|
740
|
+
</Box>
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
type HintProps = {
|
|
745
|
+
readonly children: React.ReactNode;
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
function Hint({children}: HintProps): React.JSX.Element {
|
|
749
|
+
return (
|
|
750
|
+
<Box marginTop={1}>
|
|
751
|
+
<Text dimColor>{children}</Text>
|
|
752
|
+
</Box>
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
type ScopeItemProps = {
|
|
757
|
+
readonly scope: BindingScopeItem;
|
|
758
|
+
readonly selected: boolean;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
function ScopeItem({scope, selected}: ScopeItemProps): React.JSX.Element {
|
|
762
|
+
const summary = getBindingSummary([scope]);
|
|
763
|
+
|
|
764
|
+
return (
|
|
765
|
+
<ListItem
|
|
766
|
+
details={`${summary.deviceCount} devices · ${summary.configuredEndpointCount} bound · ${summary.unconfiguredEndpointCount} unbound`}
|
|
767
|
+
label={scope.path.join(' › ')}
|
|
768
|
+
selected={selected}
|
|
769
|
+
/>
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
type BindingScopePageItemViewProps = {
|
|
774
|
+
readonly item: BindingScopePageItem;
|
|
775
|
+
readonly selected: boolean;
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
function BindingScopePageItemView({
|
|
779
|
+
item,
|
|
780
|
+
selected,
|
|
781
|
+
}: BindingScopePageItemViewProps): React.JSX.Element {
|
|
782
|
+
if (item.type === 'scope') {
|
|
783
|
+
const summary = getBindingSummary([item.scope]);
|
|
784
|
+
|
|
785
|
+
return (
|
|
786
|
+
<ListItem
|
|
787
|
+
details={`${summary.deviceCount} devices · ${summary.unconfiguredEndpointCount} unbound`}
|
|
788
|
+
label={`${item.scope.path.at(-1) ?? '(scope)'} /`}
|
|
789
|
+
selected={selected}
|
|
790
|
+
/>
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const summary = getDeviceSummary(item.device);
|
|
795
|
+
|
|
796
|
+
return (
|
|
797
|
+
<ListItem
|
|
798
|
+
details={`${summary.configuredEndpointCount} bound · ${summary.unconfiguredEndpointCount} unbound`}
|
|
799
|
+
label={getDisplayName(item.device.name, '(default device)')}
|
|
800
|
+
selected={selected}
|
|
801
|
+
/>
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
type BindingProviderItemViewProps = {
|
|
806
|
+
readonly provider: BindingProviderItem;
|
|
807
|
+
readonly selected: boolean;
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
function BindingProviderItemView({
|
|
811
|
+
provider,
|
|
812
|
+
selected,
|
|
813
|
+
}: BindingProviderItemViewProps): React.JSX.Element {
|
|
814
|
+
const details =
|
|
815
|
+
provider.boundEndpointCount === 0
|
|
816
|
+
? undefined
|
|
817
|
+
: `${provider.boundEndpointCount} bound`;
|
|
818
|
+
|
|
819
|
+
return (
|
|
820
|
+
<ListItem
|
|
821
|
+
details={details}
|
|
822
|
+
label={`${provider.namespace} · ${provider.name}`}
|
|
823
|
+
selected={selected}
|
|
824
|
+
/>
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
type ListItemProps = {
|
|
829
|
+
readonly label: string;
|
|
830
|
+
readonly details: string | undefined;
|
|
831
|
+
readonly selected: boolean;
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
function ListItem({
|
|
835
|
+
label,
|
|
836
|
+
details,
|
|
837
|
+
selected,
|
|
838
|
+
}: ListItemProps): React.JSX.Element {
|
|
839
|
+
return (
|
|
840
|
+
<Box>
|
|
841
|
+
<Box width={32}>
|
|
842
|
+
<Text bold={selected} color={selected ? 'cyan' : undefined}>
|
|
843
|
+
{selected ? '› ' : ' '}
|
|
844
|
+
{label}
|
|
845
|
+
</Text>
|
|
846
|
+
</Box>
|
|
847
|
+
|
|
848
|
+
{details === undefined ? null : <Text dimColor>{details}</Text>}
|
|
849
|
+
</Box>
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function getDeviceSummary(device: BindingDeviceItem): BindingSummary {
|
|
854
|
+
let configuredEndpointCount = 0;
|
|
855
|
+
let unconfiguredEndpointCount = 0;
|
|
856
|
+
|
|
857
|
+
for (const endpoint of device.endpoints) {
|
|
858
|
+
if (endpoint.provider !== undefined) {
|
|
859
|
+
configuredEndpointCount++;
|
|
860
|
+
} else {
|
|
861
|
+
unconfiguredEndpointCount++;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return {
|
|
866
|
+
deviceCount: 1,
|
|
867
|
+
configuredEndpointCount,
|
|
868
|
+
unconfiguredEndpointCount,
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
function getBoundEndpoints(
|
|
873
|
+
device: BindingDeviceItem,
|
|
874
|
+
): readonly BoundBindingEndpointItem[] {
|
|
875
|
+
return device.endpoints.filter(
|
|
876
|
+
(endpoint): endpoint is BoundBindingEndpointItem =>
|
|
877
|
+
endpoint.provider !== undefined,
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function getBindingDeviceHint(
|
|
882
|
+
hasProviders: boolean,
|
|
883
|
+
hasBoundEndpoints: boolean,
|
|
884
|
+
): string {
|
|
885
|
+
const actions: string[] = [];
|
|
886
|
+
|
|
887
|
+
if (hasProviders) {
|
|
888
|
+
actions.push('↑↓ select', 'enter');
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
if (hasBoundEndpoints) {
|
|
892
|
+
actions.push('u unbind');
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
actions.push('esc back', 'q menu', 'ctrl+c exit');
|
|
896
|
+
return actions.join(' · ');
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function getBindingsPageHint(
|
|
900
|
+
hasScopes: boolean,
|
|
901
|
+
hasStaleBindings: boolean,
|
|
902
|
+
): string {
|
|
903
|
+
const actions: string[] = [];
|
|
904
|
+
|
|
905
|
+
if (hasScopes) {
|
|
906
|
+
actions.push('↑↓ select', 'enter');
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
if (hasStaleBindings) {
|
|
910
|
+
actions.push('u stale');
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
actions.push('esc back', 'q menu', 'ctrl+c exit');
|
|
914
|
+
return actions.join(' · ');
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
function normalizeCursor(cursor: number, itemCount: number): number {
|
|
918
|
+
return itemCount === 0 ? 0 : Math.min(cursor, itemCount - 1);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function countBindingsForPath(
|
|
922
|
+
bindings: readonly StaleBindingItem[],
|
|
923
|
+
path: EndpointPath,
|
|
924
|
+
): number {
|
|
925
|
+
const pathKey = getEndpointPathKey(path);
|
|
926
|
+
|
|
927
|
+
return bindings.filter(
|
|
928
|
+
binding => getEndpointPathKey(binding.path) === pathKey,
|
|
929
|
+
).length;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
function getStaleBindingKey(binding: StaleBindingItem, index: number): string {
|
|
933
|
+
return JSON.stringify([
|
|
934
|
+
binding.path.scopePath,
|
|
935
|
+
binding.path.deviceName,
|
|
936
|
+
binding.path.endpointName,
|
|
937
|
+
binding.provider.namespace,
|
|
938
|
+
binding.provider.name,
|
|
939
|
+
index,
|
|
940
|
+
]);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function getEndpointPathKey(path: EndpointPath): string {
|
|
944
|
+
return JSON.stringify([path.scopePath, path.deviceName, path.endpointName]);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function formatEndpointPath(path: EndpointPath): string {
|
|
948
|
+
return [
|
|
949
|
+
...path.scopePath,
|
|
950
|
+
getDisplayName(path.deviceName, '(default device)'),
|
|
951
|
+
getDisplayName(path.endpointName, '(default endpoint)'),
|
|
952
|
+
].join(' › ');
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function getScopeKey(scope: BindingScopeItem): string {
|
|
956
|
+
return JSON.stringify(scope.path);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
function getBindingScopePageItemKey(item: BindingScopePageItem): string {
|
|
960
|
+
if (item.type === 'scope') {
|
|
961
|
+
return `scope:${getScopeKey(item.scope)}`;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
return `device:${item.device.name}`;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function getProviderKey(provider: BindingProviderItem): string {
|
|
968
|
+
return JSON.stringify([provider.namespace, provider.name]);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
function getDevicePageTitle(
|
|
972
|
+
scopePath: readonly string[],
|
|
973
|
+
deviceName: string,
|
|
974
|
+
): string {
|
|
975
|
+
return `bindings › ${[
|
|
976
|
+
...scopePath,
|
|
977
|
+
getDisplayName(deviceName, '(default device)'),
|
|
978
|
+
].join(' › ')}`;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function getDisplayName(name: string, fallback: string): string {
|
|
982
|
+
return name === '' ? fallback : name;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
function getErrorMessage(error: unknown): string {
|
|
986
|
+
return error instanceof Error ? error.message : String(error);
|
|
987
|
+
}
|