pull/5370/head
bunsenstraat 9 months ago
parent 652a921052
commit 8519298b34
  1. 358
      libs/remix-ui/terminal/src/lib/reducers/terminalReducer.ts
  2. 38
      libs/remix-ui/terminal/src/lib/remix-ui-terminal-wrapper.tsx
  3. 110
      libs/remix-ui/xterm/src/lib/reducer/index.ts

@ -27,209 +27,209 @@ export const initialState = {
export const registerCommandReducer = (state, action) => {
switch (action.type) {
case HTML:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, {...action.payload.data}),
}
case LOG:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, {...action.payload.data}),
}
case INFO:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case WARN:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case ERROR:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case SCRIPT:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case CLEAR_CONSOLE:
return {
...state,
...state.journalBlocks.splice(0),
clearConsole: true,
}
case HTML:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, {...action.payload.data}),
}
case LOG:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, {...action.payload.data}),
}
case INFO:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case WARN:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case ERROR:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case SCRIPT:
return {
...state,
_commands: Object.assign(initialState._commands, action.payload._commands),
commands: Object.assign(initialState.commands, action.payload.commands),
data: Object.assign(initialState.data, action.payload.data),
}
case CLEAR_CONSOLE:
return {
...state,
...state.journalBlocks.splice(0),
clearConsole: true,
}
case SEARCH:
return {
...state,
searchInput: action.payload,
}
case SEARCH:
return {
...state,
searchInput: action.payload,
}
case TOGGLE:
return {
...state,
isOpen: !state.isOpen,
}
case TOGGLE:
return {
...state,
isOpen: !state.isOpen,
}
case SET_OPEN:
return {
...state,
isOpen: action.payload,
}
case SET_OPEN:
return {
...state,
isOpen: action.payload,
}
case LISTEN_ON_NETWORK:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log'}),
}
case LISTEN_ON_NETWORK:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log'}),
}
case SET_ISVM:
return {
...state,
isVM: action.payload,
}
default:
return {state}
case SET_ISVM:
return {
...state,
isVM: action.payload,
}
default:
return {state}
}
}
export const registerFilterReducer = (state, action) => {
switch (action.type) {
case LOG:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case INFO:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case WARN:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case ERROR:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case SCRIPT:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
default:
return {state}
case LOG:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case INFO:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case WARN:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case ERROR:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
case SCRIPT:
return {
...state,
data: Object.assign(initialState.data.filterFns, action.payload.data.filterFns),
}
default:
return {state}
}
}
export const addCommandHistoryReducer = (state, action) => {
switch (action.type) {
case CMD_HISTORY:
return {
...state,
_commandHistory: initialState._commandHistory.unshift(action.payload.script),
}
default:
return {state}
case CMD_HISTORY:
return {
...state,
_commandHistory: initialState._commandHistory.unshift(action.payload.script),
}
default:
return {state}
}
}
export const remixWelcomeTextReducer = (state, action) => {
switch (action.type) {
case 'welcomeText':
return {
...state,
journalBlocks: initialState.journalBlocks.push(action.payload.welcomeText),
}
case 'welcomeText':
return {
...state,
journalBlocks: initialState.journalBlocks.push(action.payload.welcomeText),
}
}
}
export const registerScriptRunnerReducer = (state, action) => {
switch (action.type) {
case HTML:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log', provider: action.payload.provider}),
}
case LOG:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log', provider: action.payload.provider}),
}
case TYPEWRITERLOG:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, typewriter: true, style: 'text-log', provider: action.payload.provider}),
}
case TYPEWRITERWARNING:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, typewriter: true, style: 'text-warning', provider: action.payload.provider}),
}
case TYPEWRITERSUCCESS:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, typewriter: true, style: 'text-success', provider: action.payload.provider}),
}
case INFO:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-success', provider: action.payload.provider}),
}
case WARN:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-warning', provider: action.payload.provider}),
}
case ERROR:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-danger', provider: action.payload.provider}),
}
case SCRIPT:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log', provider: action.payload.provider}),
}
case KNOWN_TRANSACTION:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', name: 'knownTransaction', provider: action.payload.provider}),
}
case UNKNOWN_TRANSACTION:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', name: 'unknownTransaction', provider: action.payload.provider}),
}
case EMPTY_BLOCK:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', name: 'emptyBlock', provider: action.payload.provider}),
}
case NEW_TRANSACTION:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', provider: action.payload.provider}),
}
case HTML:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log', provider: action.payload.provider}),
}
case LOG:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log', provider: action.payload.provider}),
}
case TYPEWRITERLOG:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, typewriter: true, style: 'text-log', provider: action.payload.provider}),
}
case TYPEWRITERWARNING:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, typewriter: true, style: 'text-warning', provider: action.payload.provider}),
}
case TYPEWRITERSUCCESS:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, typewriter: true, style: 'text-success', provider: action.payload.provider}),
}
case INFO:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-success', provider: action.payload.provider}),
}
case WARN:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-warning', provider: action.payload.provider}),
}
case ERROR:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-danger', provider: action.payload.provider}),
}
case SCRIPT:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: 'text-log', provider: action.payload.provider}),
}
case KNOWN_TRANSACTION:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', name: 'knownTransaction', provider: action.payload.provider}),
}
case UNKNOWN_TRANSACTION:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', name: 'unknownTransaction', provider: action.payload.provider}),
}
case EMPTY_BLOCK:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', name: 'emptyBlock', provider: action.payload.provider}),
}
case NEW_TRANSACTION:
return {
...state,
journalBlocks: initialState.journalBlocks.push({message: action.payload.message, style: '', provider: action.payload.provider}),
}
}
}

@ -8,26 +8,26 @@ import RemixUiTerminal from './remix-ui-terminal'
import { RemixUiTerminalProps } from './types/terminalTypes'
export const RemixUITerminalWrapper = (props: RemixUiTerminalProps) => {
const [terminalState, dispatch] = useReducer(registerCommandReducer, initialState)
const [xtermState, dispatchXterm] = useReducer(xtermReducer, xTerminInitialState)
const platform = useContext(platformContext)
const providerState = {
terminalState,
dispatch,
xtermState,
dispatchXterm
}
const [terminalState, dispatch] = useReducer(registerCommandReducer, initialState)
const [xtermState, dispatchXterm] = useReducer(xtermReducer, xTerminInitialState)
const platform = useContext(platformContext)
const providerState = {
terminalState,
dispatch,
xtermState,
dispatchXterm
}
return (<>
<TerminalContext.Provider value={providerState}>
<RemixUITerminalBar {...props} />
{platform !== appPlatformTypes.desktop && <RemixUiTerminal {...props} />}
{platform === appPlatformTypes.desktop &&
return (<>
<TerminalContext.Provider value={providerState}>
<RemixUITerminalBar {...props} />
{platform !== appPlatformTypes.desktop && <RemixUiTerminal {...props} />}
{platform === appPlatformTypes.desktop &&
<>
<RemixUiTerminal visible={xtermState.showOutput} plugin={props.plugin} onReady={props.onReady} />
<RemixUiXterminals {...props} />
<RemixUiTerminal visible={xtermState.showOutput} plugin={props.plugin} onReady={props.onReady} />
<RemixUiXterminals {...props} />
</>
}
</TerminalContext.Provider>
</>)
}
</TerminalContext.Provider>
</>)
}

@ -10,60 +10,60 @@ export const xTerminInitialState: xTerminalUiState = {
export const xtermReducer = (state = xTerminInitialState, action: Actions) => {
switch (action.type) {
case 'ENABLE_TERMINALS':
return {
...state,
terminalsEnabled: true
}
case 'DISABLE_TERMINALS':
return {
...state,
terminalsEnabled: false
}
case 'ADD_TERMINAL':
return {
...state,
terminals: [...state.terminals, action.payload]
}
case 'HIDE_TERMINAL':
return {
...state,
terminals: state.terminals.map(terminal => terminal.pid === action.payload ? { ...terminal, hidden: true } : terminal)
}
case 'SHOW_TERMINAL':
return {
...state,
terminals: state.terminals.map(terminal => terminal.pid === action.payload ? { ...terminal, hidden: false } : terminal)
}
case 'HIDE_ALL_TERMINALS':
return {
...state,
terminals: state.terminals.map(terminal => ({ ...terminal, hidden: true }))
}
case 'REMOVE_TERMINAL':
const removed = state.terminals.filter(xtermState => xtermState.pid !== action.payload)
if (removed.length > 0)
removed[removed.length - 1].hidden = false
return {
...state,
terminals: removed
}
case 'ADD_SHELLS':
return {
...state,
shells: action.payload
}
case 'SHOW_OUTPUT':
return {
...state,
showOutput: action.payload
}
case 'SET_WORKING_DIR':
return {
...state,
workingDir: action.payload
}
default:
return state
case 'ENABLE_TERMINALS':
return {
...state,
terminalsEnabled: true
}
case 'DISABLE_TERMINALS':
return {
...state,
terminalsEnabled: false
}
case 'ADD_TERMINAL':
return {
...state,
terminals: [...state.terminals, action.payload]
}
case 'HIDE_TERMINAL':
return {
...state,
terminals: state.terminals.map(terminal => terminal.pid === action.payload ? { ...terminal, hidden: true } : terminal)
}
case 'SHOW_TERMINAL':
return {
...state,
terminals: state.terminals.map(terminal => terminal.pid === action.payload ? { ...terminal, hidden: false } : terminal)
}
case 'HIDE_ALL_TERMINALS':
return {
...state,
terminals: state.terminals.map(terminal => ({ ...terminal, hidden: true }))
}
case 'REMOVE_TERMINAL':
const removed = state.terminals.filter(xtermState => xtermState.pid !== action.payload)
if (removed.length > 0)
removed[removed.length - 1].hidden = false
return {
...state,
terminals: removed
}
case 'ADD_SHELLS':
return {
...state,
shells: action.payload
}
case 'SHOW_OUTPUT':
return {
...state,
showOutput: action.payload
}
case 'SET_WORKING_DIR':
return {
...state,
workingDir: action.payload
}
default:
return state
}
}

Loading…
Cancel
Save