• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nguyenhuuit / adventofcode-runner / #4

10 Jun 2025 04:49PM UTC coverage: 9.492%. Remained the same
#4

push

nguyenhuuit
ci: publish coverage

20 of 137 branches covered (14.6%)

Branch coverage included in aggregate %.

36 of 453 relevant lines covered (7.95%)

0.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/hooks/useHandleInput.ts
1
import { useStore } from 'zustand';
2

3
import { useCallback } from 'react';
4

5
import type { Key } from 'ink';
6
import { useInput } from 'ink';
7

8
import { HELP_MESSAGE } from '@utils/constants';
9
import { Executor } from '@utils/executors';
10

11
import { useExecuteAsStream } from '@hooks/useExecuteAsStream';
12
import { ExecutionStoreInstance } from '@hooks/useExecutionStore';
13
import { useSubmit } from '@hooks/useSubmit';
14

15
export const useHandleInput = (executionStore: ExecutionStoreInstance) => {
×
16
  const { inputMode, part, loading, setInputMode, setPart, setOutput, appendOutput, clearOutput } =
17
    useStore(executionStore);
×
18

19
  const executeSolution = useExecuteAsStream(executionStore);
×
20

21
  const { submit } = useSubmit(executionStore);
×
22

23
  const handleInput = useCallback(
×
24
    async (input: string, key: Key) => {
25
      switch (input.toLowerCase()) {
×
26
        case 'q': {
27
          Executor.terminate();
×
28
          process.exit();
×
29
          break; // Unreachable but satisfies eslint god
×
30
        }
31
        case 'i': {
32
          setInputMode('input');
×
33
          break;
×
34
        }
35
        case 's': {
36
          setInputMode('sample');
×
37
          break;
×
38
        }
39
        case 'c':
40
          clearOutput();
×
41
          break;
×
42
        case '0':
43
        case '1':
44
        case '2':
45
        case '3':
46
        case '4':
47
        case '5':
48
        case '6':
49
        case '7':
50
        case '8':
51
        case '9': {
52
          setPart(input);
×
53
          break;
×
54
        }
55
        case 'x': {
56
          if (loading) {
×
57
            Executor.terminate();
×
58
            setTimeout(() => setOutput('Terminated!'), 100);
×
59
          }
60
          break;
×
61
        }
62
        case 'h': {
63
          setOutput(HELP_MESSAGE);
×
64
          break;
×
65
        }
66
        case 'u': {
67
          submit();
×
68
          break;
×
69
        }
70
      }
71
      if (key.downArrow) {
×
72
        setInputMode('input');
×
73
      }
74
      if (key.upArrow) {
×
75
        setInputMode('sample');
×
76
      }
77
      if (key.return) {
×
78
        executeSolution();
×
79
      }
80
    },
81
    [
82
      part,
83
      inputMode,
84
      loading,
85
      setInputMode,
86
      setPart,
87
      setOutput,
88
      appendOutput,
89
      clearOutput,
90
      executeSolution,
91
      submit,
92
    ]
93
  );
94

95
  useInput(handleInput);
×
96
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc