16
*/
17
export function terminalReducer(state: TerminalState, action: TerminalAction, log?: (msg: string) => void): TerminalState {
19
>
case ActionType.TerminalData: {
20
>
const content = [...state.content];
21
>
const tail = content.length > 0 ? content[content.length - 1] : undefined;
22
>
if (tail && tail.type === 'command' && !tail.isComplete) {
23
content[content.length - 1] = { ...tail, output: tail.output + action.data };
24
>
} else if (tail && tail.type === 'unclassified') {
reducer.ts
25
content[content.length - 1] = { ...tail, value: tail.value + action.data };
26
} else {
27
content.push({ type: 'unclassified', value: action.data });
28
}
30
>
}
31
>
32
>
case ActionType.TerminalInput:
33
// Side-effect-only: the server forwards to the pty.
34
// No state change in the reducer.
35
return state;
37
>
case ActionType.TerminalResized:
38
return { ...state, cols: action.cols, rows: action.rows };
40
>
case ActionType.TerminalClaimed:
41
return { ...state, claim: action.claim };
43
>
case ActionType.TerminalTitleChanged:
44
return { ...state, title: action.title };
46
>
case ActionType.TerminalCwdChanged:
47
return { ...state, cwd: action.cwd };
49
>
case ActionType.TerminalExited:
50
return { ...state, exitCode: action.exitCode };
52
>
case ActionType.TerminalCleared:
53
return { ...state, content: [] };
55
>
case ActionType.TerminalCommandDetectionAvailable:
56
return { ...state, supportsCommandDetection: true };
58
>
case ActionType.TerminalCommandExecuted: {
59
const part: TerminalContentPart = {
60
type: 'command',