From 7827ae72788b0c0d1109b18f73aced901184e590 Mon Sep 17 00:00:00 2001 From: Philipp Fritsche Date: Tue, 12 Nov 2024 09:30:02 +0000 Subject: [PATCH] wip: ui --- src/ui/cli/Input.tsx | 2 +- src/ui/cli/Main.tsx | 2 +- src/ui/cli/TesterStatus.tsx | 8 ++++++-- src/ui/cli/useWindowSize.ts | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ui/cli/Input.tsx b/src/ui/cli/Input.tsx index 783ad27..3d8e61e 100644 --- a/src/ui/cli/Input.tsx +++ b/src/ui/cli/Input.tsx @@ -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' diff --git a/src/ui/cli/Main.tsx b/src/ui/cli/Main.tsx index 1ac118b..e5a90c8 100644 --- a/src/ui/cli/Main.tsx +++ b/src/ui/cli/Main.tsx @@ -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' diff --git a/src/ui/cli/TesterStatus.tsx b/src/ui/cli/TesterStatus.tsx index 89668e5..45cb985 100644 --- a/src/ui/cli/TesterStatus.tsx +++ b/src/ui/cli/TesterStatus.tsx @@ -30,16 +30,20 @@ export function TesterStatus() { tester.filterSuites.set(s ? new RegExp(s, 'i') : undefined)} - initialValue={tester.filterSuites.get()?.source ?? ''} + initialValue={getRegexpSource(tester.filterSuites.get())} /> tester.filterTests.set(s ? new RegExp(s, 'i') : undefined)} - initialValue={tester.filterTests.get()?.source ?? ''} + initialValue={getRegexpSource(tester.filterTests.get())} /> } +function getRegexpSource(r: RegExp|undefined) { + return r?.source.replaceAll(/\\(.)/g, '$1') ?? '' +} + function getState(tester: Tester, run?: TestRunStack): { color: TextProps['backgroundColor'] text: string diff --git a/src/ui/cli/useWindowSize.ts b/src/ui/cli/useWindowSize.ts index a041e9e..c6af070 100644 --- a/src/ui/cli/useWindowSize.ts +++ b/src/ui/cli/useWindowSize.ts @@ -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]}