Skip to content

Commit

Permalink
fix(command-listener): fix stdout.write entered letters
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Apr 28, 2018
1 parent 8fdab78 commit 0eb9969
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ lerna-terminal-0.0.0-semantically-released.tgz
.vscode

npm-debug.log*
log.txt
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"src/*.{js}",
"src/*/*.{js}",
"!src/index.js",
"!src/log.js",
"!src/resolve/index.js",
"!src/resolve/resolve-dependency.js"
]
Expand Down
5 changes: 5 additions & 0 deletions src/commandListener/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const onReturn = onCommandEntered => {
};

const onRecieveLetter = letter => {
if (!letter) {
return;
}
buffer += letter;
getUiState().onChange(buffer);
};
Expand Down Expand Up @@ -102,11 +105,13 @@ function commandListener(onCommandEntered) {
return;
}

/* istanbul ignore else case */
if (keyNameMap[key.name]) {
keyNameMap[key.name](onCommandEntered);
return;
}
}
onRecieveLetter(letter);
});
process.stdin.resume();
}
Expand Down
18 changes: 18 additions & 0 deletions src/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');
const path = require('path');

const logFilePath = path.resolve(__dirname, '..', 'log.txt');

const readLog = () => {
try {
return fs.readFileSync(logFilePath, 'utf8');
} catch (err) {
return '';
}
};

const log = value => {
fs.writeFileSync(logFilePath, `${readLog()}\n[${new Date()}]: ${value}`);
};

module.exports = log;

0 comments on commit 0eb9969

Please sign in to comment.