From 994bcba5d9adc051b01ea3d3ee9e561fe143b860 Mon Sep 17 00:00:00 2001 From: Timo Lins Date: Wed, 16 Nov 2016 12:21:52 +0100 Subject: [PATCH] Updated documentation Closes #7 --- README.md | 117 +++++++++++++++++++++++++++++++++++++++++++++--------- index.js | 2 +- 2 files changed, 100 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f82c41f..c2a800f 100644 --- a/README.md +++ b/README.md @@ -18,21 +18,20 @@ $ hpm install hyperlayout ``` # Usage -To get started, setup a layout inside of `package.json`. +To get started, write [your layout](#define_layout) inside `.hyperlayout`. -_Alternatively you can define it in `.hyperlayout` or `~/.hyperlayout`._ +If you already use a `package.json` file, you can add it there. (With with the `hyperlayout` key) -> `package.json` +*Alternatively you can define [global layouts](#global_layouts) in `~/.hyperlayout`.* + +> `.hyperlayout` ```json -{ - "name": "example-1", - "hyperlayout": [ - [ - "echo 'Hello'", - "echo 'World'" - ] +[ + [ + "echo 'Hello'", + "echo 'World'" ] -} +] ``` To apply the layout, simply run `hyperlayout` in the same directory. @@ -43,9 +42,9 @@ $ hyperlayout #### Result ![Demo 1](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/demo1.svg) - + ## Advanced example -This example shows the capabilities of `hyperlayout`. +This example shows the capabilities of `hyperlayout`. It demonstrates the usage inside `package.json` and how to define [multiple layouts](#multiple_layouts). > `package.json` ```json @@ -53,10 +52,11 @@ This example shows the capabilities of `hyperlayout`. "name": "example-2", "scripts": { "watch": "gulp watch", - "serve": "nodemon build/index" + "serve": "nodemon build/index", + "layout": "hyperlayout" }, "hyperlayout": { - "start": [ + "default": [ [[ "npm run watch", ["npm run serve", "http://localhost:3000"] @@ -70,14 +70,25 @@ This example shows the capabilities of `hyperlayout`. "echo 'World'" ] } + }, + "devDependencies": { + "nodemon": "latest", + "gulp": "latest", + "hyperlayout": "latest" } } ``` -Since there are two layouts defined here, you have to tell `hyperlayout` which one you want to use, by suppling it as parameter. +Since there are two layouts defined here, you have to tell `hyperlayout` which one you want to use. ```sh -$ hyperlayout start +$ hyperlayout # Layout: default +``` +```sh +$ hyperlayout helloworld # Layout: helloworld +``` +```sh +$ npm run layout # Layout: default ``` #### Result ![Demo 2](https://cdn.rawgit.com/timolins/hyperlayout/f84d20382116fde4866b46e18180a446dc94d1dd/assets/demo2.svg) @@ -114,13 +125,83 @@ or "layout": ["1", "2"] } ``` + + +# Define a layout +There are two different ways to define a layout: + +#### Array +The most basic way is to create a nested array with strings (commands) inside. The hierarchy looks like this: + + +``` +Tabs +|-- Horizontal Panes + |-- Vertical Panes + |-- Horizontal Panes + |-- Vertical Panes + |-- ... +``` + + +This is a example for a vertical split using this method: +```json +[ + [ + ["echo Hello", "echo World"] + ] +] +``` + +#### Object +A layout object should contain the following key-value pairs: + +* `entry: ` – *You can define at which level the layout begins. Either `tab`, `vertical` or `horizontal`. Default value is `tab`.* + +* `layout: ` – *A layout, as described above. The only difference is, that it respects the entry point. This can make the layout more readable.* + + +```json +{ + "entry": "vertical", + "layout": [ + "echo Hello", "echo World" + ] +} +``` + + +# Multiple Layouts +As shown in the [Advanced Example](#advanced_example), it's possible to define multiple layouts in one project. Instead of supplying the [layout](#define_layout) directly, you define name for the layout first. + +```json +{ + "default": { + "entry": "vertical", + "layout": ["echo Hello", "echo World"] + }, + "otherlayout": ["echo Hyper", "echo Term"] +} +``` + +`hyperlayout` will look for the `default` layout, when there is no parameter. If there is one, it will apply the given layout. + +```sh +$ hyperlayout [NAME] +``` + + # Global layouts You can define global layouts inside `~/.hyperlayout`. `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] +$ hyperlayout global [NAME] +``` +or +```sh +$ hyperlayout g [NAME] ``` # Known Issues diff --git a/index.js b/index.js index 27845c7..35621e0 100644 --- a/index.js +++ b/index.js @@ -150,7 +150,7 @@ function focusUid({dispatch}, uid) { }) } -// Listens for initial load and sessions +// Listens for cli commands and sessions exports.middleware = store => next => action => { const {type, data} = action const {sessions} = store.getState()