Skip to content

Instantly share code, notes, and snippets.

@Guria
Last active July 12, 2016 13:48
Show Gist options
  • Save Guria/b925181ef6c222cb2735d9174aed6298 to your computer and use it in GitHub Desktop.
Save Guria/b925181ef6c222cb2735d9174aed6298 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react'
import blessed from 'blessed'
import {render} from 'react-blessed'
import {Controller} from 'cerebral'
import Model from 'cerebral-model-immutable'
import {Container, connect} from 'cerebral-view-react'
var state = {
page: 'list',
config: {
model: 'immutable',
view: 'react',
modules: {
devtools: true
}
}
}
const controller = Controller(Model(state))
let App = connect({
page: 'page'
},
class App extends Component {
render () {
let Component
switch (this.props.page) {
case 'list':
default:
Component = List
}
return <Component />
}
})
let List = connect({
config: 'config'
},
class List extends Component {
componentDidMount() {
this.refs.list.focus()
}
render() {
const items = ["- Change Model","- Change View","- 3"]
return (
<box>
<text>Current config:</text>
<text top="50">- Model: {this.props.config.model}</text>
<text top="100">- View: {this.props.config.view}</text>
<text top="150">------</text>
<list
ref="list"
items={items}
style={{ selected: {bg: '#005'} }}
mouse
keys
top="200"
/>
</box>
);
}
})
const screen = blessed.screen({
autoPadding: true,
smartCSR: true,
title: 'cerebral-cli'
});
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
const component = render(<Container controller={controller}><App /></Container>, screen);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment