hyperlayout
Advanced tools
Comparing version 0.0.2 to 0.1.0
58
index.js
@@ -23,6 +23,7 @@ let hyperlayout | ||
// Generate Command queue from converted Config | ||
function generateQueue(converted, mode = 'TAB') { | ||
function generateQueue(converted, mode = 'TAB', initial) { | ||
mode = (mode === 'PANE') ? 'HORIZONTAL' : mode | ||
let q = [] | ||
if (converted instanceof Array) { | ||
@@ -42,7 +43,18 @@ converted.forEach((item, i) => { | ||
} | ||
if (initial || i > 0) { | ||
q.push({ | ||
action: 'cmd', | ||
pane: resolveArray(item) | ||
}) | ||
} | ||
}) | ||
converted.forEach(item => { | ||
q = [...q, ...generateQueue(item, nextMode(mode))] | ||
q = q.concat(generateQueue(item, nextMode(mode))) | ||
}) | ||
} | ||
// Jump back to initial pane | ||
q.push({ | ||
action: 'jump', | ||
pane: resolveArray(converted) | ||
}) | ||
return q | ||
@@ -58,7 +70,7 @@ } | ||
this.lastIndex = 0 | ||
this.knownUids = [] | ||
const converted = this.convertConfig(config.layout) | ||
const entry = (config.entry || 'tab').toUpperCase() | ||
console.log(entry) | ||
this.queue = generateQueue(converted, entry) | ||
this.queue = generateQueue(converted, entry, true) | ||
this.work() | ||
@@ -71,2 +83,3 @@ } | ||
const pane = this.panes[lastIndex] | ||
if (this.queue.length > 0) { | ||
@@ -78,18 +91,23 @@ const item = this.queue.shift() | ||
this.panes[lastIndex].uid = activeUid | ||
runCommand(activeUid, pane.cmd) | ||
} | ||
this.lastIndex = index | ||
if (item.action === 'split') { | ||
requestSession(cwd, item.mode) | ||
} else { | ||
const jumpTo = this.panes[index].uid | ||
if (jumpTo) { | ||
focusUid(this.store, jumpTo) | ||
this.lastUid = activeUid | ||
switch (item.action) { | ||
case 'split': | ||
requestSession(cwd, item.mode) | ||
break | ||
case 'cmd': | ||
runCommand(activeUid, pane.cmd) | ||
this.work() | ||
break | ||
case 'jump': | ||
default: { | ||
const jumpTo = this.panes[index].uid | ||
if (jumpTo) { | ||
focusUid(this.store, jumpTo) | ||
} | ||
this.work() | ||
} | ||
this.work() | ||
} | ||
} else if (lastIndex) { | ||
runCommand(activeUid, pane.cmd) | ||
this.lastIndex = 0 | ||
} | ||
@@ -141,3 +159,2 @@ } | ||
// Listens for initial load and sessions | ||
let lastUid | ||
exports.middleware = store => next => action => { | ||
@@ -150,3 +167,3 @@ const {type, data} = action | ||
if (type === 'SESSION_ADD_DATA') { | ||
const testedData = /^\[hyperlayout config\]:(.*)/.exec(data) | ||
const testedData = /^\[hyperlayout config]:(.*)/.exec(data) | ||
if (testedData && testedData[1]) { | ||
@@ -159,10 +176,11 @@ const config = JSON.parse(testedData[1]) | ||
// Check for new sessions | ||
// Check for sessions | ||
if (type === 'SESSION_SET_PROCESS_TITLE' && hyperlayout) { | ||
if (lastUid !== activeUid) { | ||
// Check if it's a new session | ||
if (!hyperlayout.knownUids.includes(activeUid)) { | ||
hyperlayout.knownUids.push(activeUid) | ||
hyperlayout.work() | ||
} | ||
lastUid = activeUid | ||
} | ||
next(action) | ||
} |
{ | ||
"name": "hyperlayout", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Layout presets for Hyper.app", | ||
@@ -27,8 +27,7 @@ "repository": "timolins/hyperlayout", | ||
"devDependencies": { | ||
"xo": "^0.17.0" | ||
"xo": "^0.17.1" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.3.2", | ||
"is-hyper": "^0.2.0" | ||
"debug": "^2.3.2" | ||
} | ||
} |
<img src="assets/header.png" width="320" > | ||
<img src="https://github.com/timolins/hyperlayout/raw/master/assets/header.png" width="320" > | ||
> Layout presets for [Hyper.app](https://hyper.is) | ||
[![Build Status](https://travis-ci.org/timolins/hyperlayout.svg?branch=master)](https://travis-ci.org/timolins/hyperlayout) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
<img src="https://github.com/timolins/hyperlayout/raw/master/assets/demo.gif" width="532" > | ||
# Install | ||
@@ -18,3 +23,3 @@ | ||
_Alternatively you can define it inside of `.hyperlayout` or `~/.hyperlayout`._ | ||
_Alternatively you can define it in `.hyperlayout` or `~/.hyperlayout`._ | ||
@@ -40,3 +45,3 @@ > `package.json` | ||
#### Result | ||
![Demo 1](assets/demo1.svg) | ||
![Demo 1](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/demo1.svg) | ||
@@ -80,6 +85,7 @@ | ||
#### Result | ||
![Demo 2](assets/demo2.svg) | ||
![Demo 2](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/demo2.svg) | ||
# Examples | ||
![Example 1](assets/example1.svg) **Tabs** | ||
#### Tabs | ||
![Example 1](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/example1.svg) | ||
```json | ||
@@ -89,3 +95,4 @@ ["1", "2"] | ||
--- | ||
![Example 2](assets/example2.svg) **Horizontal Panes** | ||
#### Horizontal Panes | ||
![Example 2](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/example2.svg) | ||
```json | ||
@@ -102,3 +109,4 @@ [["1", "2"]] | ||
--- | ||
![Example 3](assets/example3.svg) **Vertical Panes** | ||
#### Vertical Panes | ||
![Example 3](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/example3.svg) | ||
```json | ||
@@ -114,4 +122,17 @@ [[["1", "2"]]] | ||
``` | ||
# Global layouts | ||
You can define global layouts inside `~/.hyperlayout`. | ||
# License | ||
`hyperlayout` is released under the [MIT License](http://www.opensource.org/licenses/MIT). | ||
`hyperlayout` will use these layouts when there is no configuration in the current directory. It's possible to force global layouts with the following command: | ||
```sh | ||
$ hyperlayout global [LAYOUT] | ||
``` | ||
# Known Issues | ||
* It isn't possible layout multiple windows at once. If you know how to approach this feature, then head over to [Issue #2](https://github.com/timolins/hyperlayout/issues/2) and let me know! | ||
# Author | ||
`hyperlayout` is written by [Timo Lins](https://timo.sh). | ||
_Special thanks to [Tobias Lins](https://github.com/tobiaslins), for coming up with some great solutions._ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
71620
1
9
162
133
- Removedis-hyper@^0.2.0
- Removedis-hyper@0.2.0(transitive)
- Removedsemver@5.7.2(transitive)