-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
1 parent
f6ba182
commit f0e6b7c
Showing
29 changed files
with
290 additions
and
34 deletions.
There are no files selected for viewing
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react' | ||
import { Box } from 'ink' | ||
import { drawBox } from './drawBox' | ||
|
||
interface Layout { | ||
bottom: number | ||
height: number | ||
left: number | ||
right: number | ||
top: number | ||
width: number | ||
} | ||
|
||
export default class BorderBox extends React.Component<any> { | ||
ref: any | ||
state = { | ||
border: '', | ||
height: 0, | ||
width: 0, | ||
} | ||
setRef = ref => { | ||
this.ref = ref | ||
const layout: Layout = this.ref.nodeRef.current.yogaNode.getComputedLayout() | ||
const width = this.props.width || layout.width | ||
const height = this.props.height || layout.height | ||
|
||
const border = drawBox({ | ||
title: this.props.title, | ||
width: width + 0, | ||
height, | ||
str: '', | ||
drawExtension: this.props.extension, | ||
}) | ||
this.setState({ border, height, width }) | ||
} | ||
render() { | ||
const { props } = this | ||
const { marginTop, marginBottom, marginLeft, marginRight, paddingBottom, paddingTop, ...rest } = props | ||
const extensionTop = this.props.extension ? -1 : 0 | ||
const outerProps = { | ||
marginTop: (marginTop || 0) + extensionTop, | ||
marginBottom, | ||
marginLeft, | ||
marginRight, | ||
} | ||
return ( | ||
<Box flexDirection="column" {...outerProps}> | ||
<Box>{this.state.border}</Box> | ||
<Box | ||
ref={this.setRef} | ||
marginTop={-this.state.height} | ||
marginLeft={2} | ||
paddingTop={paddingTop} | ||
paddingBottom={(paddingBottom || 0) + 2} | ||
{...rest} | ||
/> | ||
</Box> | ||
) | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
import { Color, Box, Text } from 'ink' | ||
import ProgressBar from 'ink-progress-bar' | ||
|
||
export interface Props { | ||
progress: number // progress from 0 to 1 | ||
} | ||
|
||
const width = 40 | ||
|
||
export function Progress(props: Props) { | ||
const { progress } = props | ||
const percentage = Math.round(progress * 100) | ||
return ( | ||
<Color green> | ||
<Box marginLeft={1} marginRight={1}> | ||
<Text bold>{percentage}%</Text> | ||
</Box> | ||
<ProgressBar percent={progress} columns={width} /> | ||
<Color dim> | ||
<ProgressBar percent={1 - progress} columns={width} character="░" /> | ||
</Color> | ||
</Color> | ||
) | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import chalk from 'chalk' | ||
import cliTruncate from 'cli-truncate' | ||
import stringWidth from 'string-width' | ||
|
||
export type BoxOptions = { | ||
title: string | ||
width: number | ||
height: number | ||
str: string | ||
drawExtension?: boolean | ||
} | ||
|
||
const defaultChars = { | ||
topLeft: '┌', | ||
topRight: '┐', | ||
bottomRight: '┘', | ||
bottomLeft: '└', | ||
vertical: '│', | ||
horizontal: '─', | ||
} | ||
|
||
export function drawBox({ title, width, height, str, drawExtension }: BoxOptions) { | ||
const chars = { ...defaultChars } | ||
|
||
if (drawExtension) { | ||
chars.topLeft = '├' | ||
chars.topRight = '┤' | ||
} | ||
|
||
title = title || '' | ||
const topLine = | ||
chalk.grey(chars.topLeft + chars.horizontal) + | ||
(title ? ' ' : '') + | ||
chalk.reset(title) + | ||
(title ? ' ' : '') + | ||
chalk.grey(chars.horizontal.repeat(width - stringWidth(title) - (title ? 2 : 0) - 3) + chars.topRight) + | ||
chalk.reset() | ||
|
||
const bottomLine = chars.bottomLeft + chars.horizontal.repeat(width - 2) + chars.bottomRight | ||
|
||
const lines = str.split('\n') | ||
|
||
if (lines.length < height) { | ||
lines.push(...new Array(height - lines.length).fill('')) | ||
} | ||
|
||
const mappedLines = lines | ||
.slice(-height) | ||
.map(l => { | ||
const lineWidth = Math.min(stringWidth(l || ''), width) | ||
const paddingRight = Math.max(width - lineWidth - 2, 0) | ||
return `${chalk.grey(chars.vertical)}${chalk.reset(cliTruncate(l, width - 2))}${' '.repeat( | ||
paddingRight, | ||
)}${chalk.grey(chars.vertical)}` | ||
}) | ||
.join('\n') | ||
|
||
return chalk.grey(topLine + '\n' + mappedLines + '\n' + bottomLine) | ||
} |
2 changes: 1 addition & 1 deletion
2
cli/introspection/src/prompt-lib/helpers.ts → ...spection/src/prompt/components/helpers.ts
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { render, Color, Box, Text } from 'ink' | ||
import React from 'react' | ||
import { Progress } from './components/Progress' | ||
import BorderBox from './components/BorderBox' | ||
import chalk from 'chalk' | ||
import Step0StarterVsBlank from './steps/Step0StarterVsBlank' | ||
|
||
class Compy extends React.Component<any, { step: number; progress: number }> { | ||
state = { | ||
step: 0, | ||
progress: 0, | ||
} | ||
componentDidMount() { | ||
setInterval(() => { | ||
this.setState(({ step }) => { | ||
step += 0.05 | ||
|
||
return { | ||
step, | ||
progress: Math.abs(Math.sin(step)), | ||
} | ||
}) | ||
}, 16) | ||
} | ||
render() { | ||
return ( | ||
<BorderBox flexDirection="column" title={chalk.bold('Hello World ' + Math.round(this.state.progress * 100))}> | ||
<Progress progress={this.state.progress} /> | ||
</BorderBox> | ||
) | ||
} | ||
} | ||
|
||
export function renderInk() { | ||
return new Promise(resolve => { | ||
render(<Step0StarterVsBlank />) | ||
}) | ||
} |
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
48 changes: 48 additions & 0 deletions
48
cli/introspection/src/prompt/steps/Step0StarterVsBlank.tsx
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react' | ||
import { Box, Color, Text } from 'ink' | ||
import BorderBox from '../components/BorderBox' | ||
import chalk from 'chalk' | ||
import figures from 'figures' | ||
|
||
export default class Step0StarterVsBlank extends React.Component { | ||
render() { | ||
return ( | ||
<Box flexDirection="column"> | ||
<Box flexDirection="column" marginLeft={2}> | ||
<Text bold>Select the language for a starter kit or start with a blank project.</Text> | ||
<Color dim>Starter kits provide ready-made setups for various use cases.</Color> | ||
</Box> | ||
<BorderBox flexDirection="column" title={chalk.bold('Languages for starter kits')} marginTop={1}> | ||
<Box> | ||
<Color cyan> | ||
<Box width={14} marginRight={2}> | ||
{figures.pointer} <Text bold>JavaScript</Text> | ||
</Box> | ||
<Color dim>GraphQL, REST, gRPC, ...</Color> | ||
</Color> | ||
</Box> | ||
<Box> | ||
<Box width={14} marginLeft={2}> | ||
TypeScript | ||
</Box> | ||
<Color dim>GraphQL, REST, gRPC, ...</Color> | ||
</Box> | ||
<Box marginLeft={2}> | ||
<Color dim>Go (Coming soon)</Color> | ||
</Box> | ||
<Box marginLeft={2} marginTop={1}> | ||
<Color dim>Note: Starter kits only work with empty databases</Color> | ||
</Box> | ||
</BorderBox> | ||
<BorderBox flexDirection="column" title={chalk.bold('Get started from scratch')} marginBottom={1} marginTop={1}> | ||
<Box> | ||
<Box width={15} marginLeft={2}> | ||
Blank project | ||
</Box> | ||
<Color dim>Supports introspecting your existing DB</Color> | ||
</Box> | ||
</BorderBox> | ||
</Box> | ||
) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.