2021-11-25 15:00:52 +03:00
|
|
|
import { Terminal } from 'xterm';
|
|
|
|
import { FitAddon } from 'xterm-addon-fit';
|
2021-12-06 18:05:14 +03:00
|
|
|
import create from 'zustand';
|
|
|
|
import produce from 'immer';
|
2021-11-25 15:00:52 +03:00
|
|
|
|
|
|
|
type Session = { term: Terminal, fit: FitAddon };
|
|
|
|
type Sessions = { [id: string]: Session; }
|
|
|
|
|
|
|
|
export interface TermState {
|
|
|
|
sessions: Sessions,
|
|
|
|
selected: string,
|
|
|
|
slogstream: null | EventSource,
|
2021-12-06 18:05:14 +03:00
|
|
|
theme: 'auto' | 'light' | 'dark'
|
2021-11-25 15:00:52 +03:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:05:14 +03:00
|
|
|
const useTermState = create<TermState>((set, get) => ({
|
|
|
|
sessions: {} as Sessions,
|
2021-11-25 15:00:52 +03:00
|
|
|
selected: '', // empty string is default session
|
|
|
|
slogstream: null,
|
2021-12-06 18:05:14 +03:00
|
|
|
theme: 'auto',
|
|
|
|
set: (f: (draft: TermState) => void) => {
|
|
|
|
set(produce(f));
|
|
|
|
}
|
2021-12-08 19:12:38 +03:00
|
|
|
} as TermState));
|
2021-11-25 15:00:52 +03:00
|
|
|
|
2021-12-06 18:05:14 +03:00
|
|
|
export default useTermState;
|