-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
032d7ea
commit 4c87df3
Showing
13 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const { rulesHandler } = require('./src/rules/rules-handler') | ||
const waitFor = require('./src/wait-for') | ||
|
||
const init = {} | ||
const terminal = {} | ||
|
||
exports.onApp = ({ config }) => | ||
Object.assign(init, config.getConfig().init) | ||
|
||
exports.getTabProps = (uid, parentProps, props) => | ||
Object.assign(terminal, uid, { tabs: parentProps.tabs }) && | ||
Object.assign({}, props) | ||
|
||
exports.reduceTermGroups = reducer => | ||
Object.assign(terminal, reducer.termGroups) && reducer | ||
|
||
exports.middleware = store => next => action => { | ||
if (action.type === 'SESSION_ADD') | ||
Object.assign(terminal, { splitDirection: action.splitDirection }) | ||
|
||
next(action) | ||
} | ||
|
||
exports.onWindow = app => | ||
app.rpc.on('execute commands', ({ uid, terminal }) => | ||
Object.keys(init).map(key => | ||
init[key].commands.map(cmd => | ||
rulesHandler({ init, key, cmd, app, uid, terminal })) | ||
) | ||
) | ||
|
||
exports.onRendererWindow = app => | ||
waitFor(app, 'rpc', rpc => | ||
rpc.on('session add', ({ uid }) => | ||
rpc.emit('execute commands', { uid, terminal }) | ||
) | ||
) |
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,6 @@ | ||
const { numberOfWindows } = require('../number-of-windows') | ||
|
||
exports.isNewWindow = terminal => | ||
!terminal.splitDirection && | ||
Object.keys(terminal).length <= 2 && | ||
numberOfWindows() > 2 |
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,5 @@ | ||
const { numberOfWindows } = require('../number-of-windows') | ||
|
||
exports.isOnce = terminal => | ||
numberOfWindows() <= 2 && | ||
Object.keys(terminal).length <= 2 |
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,5 @@ | ||
exports.isTab = terminal => | ||
terminal.uid ? | ||
!terminal[terminal.uid].direction && | ||
Object.keys(terminal.tabs).length > 1 : | ||
'' |
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,4 @@ | ||
const { BrowserWindow } = require('electron') | ||
|
||
exports.numberOfWindows = () => | ||
BrowserWindow.getAllWindows().length |
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,13 @@ | ||
const { onceRule } = require('./once-rule') | ||
const { onNewWindowRule } = require('./on-new-window-rule') | ||
const { onSplittedWindowsRule } = require('./on-splitted-windows-rule') | ||
const { onTabsRule } = require('./on-tabs-rule') | ||
const { onAllRule } = require('./on-all-rule') | ||
|
||
module.exports = { | ||
'once': onceRule, | ||
'windows': onNewWindowRule, | ||
'splitted': onSplittedWindowsRule, | ||
'tabs': onTabsRule, | ||
'all': onAllRule | ||
} |
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,2 @@ | ||
exports.onAllRule = ({ app, uid, cmd }) => | ||
app.sessions.get(uid).write(`${cmd}\r`) |
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,6 @@ | ||
const { isNewWindow } = require('../is/is-new-window') | ||
|
||
exports.onNewWindowRule = ({ app, uid, terminal, cmd }) => | ||
isNewWindow(terminal) ? | ||
app.sessions.get(uid).write(`${cmd}\r`) : | ||
'' |
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,4 @@ | ||
exports.onSplittedWindowsRule = ({ app, uid, cmd, terminal }) => | ||
!!terminal.splitDirection ? | ||
app.sessions.get(uid).write(`${cmd}\r`) : | ||
'' |
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,7 @@ | ||
const { isTab } = require('../is/is-tab') | ||
|
||
exports.onTabsRule = ({ app, uid, terminal, cmd }) => | ||
isTab(terminal) && | ||
!terminal.splitDirection ? | ||
app.sessions.get(uid).write(`${cmd}\r`) : | ||
'' |
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,6 @@ | ||
const { isOnce } = require('../is/is-once') | ||
|
||
exports.onceRule = ({ app, uid, terminal, cmd }) => | ||
isOnce(terminal) ? | ||
app.sessions.get(uid).write(`${cmd}\r`) : | ||
'' |
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,8 @@ | ||
const rules = require('./index') | ||
|
||
exports.rulesHandler = (...[props]) => { | ||
const rule = props.init[props.key].rule | ||
|
||
if (rule in rules) | ||
rules[rule](props) | ||
} |
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,4 @@ | ||
module.exports = waitFor = (object, key, fn) => | ||
key in object ? | ||
fn(object[key]) : | ||
setTimeout(() => waitFor(object, key, fn), 10) |