From e6dabbd703cc30f43a3eebd29ed9185fa7cc10d0 Mon Sep 17 00:00:00 2001 From: Stereokai Date: Wed, 14 Dec 2016 15:05:29 +0200 Subject: [PATCH 1/4] Add more robust method to retrieve config JSON from the terminal --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 18dfdb9..5367e32 100644 --- a/index.js +++ b/index.js @@ -154,12 +154,19 @@ exports.middleware = store => next => action => { const {type, data} = action const {sessions} = store.getState() const {activeUid} = sessions + // Remove ANSI escape code sequences. Visualization: https://goo.gl/IY8vuU + const ANSI_escape_codes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm + // Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/hxz4S1 + const config_matcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm + // Cross-os new-line characters. Visualization: https://goo.gl/q501uy + const newlines = /[\n\r]/gm // Check for hyperlayout config if (type === 'SESSION_ADD_DATA') { - const testedData = /^\[hyperlayout config]:(.*)/.exec(data) + data = data.replace(ANSI_escape_codes, '') + const testedData = config_matcher.exec(data.trim()); if (testedData && testedData[1]) { - const config = JSON.parse(testedData[1]) + const config = JSON.parse(testedData[1].replace(newlines, '')) hyperlayout = new Hyperlayout(config, store) return } From d1000faae59d7dffcec57c055380d807d212c63f Mon Sep 17 00:00:00 2001 From: Stereokai Date: Wed, 14 Dec 2016 15:18:18 +0200 Subject: [PATCH 2/4] Move constants to module scope --- index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 5367e32..0c2b38a 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,14 @@ const nextMode = mode => { } } +// Matchers for retrieving config JSON from terminal +// Remove ANSI escape code sequences. Visualization: https://goo.gl/IY8vuU +const ANSI_escape_codes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm +// Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/hxz4S1 +const config_matcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm +// Cross-os new-line characters. Visualization: https://goo.gl/q501uy +const newlines = /[\n\r]/gm + // Generate Command queue from converted Config function generateQueue(converted, mode = 'TAB', initial) { mode = (mode === 'PANE') ? 'HORIZONTAL' : mode @@ -154,12 +162,6 @@ exports.middleware = store => next => action => { const {type, data} = action const {sessions} = store.getState() const {activeUid} = sessions - // Remove ANSI escape code sequences. Visualization: https://goo.gl/IY8vuU - const ANSI_escape_codes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm - // Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/hxz4S1 - const config_matcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm - // Cross-os new-line characters. Visualization: https://goo.gl/q501uy - const newlines = /[\n\r]/gm // Check for hyperlayout config if (type === 'SESSION_ADD_DATA') { From cf0466bdc18139c072b62219f4455d48a09a7776 Mon Sep 17 00:00:00 2001 From: Stereokai Date: Wed, 14 Dec 2016 15:27:22 +0200 Subject: [PATCH 3/4] Convert identifiers to camel case --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0c2b38a..969f594 100644 --- a/index.js +++ b/index.js @@ -21,9 +21,9 @@ const nextMode = mode => { // Matchers for retrieving config JSON from terminal // Remove ANSI escape code sequences. Visualization: https://goo.gl/IY8vuU -const ANSI_escape_codes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm +const ansiEscapeCodes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm // Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/hxz4S1 -const config_matcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm +const configMatcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm // Cross-os new-line characters. Visualization: https://goo.gl/q501uy const newlines = /[\n\r]/gm @@ -165,8 +165,8 @@ exports.middleware = store => next => action => { // Check for hyperlayout config if (type === 'SESSION_ADD_DATA') { - data = data.replace(ANSI_escape_codes, '') - const testedData = config_matcher.exec(data.trim()); + data = data.replace(ansiEscapeCodes, '') + const testedData = configMatcher.exec(data.trim()); if (testedData && testedData[1]) { const config = JSON.parse(testedData[1].replace(newlines, '')) hyperlayout = new Hyperlayout(config, store) From f0f8dd9327fbcabfc237f67b7c6fdb7e41c9ee0e Mon Sep 17 00:00:00 2001 From: Stereokai Date: Wed, 14 Dec 2016 15:35:04 +0200 Subject: [PATCH 4/4] Fix the rest of the linter errors --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 969f594..745fb31 100644 --- a/index.js +++ b/index.js @@ -22,8 +22,8 @@ const nextMode = mode => { // Matchers for retrieving config JSON from terminal // Remove ANSI escape code sequences. Visualization: https://goo.gl/IY8vuU const ansiEscapeCodes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm -// Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/hxz4S1 -const configMatcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm +// Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/afYmAO +const configMatcher = /(?:.|\s)*\[hyperlayout config]:((?:.|\s)*})(?:.|\s)*/gm // Cross-os new-line characters. Visualization: https://goo.gl/q501uy const newlines = /[\n\r]/gm @@ -159,14 +159,14 @@ function focusUid({dispatch}, uid) { // Listens for cli commands and sessions exports.middleware = store => next => action => { - const {type, data} = action + let {type, data} = action const {sessions} = store.getState() const {activeUid} = sessions // Check for hyperlayout config if (type === 'SESSION_ADD_DATA') { data = data.replace(ansiEscapeCodes, '') - const testedData = configMatcher.exec(data.trim()); + const testedData = configMatcher.exec(data.trim()) if (testedData && testedData[1]) { const config = JSON.parse(testedData[1].replace(newlines, '')) hyperlayout = new Hyperlayout(config, store)