-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
308 additions
and
253 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ export var commandLineInput = { | |
outline: 'none', | ||
zIndex: -1, | ||
position: 'absolute', | ||
left: '-1000px', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
import { ITerminalStatelessProps } from './terminalStateless.interface'; | ||
export declare function TerminalStateless(props: ITerminalStatelessProps): JSX.Element; | ||
export declare class TerminalStateless extends React.Component<ITerminalStatelessProps> { | ||
private boxRef; | ||
render(): JSX.Element; | ||
componentDidUpdate(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import * as tslib_1 from "tslib"; | ||
import * as React from 'react'; | ||
import { CommandLine } from './commandLine/commandLine'; | ||
import * as styles from './terminalStateless.style'; | ||
export function TerminalStateless(props) { | ||
var history = props.history, prompt = props.prompt, onReceiveCommand = props.onReceiveCommand; | ||
return (React.createElement("div", { style: styles.terminalBox }, | ||
React.createElement("div", { style: styles.terminalContainer }, | ||
history.map(function (line, index) { | ||
return React.createElement("div", { key: index }, line); | ||
}), | ||
React.createElement(CommandLine, { onReceiveCommand: onReceiveCommand, prompt: prompt })))); | ||
} | ||
var TerminalStateless = /** @class */ (function (_super) { | ||
tslib_1.__extends(TerminalStateless, _super); | ||
function TerminalStateless() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.boxRef = React.createRef(); | ||
return _this; | ||
} | ||
TerminalStateless.prototype.render = function () { | ||
var _a = this.props, history = _a.history, prompt = _a.prompt, onReceiveCommand = _a.onReceiveCommand, width = _a.width, height = _a.height; | ||
var terminalBox = tslib_1.__assign({}, styles.terminalBox, { width: width || styles.terminalBox.width, height: height || styles.terminalBox.height }); | ||
return (React.createElement("div", { style: terminalBox, ref: this.boxRef }, | ||
React.createElement("div", { style: styles.terminalContainer }, | ||
history.map(function (line, index) { | ||
return React.createElement("div", { key: index, style: styles.terminalContainerLine }, line); | ||
}), | ||
React.createElement(CommandLine, { onReceiveCommand: onReceiveCommand, prompt: prompt })))); | ||
}; | ||
TerminalStateless.prototype.componentDidUpdate = function () { | ||
var box = this.boxRef.current; | ||
box.scroll({ | ||
top: box.scrollHeight, | ||
}); | ||
}; | ||
return TerminalStateless; | ||
}(React.Component)); | ||
export { TerminalStateless }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { CSSProperties } from 'react'; | ||
export declare const terminalBox: CSSProperties; | ||
export declare const terminalContainer: CSSProperties; | ||
export declare const terminalContainerLine: CSSProperties; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
export var terminalBox = { | ||
fontFamily: 'monospace', | ||
display: 'flex', | ||
backgroundColor: '#44494e', | ||
fontWeight: 'bold', | ||
height: '400px', | ||
height: '500px', | ||
overflowY: 'scroll', | ||
}; | ||
export var terminalContainer = { | ||
fontSize: '14px', | ||
color: '#20e444', | ||
padding: '8px', | ||
}; | ||
export var terminalContainerLine = { | ||
margin: 0, | ||
whiteSpace: 'pre', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { SetState } from '../terminalEmulator.interface'; | ||
export declare abstract class BaseExecutor { | ||
protected commandPattern: RegExp; | ||
abstract execute(command: string, setState: SetState): void; | ||
checkCommand(command: string): boolean; | ||
init(): void; | ||
abstract isCompleted(): boolean; | ||
protected abstract getCommandPattern(): RegExp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { SetState } from '../terminalEmulator.interface'; | ||
import { BaseExecutor } from './baseExecutor'; | ||
export declare class ClearExecutor extends BaseExecutor { | ||
readonly commandPattern: RegExp; | ||
execute(command: string, setState: SetState): void; | ||
isCompleted(): boolean; | ||
protected getCommandPattern(): RegExp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { SetState } from '../terminalEmulator.interface'; | ||
import { BaseExecutor } from './baseExecutor'; | ||
export declare class HelpExecutor extends BaseExecutor { | ||
constructor(); | ||
execute(command: string, setState: SetState): void; | ||
isCompleted(): boolean; | ||
protected getCommandPattern(): RegExp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import {CSSProperties} from 'react'; | ||
import * as React from 'react'; | ||
import {CommandLine} from './commandLine/commandLine'; | ||
import {ITerminalStatelessProps} from './terminalStateless.interface'; | ||
import * as styles from './terminalStateless.style'; | ||
|
||
export function TerminalStateless(props: ITerminalStatelessProps) { | ||
const {history, prompt, onReceiveCommand} = props; | ||
export class TerminalStateless extends React.Component<ITerminalStatelessProps> { | ||
private boxRef = React.createRef<HTMLDivElement>(); | ||
|
||
return ( | ||
<div style={styles.terminalBox}> | ||
<div style={styles.terminalContainer}> | ||
{history.map((line, index) => | ||
<div key={index}>{line}</div>)} | ||
<CommandLine onReceiveCommand={onReceiveCommand} prompt={prompt}/> | ||
public render() { | ||
const {history, prompt, onReceiveCommand, width, height} = this.props; | ||
const terminalBox: CSSProperties = { | ||
...styles.terminalBox, | ||
width: width || styles.terminalBox.width, | ||
height: height || styles.terminalBox.height, | ||
}; | ||
|
||
return ( | ||
<div style={terminalBox} ref={this.boxRef}> | ||
<div style={styles.terminalContainer}> | ||
{history.map((line, index) => | ||
<div key={index} style={styles.terminalContainerLine}>{line}</div>)} | ||
<CommandLine onReceiveCommand={onReceiveCommand} prompt={prompt}/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
} | ||
|
||
public componentDidUpdate() { | ||
const box = this.boxRef.current!; | ||
box.scroll({ | ||
top: box.scrollHeight, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import {SetState} from '../terminalEmulator.interface'; | ||
|
||
export abstract class BaseExecutor { | ||
protected commandPattern: RegExp; | ||
|
||
public abstract execute(command: string, setState: SetState): void; | ||
|
||
public checkCommand(command: string): boolean { | ||
return this.commandPattern.test(command); | ||
const commandPattern = this.getCommandPattern(); | ||
return commandPattern.test(command); | ||
} | ||
|
||
public init(): void { | ||
// it necessary for complicated command | ||
} | ||
|
||
public abstract isCompleted(): boolean; | ||
|
||
protected abstract getCommandPattern(): RegExp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.