Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 07f89c0

Browse files
committed
Rename OutputDecorator to Prettyfier.
1 parent 24daea5 commit 07f89c0

13 files changed

+59
-71
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ More Screenshots
6565
![](README/npm_autocompletion.png)
6666
![](README/error.png)
6767
![](README/top_autocompletion.png)
68-
![](README/json_decorator.png)
68+
![](README/json_prettyfier.png)
6969
![](README/vim.png)
7070
![](README/emacs.png)
7171
![](README/htop.png)
File renamed without changes.

src/Interfaces.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ export interface FileInfo {
4141
stat: Stats;
4242
}
4343

44-
export interface OutputDecorator {
44+
export interface Prettyfier {
4545
isApplicable: (job: Job) => boolean;
46-
decorate: (job: Job) => ReactElement<any>;
47-
48-
/**
49-
* @note Setting this property to `true` will result in rendering performance
50-
* decrease because the output will be re-decorated after each data chunk.
51-
*/
52-
shouldDecorateRunningPrograms?: boolean;
46+
prettify: (job: Job) => ReactElement<any>;
5347
}
5448

5549
export interface EnvironmentObserverPlugin {

src/PluginManager.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {OutputDecorator, EnvironmentObserverPlugin, AutocompletionProvider, PreexecPlugin, CommandInterceptorPlugin} from "./Interfaces";
1+
import {Prettyfier, EnvironmentObserverPlugin, AutocompletionProvider, PreexecPlugin, CommandInterceptorPlugin} from "./Interfaces";
22
import * as Path from "path";
33
import {io} from "./utils/Common";
44
import {environmentVariableSuggestions, anyFilesSuggestionsProvider} from "../src/plugins/autocompletion_utils/Common";
@@ -8,18 +8,18 @@ const defaultAutocompletionProvider = combine([environmentVariableSuggestions, a
88

99
// FIXME: Technical debt: register all the plugin types via single method.
1010
export class PluginManager {
11-
private static _outputDecorators: OutputDecorator[] = [];
11+
private static _prettyfiers: Prettyfier[] = [];
1212
private static _environmentObservers: EnvironmentObserverPlugin[] = [];
1313
private static _autocompletionProviders: Dictionary<AutocompletionProvider> = {};
1414
private static _preexecPlugins: PreexecPlugin[] = [];
1515
private static _commandInterceptorPlugins: CommandInterceptorPlugin[] = [];
1616

17-
static registerOutputDecorator(decorator: OutputDecorator): void {
18-
this._outputDecorators.push(decorator);
17+
static registerPrettyfier(prettyfier: Prettyfier): void {
18+
this._prettyfiers.push(prettyfier);
1919
}
2020

21-
static get outputDecorators(): OutputDecorator[] {
22-
return this._outputDecorators;
21+
static get prettyfiers(): Prettyfier[] {
22+
return this._prettyfiers;
2323
}
2424

2525
static registerEnvironmentObserver(plugin: EnvironmentObserverPlugin): void {

src/plugins/GitGrep.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {Link} from "../utils/Link";
55
import {join} from "path";
66
import {colors} from "../views/css/colors";
77

8-
PluginManager.registerOutputDecorator({
9-
decorate: (job: Job): React.ReactElement<any> => {
8+
PluginManager.registerPrettyfier({
9+
prettify: (job: Job): React.ReactElement<any> => {
1010
return <div style={{
1111
padding: "10px",
1212
lineHeight: "18px",

src/plugins/JSON.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {Job} from "../shell/Job";
33
import {PluginManager} from "../PluginManager";
44
import {JSONTree} from "../utils/JSONTree";
55

6-
PluginManager.registerOutputDecorator({
7-
decorate: (job: Job): React.ReactElement<any> => {
6+
PluginManager.registerPrettyfier({
7+
prettify: (job: Job): React.ReactElement<any> => {
88
return <JSONTree data={JSON.parse(job.screenBuffer.toString())}/>;
99
},
1010

src/plugins/Show.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {PluginManager} from "../PluginManager";
33
import {Job} from "../shell/Job";
44
import * as css from "../views/css/main";
55

6-
PluginManager.registerOutputDecorator({
7-
decorate: (job: Job): React.ReactElement<any> => {
6+
PluginManager.registerPrettyfier({
7+
prettify: (job: Job): React.ReactElement<any> => {
88
const rows = job.screenBuffer.toLines().map(path => <img style={css.image} src={path}/>);
99

1010
return <div>{rows}</div>;

src/shell/Job.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ export class Job extends EmitterWithUniqueID implements TerminalLikeDevice {
191191
}
192192
}
193193

194-
canBeDecorated(): boolean {
195-
return !!this.firstApplicableDecorator;
194+
canBePrettified(): boolean {
195+
return this.status !== Status.InProgress && !!this.firstApplicablePrettyfier;
196196
}
197197

198-
decorate(): React.ReactElement<any> {
199-
if (this.firstApplicableDecorator) {
200-
return this.firstApplicableDecorator.decorate(this);
198+
prettify(): React.ReactElement<any> {
199+
if (this.firstApplicablePrettyfier) {
200+
return this.firstApplicablePrettyfier.prettify(this);
201201
} else {
202-
throw "No applicable decorator found.";
202+
throw "No applicable prettyfier found.";
203203
}
204204
}
205205

@@ -208,14 +208,8 @@ export class Job extends EmitterWithUniqueID implements TerminalLikeDevice {
208208
return this.session.environment;
209209
}
210210

211-
private get decorators(): i.OutputDecorator[] {
212-
return PluginManager.outputDecorators.filter(decorator =>
213-
this.status === Status.InProgress ? decorator.shouldDecorateRunningPrograms : true,
214-
);
215-
}
216-
217-
private get firstApplicableDecorator(): i.OutputDecorator | undefined {
218-
return this.decorators.find(decorator => decorator.isApplicable(this));
211+
private get firstApplicablePrettyfier(): i.Prettyfier | undefined {
212+
return PluginManager.prettyfiers.find(prettyfier => prettyfier.isApplicable(this));
219213
}
220214

221215
get screenBuffer(): ScreenBuffer {

src/views/3_JobShowComponent.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ interface Props {
1111
}
1212

1313
interface State {
14-
decorate: boolean;
14+
prettify: boolean;
1515
}
1616

1717
export class JobShowComponent extends React.Component<Props, State> {
1818
constructor(props: Props) {
1919
super(props);
2020

2121
this.state = {
22-
decorate: true,
22+
prettify: true,
2323
};
2424
}
2525

@@ -30,18 +30,18 @@ export class JobShowComponent extends React.Component<Props, State> {
3030
}
3131

3232
shouldComponentUpdate(nextProps: Props, nextState: State) {
33-
return this.state.decorate !== nextState.decorate ||
33+
return this.state.prettify !== nextState.prettify ||
3434
this.props.jobStatus === Status.InProgress ||
3535
this.props.jobStatus !== nextProps.jobStatus;
3636
}
3737

3838
render() {
3939
let buffer: React.ReactElement<any>;
40-
let canBeDecorated = this.props.job.canBeDecorated();
41-
if (this.props.job.interceptionResult && this.state.decorate) {
40+
let canBePrettified = this.props.job.canBePrettified();
41+
if (this.props.job.interceptionResult && this.state.prettify) {
4242
buffer = this.props.job.interceptionResult;
43-
} else if (canBeDecorated && this.state.decorate) {
44-
buffer = this.props.job.decorate();
43+
} else if (canBePrettified && this.state.prettify) {
44+
buffer = this.props.job.prettify();
4545
} else {
4646
buffer = <BufferComponent job={this.props.job}/>;
4747
}
@@ -50,16 +50,16 @@ export class JobShowComponent extends React.Component<Props, State> {
5050
<div className={"job"}>
5151
<JobHeaderComponent
5252
job={this.props.job}
53-
showDecorationToggle={!!this.props.job.interceptionResult || canBeDecorated}
54-
decorateToggler={() => {
53+
showPrettifyToggle={!!this.props.job.interceptionResult || canBePrettified}
54+
prettifyToggler={() => {
5555
if (this.props.job.interceptionResult) {
5656
// Re-execute without intercepting
5757
this.props.job.execute({ allowInterception: false });
5858
}
59-
// Show non-decorated output
60-
this.setState({decorate: !this.state.decorate});
59+
// Show not prettified output
60+
this.setState({prettify: !this.state.prettify});
6161
}}
62-
isDecorated={this.state.decorate}
62+
isPrettified={this.state.prettify}
6363
/>
6464
{buffer}
6565
</div>

src/views/DecorationToggleComponent.tsx

-13
This file was deleted.

src/views/JobHeaderComponent.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22
import {FloatingMenu} from "./FloatingMenu";
3-
import {DecorationToggleComponent} from "./DecorationToggleComponent";
3+
import {PrettifyToggleComponent} from "./PrettifyToggleComponent";
44
import {Job} from "../shell/Job";
55
import {Button} from "../plugins/autocompletion_utils/Button";
66
import * as css from "./css/main";
@@ -9,9 +9,9 @@ import {Status} from "../Enums";
99

1010
interface Props {
1111
job: Job;
12-
decorateToggler: () => void;
13-
isDecorated: boolean;
14-
showDecorationToggle: boolean;
12+
prettifyToggler: () => void;
13+
isPrettified: boolean;
14+
showPrettifyToggle: boolean;
1515
}
1616

1717
interface State {
@@ -34,14 +34,14 @@ export class JobHeaderComponent extends React.Component<Props, State> {
3434

3535
render() {
3636
// FIXME: write better types.
37-
let decorationToggle: any;
37+
let prettifyToggle: any;
3838
let scrollToTop: any;
3939
let jobMenuButton: any;
4040

41-
if (this.props.showDecorationToggle) {
42-
decorationToggle = <DecorationToggleComponent
43-
decorateToggler={this.props.decorateToggler}
44-
isDecorated={this.props.isDecorated}
41+
if (this.props.showPrettifyToggle) {
42+
prettifyToggle = <PrettifyToggleComponent
43+
prettifyToggler={this.props.prettifyToggler}
44+
isPrettified={this.props.isPrettified}
4545
/>;
4646
}
4747

@@ -69,7 +69,7 @@ export class JobHeaderComponent extends React.Component<Props, State> {
6969
{this.props.job.prompt.value}
7070
</div>
7171
<div style={css.actions}>
72-
{decorationToggle}
72+
{prettifyToggle}
7373
{scrollToTop}
7474
{this.props.job.isInProgress() ? jobMenuButton : undefined}
7575
</div>

src/views/PrettifyToggleComponent.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from "react";
2+
import * as css from "./css/main";
3+
import {fontAwesome} from "./css/FontAwesome";
4+
5+
interface Props {
6+
prettifyToggler: () => void;
7+
isPrettified: boolean;
8+
}
9+
10+
export const PrettifyToggleComponent = (props: Props) => <span
11+
style={css.prettifyToggle(props.isPrettified)}
12+
onClick={props.prettifyToggler}
13+
>{fontAwesome.magic}</span>;

src/views/css/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export const action = {
545545
...icon,
546546
};
547547

548-
export const decorationToggle = (isEnabled: boolean) => {
548+
export const prettifyToggle = (isEnabled: boolean) => {
549549
return {
550550
...action,
551551
color: isEnabled ? colors.green : colors.white,

0 commit comments

Comments
 (0)