@neurodevs/node-tdd 1.0.6 → 1.0.7
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/package.json +1 -1
- package/.nvmrc +0 -1
- package/.vscode/launch.json +0 -53
- package/.vscode/settings.json +0 -62
- package/.vscode/tasks.json +0 -99
- package/build/__tests__/MockFetch.d.ts +0 -18
- package/build/__tests__/MockFetch.js +0 -55
- package/build/__tests__/MockFetch.js.map +0 -1
- package/build/__tests__/behavioral/AbstractModuleTest.test.d.ts +0 -5
- package/build/__tests__/behavioral/AbstractModuleTest.test.js +0 -22
- package/build/__tests__/behavioral/AbstractModuleTest.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.d.ts +0 -5
- package/build/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.js +0 -34
- package/build/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/Assert.test.d.ts +0 -45
- package/build/__tests__/behavioral/utilities/Assert.test.js +0 -645
- package/build/__tests__/behavioral/utilities/Assert.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.d.ts +0 -4
- package/build/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.js +0 -23
- package/build/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/MockFetch.test.d.ts +0 -28
- package/build/__tests__/behavioral/utilities/MockFetch.test.js +0 -211
- package/build/__tests__/behavioral/utilities/MockFetch.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/StackCleaner.test.d.ts +0 -4
- package/build/__tests__/behavioral/utilities/StackCleaner.test.js +0 -46
- package/build/__tests__/behavioral/utilities/StackCleaner.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.d.ts +0 -7
- package/build/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.js +0 -32
- package/build/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.d.ts +0 -4
- package/build/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.js +0 -19
- package/build/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/Stringify.test.d.ts +0 -5
- package/build/__tests__/behavioral/utilities/Stringify.test.js +0 -127
- package/build/__tests__/behavioral/utilities/Stringify.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestDecoratorResolver.test.d.ts +0 -7
- package/build/__tests__/behavioral/utilities/TestDecoratorResolver.test.js +0 -38
- package/build/__tests__/behavioral/utilities/TestDecoratorResolver.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestOnBasic.test.d.ts +0 -12
- package/build/__tests__/behavioral/utilities/TestOnBasic.test.js +0 -68
- package/build/__tests__/behavioral/utilities/TestOnBasic.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestOnInstance.test.d.ts +0 -28
- package/build/__tests__/behavioral/utilities/TestOnInstance.test.js +0 -289
- package/build/__tests__/behavioral/utilities/TestOnInstance.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.d.ts +0 -9
- package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.js +0 -118
- package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.d.ts +0 -5
- package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.js +0 -78
- package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.d.ts +0 -4
- package/build/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.js +0 -23
- package/build/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.d.ts +0 -4
- package/build/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.js +0 -24
- package/build/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestResolver.test.d.ts +0 -7
- package/build/__tests__/behavioral/utilities/TestResolver.test.js +0 -38
- package/build/__tests__/behavioral/utilities/TestResolver.test.js.map +0 -1
- package/build/__tests__/behavioral/utilities/TestResolverOnStatic.test.d.ts +0 -4
- package/build/__tests__/behavioral/utilities/TestResolverOnStatic.test.js +0 -20
- package/build/__tests__/behavioral/utilities/TestResolverOnStatic.test.js.map +0 -1
- package/build/__tests__/behavioral/workspace/JestJsonParser.test.d.ts +0 -18
- package/build/__tests__/behavioral/workspace/JestJsonParser.test.js +0 -267
- package/build/__tests__/behavioral/workspace/JestJsonParser.test.js.map +0 -1
- package/build/__tests__/behavioral/workspace/TestReporter.test.d.ts +0 -27
- package/build/__tests__/behavioral/workspace/TestReporter.test.js +0 -508
- package/build/__tests__/behavioral/workspace/TestReporter.test.js.map +0 -1
- package/build/__tests__/behavioral/workspace/TestRunner.test.d.ts +0 -15
- package/build/__tests__/behavioral/workspace/TestRunner.test.js +0 -99
- package/build/__tests__/behavioral/workspace/TestRunner.test.js.map +0 -1
- package/build/__tests__/behavioral/workspace/Widgets.test.d.ts +0 -16
- package/build/__tests__/behavioral/workspace/Widgets.test.js +0 -134
- package/build/__tests__/behavioral/workspace/Widgets.test.js.map +0 -1
- package/build/__tests__/mock-terminal-kit.d.ts +0 -79
- package/build/__tests__/mock-terminal-kit.js +0 -103
- package/build/__tests__/mock-terminal-kit.js.map +0 -1
- package/build/__tests__/support/AbstractForInstanceTest.d.ts +0 -4
- package/build/__tests__/support/AbstractForInstanceTest.js +0 -9
- package/build/__tests__/support/AbstractForInstanceTest.js.map +0 -1
- package/build/__tests__/support/AbstractLevelOneTest.d.ts +0 -3
- package/build/__tests__/support/AbstractLevelOneTest.js +0 -4
- package/build/__tests__/support/AbstractLevelOneTest.js.map +0 -1
- package/build/__tests__/support/AbstractLevelTwoTest.d.ts +0 -7
- package/build/__tests__/support/AbstractLevelTwoTest.js +0 -14
- package/build/__tests__/support/AbstractLevelTwoTest.js.map +0 -1
- package/build/__tests__/support/AbstractStaticTest.d.ts +0 -7
- package/build/__tests__/support/AbstractStaticTest.js +0 -14
- package/build/__tests__/support/AbstractStaticTest.js.map +0 -1
- package/build/__tests__/support/AbstractTestOnInstanceTest.d.ts +0 -22
- package/build/__tests__/support/AbstractTestOnInstanceTest.js +0 -23
- package/build/__tests__/support/AbstractTestOnInstanceTest.js.map +0 -1
- package/build/__tests__/support/AbstractTestOnInstanceWithHooks.d.ts +0 -26
- package/build/__tests__/support/AbstractTestOnInstanceWithHooks.js +0 -59
- package/build/__tests__/support/AbstractTestOnInstanceWithHooks.js.map +0 -1
- package/build/__tests__/support/jest.setup.d.ts +0 -1
- package/build/__tests__/support/jest.setup.js +0 -4
- package/build/__tests__/support/jest.setup.js.map +0 -1
- package/build/__tests__/support/onTestFileResult.d.ts +0 -244
- package/build/__tests__/support/onTestFileResult.js +0 -980
- package/build/__tests__/support/onTestFileResult.js.map +0 -1
- package/eslint.config.js +0 -3
- package/prettier.config.js +0 -3
- package/src/.spruce/settings.json +0 -4
- package/src/__tests__/MockFetch.ts +0 -100
- package/src/__tests__/behavioral/AbstractModuleTest.test.ts +0 -15
- package/src/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.ts +0 -31
- package/src/__tests__/behavioral/utilities/Assert.test.ts +0 -826
- package/src/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.ts +0 -14
- package/src/__tests__/behavioral/utilities/MockFetch.test.ts +0 -240
- package/src/__tests__/behavioral/utilities/StackCleaner.test.ts +0 -46
- package/src/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.ts +0 -34
- package/src/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.ts +0 -11
- package/src/__tests__/behavioral/utilities/Stringify.test.ts +0 -169
- package/src/__tests__/behavioral/utilities/TestDecoratorResolver.test.ts +0 -51
- package/src/__tests__/behavioral/utilities/TestOnBasic.test.ts +0 -62
- package/src/__tests__/behavioral/utilities/TestOnInstance.test.ts +0 -439
- package/src/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.ts +0 -237
- package/src/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.ts +0 -85
- package/src/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.ts +0 -14
- package/src/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.ts +0 -16
- package/src/__tests__/behavioral/utilities/TestResolver.test.ts +0 -48
- package/src/__tests__/behavioral/utilities/TestResolverOnStatic.test.ts +0 -12
- package/src/__tests__/behavioral/workspace/JestJsonParser.test.ts +0 -357
- package/src/__tests__/behavioral/workspace/TestReporter.test.ts +0 -584
- package/src/__tests__/behavioral/workspace/TestRunner.test.ts +0 -87
- package/src/__tests__/behavioral/workspace/Widgets.test.ts +0 -131
- package/src/__tests__/mock-terminal-kit.ts +0 -115
- package/src/__tests__/support/AbstractForInstanceTest.ts +0 -12
- package/src/__tests__/support/AbstractLevelOneTest.ts +0 -3
- package/src/__tests__/support/AbstractLevelTwoTest.ts +0 -16
- package/src/__tests__/support/AbstractStaticTest.ts +0 -16
- package/src/__tests__/support/AbstractTestOnInstanceTest.ts +0 -30
- package/src/__tests__/support/AbstractTestOnInstanceWithHooks.ts +0 -138
- package/src/__tests__/support/jest.setup.ts +0 -2
- package/src/__tests__/support/onTestFileResult.ts +0 -1008
- package/src/impl/AbstractModuleTest.ts +0 -67
- package/src/index.ts +0 -12
- package/src/utilities/AssertionError.ts +0 -14
- package/src/utilities/StackCleaner.ts +0 -14
- package/src/utilities/TestDecoratorResolver.ts +0 -118
- package/src/utilities/assert.ts +0 -583
- package/src/utilities/assert.utility.ts +0 -295
- package/src/utilities/decorators.ts +0 -167
- package/src/workspace/CommandService.ts +0 -256
- package/src/workspace/JestJsonParser.ts +0 -255
- package/src/workspace/TKButtonWidget.ts +0 -54
- package/src/workspace/TestLogItemGenerator.ts +0 -184
- package/src/workspace/TestReporter.ts +0 -880
- package/src/workspace/TestRunner.ts +0 -128
- package/src/workspace/TkBaseWidget.ts +0 -249
- package/src/workspace/TkInputWidget.ts +0 -83
- package/src/workspace/TkLayoutCellWidget.ts +0 -46
- package/src/workspace/TkLayoutWidget.ts +0 -181
- package/src/workspace/TkMenuBarWidget.ts +0 -95
- package/src/workspace/TkPopupWidget.ts +0 -47
- package/src/workspace/TkProgressBarWidget.ts +0 -54
- package/src/workspace/TkTextWidget.ts +0 -167
- package/src/workspace/TkWindowWidget.ts +0 -122
- package/src/workspace/WidgetFactory.ts +0 -33
- package/src/workspace/button.types.ts +0 -19
- package/src/workspace/duration.utility.ts +0 -34
- package/src/workspace/factory.types.ts +0 -101
- package/src/workspace/input.types.ts +0 -22
- package/src/workspace/keySelectChoices.ts +0 -134
- package/src/workspace/layout.types.ts +0 -40
- package/src/workspace/menuBar.types.ts +0 -24
- package/src/workspace/popup.types.ts +0 -17
- package/src/workspace/progressBar.types.ts +0 -13
- package/src/workspace/table.types.ts +0 -9
- package/src/workspace/termKit.utility.ts +0 -130
- package/src/workspace/terminal-kit.d.ts +0 -28
- package/src/workspace/test.types.ts +0 -34
- package/src/workspace/testRunner.cli.ts +0 -166
- package/src/workspace/text.types.ts +0 -27
- package/src/workspace/widget.utilities.ts +0 -35
- package/src/workspace/widgets.types.ts +0 -102
- package/src/workspace/window.types.ts +0 -22
- package/tsconfig.json +0 -24
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import pathUtil from 'path'
|
|
3
|
-
import { EventEmitter } from 'events'
|
|
4
|
-
import CommandServiceImpl from './CommandService.js'
|
|
5
|
-
import JestJsonParser from './JestJsonParser.js'
|
|
6
|
-
import { TestResults } from './test.types.js'
|
|
7
|
-
|
|
8
|
-
export default class TestRunner extends EventEmitter {
|
|
9
|
-
private cwd: string
|
|
10
|
-
private commandService: CommandServiceImpl
|
|
11
|
-
private wasKilled = false
|
|
12
|
-
private testResults: TestResults = { totalTestFiles: 0 }
|
|
13
|
-
|
|
14
|
-
public constructor(options: {
|
|
15
|
-
cwd: string
|
|
16
|
-
commandService: CommandServiceImpl
|
|
17
|
-
}) {
|
|
18
|
-
super()
|
|
19
|
-
this.cwd = options.cwd
|
|
20
|
-
this.commandService = options.commandService
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async run(options?: {
|
|
24
|
-
pattern?: string | null
|
|
25
|
-
debugPort?: number | null
|
|
26
|
-
}): Promise<TestResults & { wasKilled: boolean }> {
|
|
27
|
-
this.wasKilled = false
|
|
28
|
-
|
|
29
|
-
const jestPath = this.resolvePathToJest()
|
|
30
|
-
const debugArgs =
|
|
31
|
-
(options?.debugPort ?? 0) > 0
|
|
32
|
-
? `--inspect=${options?.debugPort}`
|
|
33
|
-
: ``
|
|
34
|
-
const pattern = options?.pattern ?? ''
|
|
35
|
-
const escapeShell = function (cmd: string) {
|
|
36
|
-
return (
|
|
37
|
-
'--testPathPatterns="' +
|
|
38
|
-
cmd.replace(/(["\s'$`\\])/g, '\\$1') +
|
|
39
|
-
'"'
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
const command = `node --experimental-vm-modules --unhandled-rejections=strict ${debugArgs} ${jestPath} --reporters="@sprucelabs/jest-json-reporter" --testRunner="jest-circus/runner" --passWithNoTests ${
|
|
43
|
-
pattern ? escapeShell(pattern) : ''
|
|
44
|
-
}`
|
|
45
|
-
|
|
46
|
-
const parser = new JestJsonParser()
|
|
47
|
-
|
|
48
|
-
this.testResults = {
|
|
49
|
-
totalTestFiles: 0,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
await this.commandService.execute(command, {
|
|
54
|
-
forceColor: true,
|
|
55
|
-
env: { NODE_NO_WARNINGS: '1' },
|
|
56
|
-
onError: async (data) => {
|
|
57
|
-
const isDebugMessaging = this.isDebugMessage(data)
|
|
58
|
-
|
|
59
|
-
if (!isDebugMessaging) {
|
|
60
|
-
this.emit('did-error', { message: data })
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
onData: async (data) => {
|
|
64
|
-
try {
|
|
65
|
-
parser.write(data)
|
|
66
|
-
this.testResults = parser.getResults()
|
|
67
|
-
this.emit('did-update', { results: this.testResults })
|
|
68
|
-
} catch (err) {
|
|
69
|
-
this.emit('did-error', {
|
|
70
|
-
message: `Parser error: ${err}`,
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
} catch (err) {
|
|
76
|
-
if (!this.testResults.totalTestFiles) {
|
|
77
|
-
throw err
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return { ...this.testResults, wasKilled: this.wasKilled }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private isDebugMessage(data: string) {
|
|
85
|
-
return (
|
|
86
|
-
data.search(/^ attached/i) === 0 ||
|
|
87
|
-
data.search(/^ listening/i) === 0 ||
|
|
88
|
-
data.search(/^waiting for the /i) === 0
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public hasFailedTests() {
|
|
93
|
-
return (this.testResults.totalFailed ?? 0) > 0
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public hasSkippedTests() {
|
|
97
|
-
return (this.testResults.totalSkipped ?? 0) > 0
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public kill() {
|
|
101
|
-
this.wasKilled = true
|
|
102
|
-
this.commandService.kill()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private resolvePathToJest() {
|
|
106
|
-
const jestBin = pathUtil.join('node_modules', '.bin', 'jest')
|
|
107
|
-
const fullCwd = pathUtil.resolve(this.cwd)
|
|
108
|
-
const pathParts = fullCwd.split(pathUtil.sep).filter(Boolean)
|
|
109
|
-
|
|
110
|
-
while (pathParts.length > 0) {
|
|
111
|
-
const candidate =
|
|
112
|
-
pathUtil.sep +
|
|
113
|
-
pathUtil.join(...pathParts) +
|
|
114
|
-
pathUtil.sep +
|
|
115
|
-
jestBin
|
|
116
|
-
|
|
117
|
-
if (fs.existsSync(candidate)) {
|
|
118
|
-
return candidate
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
pathParts.pop()
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
throw new Error(
|
|
125
|
-
`Could not find jest binary. Make sure jest is installed in ${this.cwd}`
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events'
|
|
2
|
-
import { Terminal } from 'terminal-kit'
|
|
3
|
-
import {
|
|
4
|
-
BaseWidget,
|
|
5
|
-
EventContract,
|
|
6
|
-
UniversalWidgetOptions,
|
|
7
|
-
WidgetFrame,
|
|
8
|
-
WidgetFrameCalculated,
|
|
9
|
-
WidgetPadding,
|
|
10
|
-
} from './widgets.types.js'
|
|
11
|
-
|
|
12
|
-
export type BaseWidgetWithTermKitAddons = BaseWidget & {
|
|
13
|
-
getTermKitElement: () => any | null
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type TkWidgetOptions = UniversalWidgetOptions & {
|
|
17
|
-
term: Terminal
|
|
18
|
-
parent: BaseWidgetWithTermKitAddons
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default abstract class TkBaseWidget<Contract extends EventContract = any>
|
|
22
|
-
extends EventEmitter
|
|
23
|
-
implements BaseWidget<Contract>
|
|
24
|
-
{
|
|
25
|
-
public type = 'abstract'
|
|
26
|
-
protected parent: BaseWidgetWithTermKitAddons | null
|
|
27
|
-
protected term: Terminal
|
|
28
|
-
private id: string | null
|
|
29
|
-
private children: BaseWidget[] = []
|
|
30
|
-
protected shouldLockWidthWithParent = false
|
|
31
|
-
protected shouldLockHeightWithParent = false
|
|
32
|
-
protected shouldLockRightWithParent = false
|
|
33
|
-
protected shouldLockBottomWithParent = false
|
|
34
|
-
protected padding: WidgetPadding = {}
|
|
35
|
-
private frameLockDeltas: {
|
|
36
|
-
leftDelta: number
|
|
37
|
-
widthDelta: number
|
|
38
|
-
topDelta: number
|
|
39
|
-
heightDelta: number
|
|
40
|
-
rightDelta: number
|
|
41
|
-
bottomDelta: number
|
|
42
|
-
} = {
|
|
43
|
-
leftDelta: 0,
|
|
44
|
-
widthDelta: 0,
|
|
45
|
-
topDelta: 0,
|
|
46
|
-
heightDelta: 0,
|
|
47
|
-
rightDelta: 0,
|
|
48
|
-
bottomDelta: 0,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public constructor(options: TkWidgetOptions) {
|
|
52
|
-
super()
|
|
53
|
-
|
|
54
|
-
this.parent = options.parent ?? null
|
|
55
|
-
this.term = options.term
|
|
56
|
-
this.id = options.id ?? null
|
|
57
|
-
this.shouldLockHeightWithParent =
|
|
58
|
-
options.shouldLockHeightWithParent ?? false
|
|
59
|
-
this.shouldLockWidthWithParent =
|
|
60
|
-
options.shouldLockWidthWithParent ?? false
|
|
61
|
-
this.shouldLockRightWithParent =
|
|
62
|
-
options.shouldLockRightWithParent ?? false
|
|
63
|
-
this.shouldLockBottomWithParent =
|
|
64
|
-
options.shouldLockBottomWithParent ?? false
|
|
65
|
-
|
|
66
|
-
this.padding = {
|
|
67
|
-
left: 0,
|
|
68
|
-
top: 0,
|
|
69
|
-
right: 0,
|
|
70
|
-
bottom: 0,
|
|
71
|
-
...options.padding,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (this.parent) {
|
|
75
|
-
this.parent.addChild(this as TkBaseWidget)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public getChildren(): BaseWidget[] {
|
|
80
|
-
return this.children
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public addChild(child: BaseWidget): void {
|
|
84
|
-
this.children.push(child)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public getId(): string | null {
|
|
88
|
-
return this.id
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public getParent(): BaseWidget | null {
|
|
92
|
-
return this.parent
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public getFrame(): WidgetFrameCalculated {
|
|
96
|
-
const element = this.getTermKitElement()
|
|
97
|
-
if (element) {
|
|
98
|
-
return {
|
|
99
|
-
left: element.outputX,
|
|
100
|
-
top: element.outputY,
|
|
101
|
-
width: element.outputWidth,
|
|
102
|
-
height: element.outputHeight,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
throw new Error(
|
|
106
|
-
element
|
|
107
|
-
? `${this.type} does not implement getFrame()`
|
|
108
|
-
: `${this.type} does not implement getTermKitElement()`
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public setFrame(frame: Partial<WidgetFrame>): void {
|
|
113
|
-
const element = this.getTermKitElement()
|
|
114
|
-
|
|
115
|
-
if (element) {
|
|
116
|
-
if (element.resize) {
|
|
117
|
-
element.resize({
|
|
118
|
-
x: frame.left,
|
|
119
|
-
y: frame.top,
|
|
120
|
-
width: frame.width,
|
|
121
|
-
height: frame.height,
|
|
122
|
-
})
|
|
123
|
-
} else {
|
|
124
|
-
element.outputX = frame.left ?? element.outputX
|
|
125
|
-
element.outputY = frame.top ?? element.outputY
|
|
126
|
-
element.outputWidth = frame.width ?? element.outputWidth
|
|
127
|
-
element.outputHeight = frame.height ?? element.outputHeight
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.sizeLockedChildren()
|
|
131
|
-
|
|
132
|
-
element.draw()
|
|
133
|
-
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
throw new Error(`${this.type} does not implement getTermKitElement()`)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected sizeLockedChildren() {
|
|
141
|
-
const newFrame = this.getFrame()
|
|
142
|
-
for (const child of this.children as TkBaseWidget[]) {
|
|
143
|
-
child.handleParentResize(newFrame)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
public getChildById(id?: string): BaseWidget | null {
|
|
148
|
-
for (const child of this.getChildren()) {
|
|
149
|
-
if (child.getId() === id) {
|
|
150
|
-
return child
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return null
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public removeChild(child: BaseWidget) {
|
|
158
|
-
this.children = this.children.filter((c) => c !== child)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
protected handleParentResize(parentFrame: WidgetFrameCalculated): void {
|
|
162
|
-
const updatedFrame = this.getFrame()
|
|
163
|
-
let shouldSetFrame = false
|
|
164
|
-
|
|
165
|
-
if (this.shouldLockHeightWithParent) {
|
|
166
|
-
shouldSetFrame = true
|
|
167
|
-
updatedFrame.height =
|
|
168
|
-
parentFrame.height - this.frameLockDeltas.heightDelta
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (this.shouldLockWidthWithParent) {
|
|
172
|
-
shouldSetFrame = true
|
|
173
|
-
updatedFrame.width =
|
|
174
|
-
parentFrame.width - this.frameLockDeltas.widthDelta
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (this.shouldLockRightWithParent) {
|
|
178
|
-
shouldSetFrame = true
|
|
179
|
-
updatedFrame.left =
|
|
180
|
-
parentFrame.width -
|
|
181
|
-
this.frameLockDeltas.rightDelta -
|
|
182
|
-
updatedFrame.width
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (this.shouldLockBottomWithParent) {
|
|
186
|
-
shouldSetFrame = true
|
|
187
|
-
updatedFrame.top =
|
|
188
|
-
parentFrame.height -
|
|
189
|
-
updatedFrame.height -
|
|
190
|
-
this.frameLockDeltas.bottomDelta
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (shouldSetFrame) {
|
|
194
|
-
this.setFrame(updatedFrame)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
public async destroy() {
|
|
199
|
-
this.getTermKitElement()?.destroy()
|
|
200
|
-
this.getParent()?.removeChild(this as BaseWidget)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
public getTermKitElement(): any | null {
|
|
204
|
-
return null
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
protected calculateSizeLockDeltas() {
|
|
208
|
-
const frame = this.getFrame()
|
|
209
|
-
const parentFrame = this.getParent()?.getFrame()
|
|
210
|
-
|
|
211
|
-
if (!parentFrame) {
|
|
212
|
-
return
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
let leftDelta = 0
|
|
216
|
-
let widthDelta = 0
|
|
217
|
-
let topDelta = 0
|
|
218
|
-
let heightDelta = 0
|
|
219
|
-
let rightDelta = 0
|
|
220
|
-
let bottomDelta = 0
|
|
221
|
-
|
|
222
|
-
if (this.shouldLockWidthWithParent) {
|
|
223
|
-
leftDelta = frame.left
|
|
224
|
-
widthDelta = parentFrame.width - frame.width
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (this.shouldLockHeightWithParent) {
|
|
228
|
-
topDelta = frame.top
|
|
229
|
-
heightDelta = parentFrame.height - frame.height
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (this.shouldLockRightWithParent) {
|
|
233
|
-
rightDelta = frame.left + frame.width - parentFrame.width
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (this.shouldLockBottomWithParent) {
|
|
237
|
-
bottomDelta = parentFrame.height - (frame.top + frame.height)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
this.frameLockDeltas = {
|
|
241
|
-
leftDelta,
|
|
242
|
-
widthDelta,
|
|
243
|
-
topDelta,
|
|
244
|
-
heightDelta,
|
|
245
|
-
rightDelta,
|
|
246
|
-
bottomDelta,
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import terminal_kit from 'terminal-kit'
|
|
3
|
-
import { InputWidget, InputWidgetOptions } from './input.types.js'
|
|
4
|
-
import { WidgetFrame } from './widgets.types.js'
|
|
5
|
-
import widgetUtil from './widget.utilities.js'
|
|
6
|
-
import termKitUtil from './termKit.utility.js'
|
|
7
|
-
import TkBaseWidget, { TkWidgetOptions } from './TkBaseWidget.js'
|
|
8
|
-
const termKit = terminal_kit as any
|
|
9
|
-
|
|
10
|
-
export default class TkInputWidget extends TkBaseWidget implements InputWidget {
|
|
11
|
-
public readonly type = 'input'
|
|
12
|
-
|
|
13
|
-
private input: any
|
|
14
|
-
|
|
15
|
-
public constructor(
|
|
16
|
-
options: TkWidgetOptions & InputWidgetOptions & { termKitElement: any }
|
|
17
|
-
) {
|
|
18
|
-
super(options)
|
|
19
|
-
|
|
20
|
-
const frame = termKitUtil.buildFrame(options, options.parent)
|
|
21
|
-
|
|
22
|
-
const { parent, ...rest } = options
|
|
23
|
-
|
|
24
|
-
this.input = new termKit.InlineInput({
|
|
25
|
-
parent: parent ? parent.getTermKitElement() : undefined,
|
|
26
|
-
textAttr: { bgColor: 'black', color: 'yellow' },
|
|
27
|
-
voidAttr: { bgColor: 'black', color: 'yellow' },
|
|
28
|
-
placeholder: options.placeholder
|
|
29
|
-
? chalk.italic.black(options.placeholder)
|
|
30
|
-
: undefined,
|
|
31
|
-
placeholderHasMarkup: true,
|
|
32
|
-
prompt: {
|
|
33
|
-
content: options.label ? `${options.label} > ` : undefined,
|
|
34
|
-
contentHasMarkup: true,
|
|
35
|
-
},
|
|
36
|
-
cancelable: true,
|
|
37
|
-
...rest,
|
|
38
|
-
...frame,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
this.input.__widget = this
|
|
42
|
-
this.input.on('submit', this.handleSubmit.bind(this))
|
|
43
|
-
this.input.on('cancel', this.handleCancel.bind(this))
|
|
44
|
-
|
|
45
|
-
this.calculateSizeLockDeltas()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public setFrame(frame: WidgetFrame) {
|
|
49
|
-
const oldFrame = this.getFrame()
|
|
50
|
-
const newFrame = widgetUtil.buildFrame(frame, this.parent)
|
|
51
|
-
|
|
52
|
-
this.input.setSizeAndPosition({
|
|
53
|
-
x: newFrame.left ?? oldFrame.left,
|
|
54
|
-
y: newFrame.top ?? oldFrame.top,
|
|
55
|
-
width: newFrame.width ?? oldFrame.width,
|
|
56
|
-
height: newFrame.height ?? oldFrame.height,
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
this.input.draw()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private async handleCancel() {
|
|
63
|
-
await (this as InputWidget).emit('cancel')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private async handleSubmit() {
|
|
67
|
-
await (this as InputWidget).emit('submit', {
|
|
68
|
-
value: this.getValue(),
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public getValue(): string | undefined {
|
|
73
|
-
return this.input.getValue()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public setValue(value: string): void {
|
|
77
|
-
this.input.setContent(value)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public getTermKitElement() {
|
|
81
|
-
return this.input
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { LayoutCellWidget, LayoutCellWidgetOptions } from './layout.types.js'
|
|
2
|
-
import TkBaseWidget, { TkWidgetOptions } from './TkBaseWidget.js'
|
|
3
|
-
|
|
4
|
-
export default class TkLayoutCellWidget
|
|
5
|
-
extends TkBaseWidget
|
|
6
|
-
implements LayoutCellWidget
|
|
7
|
-
{
|
|
8
|
-
public readonly type = 'layoutCell'
|
|
9
|
-
|
|
10
|
-
private cell: any
|
|
11
|
-
|
|
12
|
-
public constructor(
|
|
13
|
-
options: TkWidgetOptions &
|
|
14
|
-
LayoutCellWidgetOptions & { termKitElement: any }
|
|
15
|
-
) {
|
|
16
|
-
super({
|
|
17
|
-
shouldLockHeightWithParent: true,
|
|
18
|
-
shouldLockWidthWithParent: true,
|
|
19
|
-
...options,
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
this.cell = options.termKitElement
|
|
23
|
-
this.cell.__widget = this
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getId() {
|
|
27
|
-
return this.cell.id
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public getTermKitElement() {
|
|
31
|
-
return this.cell
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public getFrame() {
|
|
35
|
-
return {
|
|
36
|
-
left: this.cell.outputDst.x,
|
|
37
|
-
top: this.cell.outputDst.y,
|
|
38
|
-
width: this.cell.inputWidth,
|
|
39
|
-
height: this.cell.inputHeight,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public setFrame() {
|
|
44
|
-
this.sizeLockedChildren()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import terminal_kit from 'terminal-kit'
|
|
2
|
-
import {
|
|
3
|
-
LayoutColumn,
|
|
4
|
-
LayoutRow,
|
|
5
|
-
LayoutWidget,
|
|
6
|
-
LayoutWidgetOptions,
|
|
7
|
-
} from './layout.types.js'
|
|
8
|
-
import { WidgetFrameAttribute, WidgetFrame } from './widgets.types.js'
|
|
9
|
-
import termKitUtil from './termKit.utility.js'
|
|
10
|
-
import TkBaseWidget, { TkWidgetOptions } from './TkBaseWidget.js'
|
|
11
|
-
import TkLayoutCellWidget from './TkLayoutCellWidget.js'
|
|
12
|
-
const termKit = terminal_kit as any
|
|
13
|
-
|
|
14
|
-
export default class TkLayoutWidget
|
|
15
|
-
extends TkBaseWidget
|
|
16
|
-
implements LayoutWidget
|
|
17
|
-
{
|
|
18
|
-
public readonly type = 'layout'
|
|
19
|
-
|
|
20
|
-
private layout: any
|
|
21
|
-
|
|
22
|
-
public constructor(options: TkWidgetOptions & LayoutWidgetOptions) {
|
|
23
|
-
super(options)
|
|
24
|
-
|
|
25
|
-
const mappedOptions =
|
|
26
|
-
termKitUtil.mapWidgetOptionsToTermKitOptions(options)
|
|
27
|
-
|
|
28
|
-
const { parent, ...layout } = mappedOptions
|
|
29
|
-
|
|
30
|
-
if (!parent) {
|
|
31
|
-
throw new Error('Missing required parameter: parent')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
this.layout = new termKit.Layout({
|
|
35
|
-
parent,
|
|
36
|
-
layout,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
this.layout.__widget = this
|
|
40
|
-
this.layout.off('parentResize', this.layout.onParentResize)
|
|
41
|
-
|
|
42
|
-
this.calculateSizeLockDeltas()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public getChildren() {
|
|
46
|
-
return this.layout.zChildren.map((child: any) => {
|
|
47
|
-
return new TkLayoutCellWidget({
|
|
48
|
-
term: this.term,
|
|
49
|
-
termKitElement: child,
|
|
50
|
-
parent: this,
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public getTermKitElement() {
|
|
56
|
-
return this.layout
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public getFrame() {
|
|
60
|
-
return {
|
|
61
|
-
left: this.layout.computed.xmin,
|
|
62
|
-
top: this.layout.computed.ymin,
|
|
63
|
-
width: this.layout.computed.width,
|
|
64
|
-
height: this.layout.computed.height,
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public async destroy() {
|
|
69
|
-
this.layout.destroy()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public setFrame(frame: Partial<WidgetFrame>) {
|
|
73
|
-
const calculated = termKitUtil.buildFrame(frame, this.parent)
|
|
74
|
-
const def = this.layout.layoutDef
|
|
75
|
-
|
|
76
|
-
delete def.height
|
|
77
|
-
delete def.heightPercent
|
|
78
|
-
|
|
79
|
-
this.layout.layoutDef.height = calculated.height
|
|
80
|
-
|
|
81
|
-
this.handleResize()
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private handleResize() {
|
|
85
|
-
this.layout.computeBoundingBoxes()
|
|
86
|
-
this.layout.draw()
|
|
87
|
-
|
|
88
|
-
this.sizeLockedChildren()
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public getRows(): LayoutRow[] {
|
|
92
|
-
const rows = this.layout.layoutDef.rows
|
|
93
|
-
const layoutRows = this.termKitRowsToLayoutRows(rows)
|
|
94
|
-
|
|
95
|
-
return layoutRows
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private termKitRowsToLayoutRows(rows: any): LayoutRow[] {
|
|
99
|
-
return rows.map((row: any) => ({
|
|
100
|
-
...termKitUtil.mapTermKitOptionsToWidgetOptions(row),
|
|
101
|
-
columns: this.termKitColumnsToLayoutColumns(row.columns),
|
|
102
|
-
}))
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private termKitColumnsToLayoutColumns(columns: any) {
|
|
106
|
-
return columns.map((col: any) =>
|
|
107
|
-
termKitUtil.mapTermKitOptionsToWidgetOptions(col)
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public addRow(row: LayoutRow): void {
|
|
112
|
-
this.layout.layoutDef.rows.push({
|
|
113
|
-
...termKitUtil.mapWidgetOptionsToTermKitOptions(row),
|
|
114
|
-
columns: this.widgetColumnsToTermKitColumns(row.columns),
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public removeRow(rowIdx: number): void {
|
|
119
|
-
this.layout.layoutDef.rows.splice(rowIdx, 1)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public removeColumn(rowIdx: number, columnIdx: number): void {
|
|
123
|
-
const row = this.layout.layoutDef.rows[rowIdx]
|
|
124
|
-
if (row) {
|
|
125
|
-
row.columns.splice(columnIdx, 1)
|
|
126
|
-
} else {
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Can't add remove column because row at index ${rowIdx} does not exist.`
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public addColumn(rowIdx: number, column: LayoutColumn): void {
|
|
134
|
-
if (this.layout.layoutDef.rows[rowIdx]) {
|
|
135
|
-
this.layout.layoutDef.rows[rowIdx].columns.push({
|
|
136
|
-
...termKitUtil.mapWidgetOptionsToTermKitOptions(column),
|
|
137
|
-
})
|
|
138
|
-
} else {
|
|
139
|
-
throw new Error(
|
|
140
|
-
`Can't add column because row at index ${rowIdx} does not exist.`
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public setColumnWidth(options: {
|
|
146
|
-
rowIdx: number
|
|
147
|
-
columnIdx: number
|
|
148
|
-
width: WidgetFrameAttribute
|
|
149
|
-
}): void {
|
|
150
|
-
const { rowIdx, columnIdx, width } = options
|
|
151
|
-
|
|
152
|
-
const col = this.layout.layoutDef.rows[rowIdx]?.columns[columnIdx]
|
|
153
|
-
if (col) {
|
|
154
|
-
this.layout.layoutDef.rows[rowIdx].columns[columnIdx] = {
|
|
155
|
-
...col,
|
|
156
|
-
...termKitUtil.mapWidgetOptionsToTermKitOptions({ width }),
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
throw new Error(
|
|
160
|
-
`Can't add set column width because column ${columnIdx} at row ${rowIdx} does not exist.`
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private widgetColumnsToTermKitColumns(columns: LayoutColumn[]) {
|
|
166
|
-
return columns.map((column) => ({
|
|
167
|
-
...termKitUtil.mapWidgetOptionsToTermKitOptions(column),
|
|
168
|
-
}))
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public setRowHeight(rowIdx: number, height: WidgetFrameAttribute): void {
|
|
172
|
-
this.layout.layoutDef.rows[rowIdx] = {
|
|
173
|
-
...this.layout.layoutDef.rows[rowIdx],
|
|
174
|
-
...termKitUtil.mapWidgetOptionsToTermKitOptions({ height }),
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
public updateLayout() {
|
|
179
|
-
this.handleResize()
|
|
180
|
-
}
|
|
181
|
-
}
|