Skip to content

Commit

Permalink
wip: ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Nov 12, 2024
1 parent ed5f5d9 commit 7827ae7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ui/cli/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo } from 'react'
import React, { useMemo } from 'react'
import { Box, Text, useFocus, useInput } from 'ink'
import { useState } from 'react'

Expand Down
2 changes: 1 addition & 1 deletion src/ui/cli/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { Box, BoxProps, Text, useFocus, useFocusManager, useInput } from 'ink'
import { Box, BoxProps, Text, useFocus, useInput } from 'ink'
import { useTester } from '../TesterContext'
import { TestRunStack, TestSuiteStack } from '../../conductor/TestRun'
import { Overview } from './Overview'
Expand Down
8 changes: 6 additions & 2 deletions src/ui/cli/TesterStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ export function TesterStatus() {
<Input
title="Filter Suites"
onChange={s => tester.filterSuites.set(s ? new RegExp(s, 'i') : undefined)}
initialValue={tester.filterSuites.get()?.source ?? ''}
initialValue={getRegexpSource(tester.filterSuites.get())}
/>
<Input
title="Filter Tests"
onChange={s => tester.filterTests.set(s ? new RegExp(s, 'i') : undefined)}
initialValue={tester.filterTests.get()?.source ?? ''}
initialValue={getRegexpSource(tester.filterTests.get())}
/>
</Box>
}

function getRegexpSource(r: RegExp|undefined) {
return r?.source.replaceAll(/\\(.)/g, '$1') ?? ''
}

function getState(tester: Tester, run?: TestRunStack): {
color: TextProps['backgroundColor']
text: string
Expand Down
5 changes: 3 additions & 2 deletions src/ui/cli/useWindowSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export function useWindowSize() {
const [size, setSize] = useState(process.stdout.getWindowSize())

useEffect(() => {
process.stdout.addListener('resize', setSize)
return () => void process.stdout.removeListener('resize', setSize)
const h = () => setSize(process.stdout.getWindowSize())
process.stdout.addListener('resize', h)
return () => void process.stdout.removeListener('resize', h)
}, [])

return {width: size[0], height: size[1]}
Expand Down

0 comments on commit 7827ae7

Please sign in to comment.