├── .gitignore ├── LICENSE ├── README.md ├── components └── close.js ├── examples └── index.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Matthew Conlen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hyperterm-window 2 | Window component for hyperterm 3 | 4 | ![hyperwindow](https://cloud.githubusercontent.com/assets/1074773/17676278/cb48b1da-62fb-11e6-9eba-16c87db8995c.gif) 5 | 6 | 7 | ## Example usage: 8 | 9 | ```js 10 | 11 | const HyperWindow = require('hyperterm-window'); 12 | 13 | exports.decorateTerm = (Term, { React, notify }) => { 14 | 15 | return class extends React.Component { 16 | render () { 17 | const children = [React.createElement(Term, Object.assign({}, this.props, { key: 'term' }))]; 18 | 19 | // Add a custom component to be displayed in the window 20 | const myComponent = ...; 21 | 22 | const windowProps = Object.assign({}, this.props, {key: 'window', onClose: this.props.clearChart}); 23 | const hyperwindow = React.createElement(HyperWindow, windowProps, myComponent); 24 | children.push(hyperwindow); 25 | return React.createElement('div', {style: {width: '100%', height: '100%', position: 'relative'}}, children); 26 | } 27 | } 28 | }; 29 | 30 | ``` 31 | 32 | See the [example](./examples/index.js) for how to integrate the window with the hyperterm redux store. 33 | 34 | ## props 35 | 36 | * `width` - the width of the window in pixels. optional. 37 | * `height` - the height of the window in pixels. optional. 38 | * `onClose` - function to call when the user clicks the close button 39 | * `foregroundColor`, `backgroundColor` - these should be the colors specified in the user's `.hyperterm.js`, used to make the window integrate well into the terminal. If you just pass all of `this.props` from a terminal decorator these will get set automatically (see example above). 40 | 41 | ## TODO 42 | 43 | - [ ] add `position` prop - e.g. 'UPPER_LEFT', 'BOTTOM_RIGHT', etc 44 | - [ ] add ability to drag 45 | - [ ] add ability to resize 46 | 47 | Pull requests welcome! 48 | -------------------------------------------------------------------------------- /components/close.js: -------------------------------------------------------------------------------- 1 | const React = require('react'); 2 | 3 | const size = 10; 4 | 5 | module.exports = (props) => { 6 | return React.createElement('svg', { 7 | onClick: props.onClick, 8 | style: { 9 | position: 'absolute', 10 | top: 5, 11 | right: 5, 12 | width: size, 13 | height: size 14 | } 15 | }, [React.createElement('line', { 16 | x1: 0, 17 | y1: 0, 18 | x2: size, 19 | y2: size, 20 | stroke: props.color 21 | }), React.createElement('line', { 22 | x1: 0, 23 | y1: size, 24 | x2: size, 25 | y2: 0, 26 | stroke: props.color 27 | })]); 28 | }; 29 | -------------------------------------------------------------------------------- /examples/index.js: -------------------------------------------------------------------------------- 1 | 2 | exports.reduceUI = (state, action) => { 3 | switch (action.type) { 4 | case 'TOGGLE_WINDOW': 5 | return state.set('showWindow', !state.showWindow); 6 | } 7 | return state; 8 | }; 9 | 10 | exports.mapTermsState = (state, map) => { 11 | return Object.assign(map, { 12 | showWindow: state.ui.showWindow 13 | }); 14 | }; 15 | 16 | exports.getTermProps = (uid, parentProps, props) => { 17 | return Object.assign(props, { 18 | showWindow: parentProps.showWindow 19 | }); 20 | }; 21 | 22 | exports.middleware = (store) => (next) => (action) => { 23 | if (!action) { 24 | return; 25 | } 26 | if (action.type === 'SESSION_ADD_DATA') { 27 | const { data } = action; 28 | if (/(toggle-window: command not found)|(command not found: toggle-window)/.test(data)) { 29 | store.dispatch({ 30 | type: 'TOGGLE_WINDOW' 31 | }); 32 | } else { 33 | next(action); 34 | } 35 | } else { 36 | next(action); 37 | } 38 | }; 39 | 40 | exports.decorateTerm = (Term, { React, notify }) => { 41 | 42 | // Hack to fix the react import 43 | try { 44 | require('react'); 45 | } catch(e) { 46 | var Module = require('module'); 47 | var originalRequire = Module.prototype.require; 48 | Module.prototype.require = function (path) { 49 | if (path === 'react') { 50 | return React; 51 | } 52 | return originalRequire.apply(this, arguments); 53 | }; 54 | } 55 | 56 | const Chart = require('./components/chart')(React); 57 | const Window = require('hyperterm-window'); 58 | 59 | return class extends React.Component { 60 | render () { 61 | const children = [React.createElement(Term, Object.assign({}, this.props, { key: 'term' }))]; 62 | 63 | if (this.props.showWindow) { 64 | // Add a custom component to be displayed in the window 65 | const myComponent = ...; 66 | 67 | const windowProps = Object.assign({}, this.props, {key: 'window', onClose: this.props.clearChart}); 68 | const hyperwindow = React.createElement(HyperWindow, windowProps, myComponent); 69 | children.push(hyperwindow); 70 | } 71 | 72 | return React.createElement('div', {style: {width: '100%', height: '100%', position: 'relative'}}, children); 73 | } 74 | } 75 | }; 76 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const React = require('react'); 2 | const Close = require('./components/close'); 3 | 4 | const overlayStyles = { 5 | position: 'absolute', 6 | bottom: 0, 7 | right: 0, 8 | cursor: 'pointer', 9 | borderRadius: 5, 10 | borderWidth: 1, 11 | borderStyle: 'solid', 12 | transition: 'left 0.75s, bottom 0.75s, top 0.75s, right 0.75s, width 0.75s, height 0.75s' 13 | }; 14 | 15 | console.log('in here'); 16 | module.exports = class extends React.Component { 17 | constructor(props) { 18 | super(props); 19 | this.state = { 20 | expanded: false, 21 | showClose: false 22 | }; 23 | 24 | this.handleClick = this.handleClick.bind(this); 25 | this.handleMouseEnter = this.handleMouseEnter.bind(this); 26 | this.handleMouseLeave = this.handleMouseLeave.bind(this); 27 | } 28 | 29 | handleClick () { 30 | this.setState({ 31 | expanded: !this.state.expanded 32 | }); 33 | } 34 | 35 | handleMouseEnter () { 36 | this.setState({ 37 | showClose: true 38 | }); 39 | } 40 | 41 | handleMouseLeave () { 42 | this.setState({ 43 | showClose: false 44 | }); 45 | } 46 | mapChildren () { 47 | return React.Children.map(this.props.children, (child) => { 48 | return React.cloneElement(child, { 49 | expanded: this.state.expanded 50 | }); 51 | }); 52 | } 53 | 54 | render () { 55 | let children = this.mapChildren(); 56 | if (this.state.showClose) { 57 | const close = React.createElement(Close, {key: 'close', onClick: this.props.onClose, color: this.props.foregroundColor}); 58 | children = children.concat(close) 59 | } 60 | const inner = React.createElement('div', {style: {position: 'relative'}}, children); 61 | const dynamicStyles = { 62 | borderColor: this.props.foregroundColor, 63 | backgroundColor: this.props.backgroundColor, 64 | width: this.props.width || 200, 65 | height: this.props.height || 150 66 | }; 67 | 68 | if (this.state.expanded) { 69 | dynamicStyles.width = '100%'; 70 | dynamicStyles.height = '100%'; 71 | } 72 | return React.createElement('div', {style: Object.assign({}, overlayStyles, dynamicStyles), onDoubleClick: this.handleClick, onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave}, inner); 73 | } 74 | }; 75 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hyperterm-window", 3 | "version": "1.0.1", 4 | "description": "Window component for hyperterm", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mathisonian/hyperterm-window.git" 12 | }, 13 | "keywords": [ 14 | "hyperterm" 15 | ], 16 | "author": "Matthew Conlen ", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/mathisonian/hyperterm-window/issues" 20 | }, 21 | "homepage": "https://github.com/mathisonian/hyperterm-window#readme" 22 | } 23 | --------------------------------------------------------------------------------