Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const createElement = root => {
el.value = '';

root.appendChild(el);
document.body.ontouchend = function() { el.focus(); };

return el;
};
Expand Down Expand Up @@ -128,7 +129,7 @@ const executor = commands => (cmd, ...args) => cb => {
};

// Handle keyboard events
const keyboard = (parse) => {
const keyboard = ($element, prompt, parse) => {
let input = [];
const keys = {8: 'backspace', 13: 'enter'};
const ignoreKey = code => code >= 33 && code <= 40;
Expand All @@ -138,7 +139,7 @@ const keyboard = (parse) => {
keypress: (ev) => {
if (key(ev) === 'enter') {
const str = input.join('').trim();
parse(str);
parse(str || $element.value.split(/\n/)[$element.value.split(/\n/).length - 1].replace(prompt(), ''));
input = [];
} else if (key(ev) !== 'backspace') {
input.push(String.fromCharCode(ev.which || ev.keyCode));
Expand Down Expand Up @@ -190,7 +191,7 @@ export const terminal = (opts) => {
const render = renderer(tickrate, onrender);
const parse = parser(onparsed);
const focus = () => setTimeout(() => $element.focus(), 1);
const kbd = keyboard(parse);
const kbd = keyboard($element, prompt, parse);
const clear = () => ($element.value = '');
const input = ev => busy
? ev.preventDefault()
Expand Down