From 58dd0c929f6154d30e4ad1a617f507c4d95eabb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 12 Sep 2017 00:39:36 +0200 Subject: [PATCH] implemented bracketed paste for file upload --- js/term.js | 4 ++-- js/term_screen.js | 3 +++ js/term_upload.js | 27 +++++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/js/term.js b/js/term.js index b1bc897..ddd05af 100644 --- a/js/term.js +++ b/js/term.js @@ -1,11 +1,11 @@ /** Init the terminal sub-module - called from HTML */ window.termInit = function (opts) { let { labels, theme, allFn } = opts + const screen = new TermScreen() const conn = Conn(screen) const input = Input(conn) - const termUpload = TermUpl(conn, input) - + const termUpload = TermUpl(conn, input, screen) screen.input = input conn.init() diff --git a/js/term_screen.js b/js/term_screen.js index 7d38f6e..9573df4 100644 --- a/js/term_screen.js +++ b/js/term_screen.js @@ -159,6 +159,7 @@ window.TermScreen = class TermScreen { } }) + this.bracketedPaste = false this.blinkingCellCount = 0 this.screen = [] @@ -1129,6 +1130,8 @@ window.TermScreen = class TermScreen { $('.x-term-conf-btn').toggleClass('hidden', !showConfigLinks) $('#action-buttons').toggleClass('hidden', !showButtons) + this.bracketedPaste = !!(attributes & (1 << 13)) + // content let fg = 7 let bg = 0 diff --git a/js/term_upload.js b/js/term_upload.js index c010c55..e399c4b 100644 --- a/js/term_upload.js +++ b/js/term_upload.js @@ -1,5 +1,5 @@ /** File upload utility */ -window.TermUpl = function (conn, input) { +window.TermUpl = function (conn, input, screen) { let lines, // array of lines without newlines line_i, // current line index fuTout, // timeout handle for line sending @@ -72,7 +72,20 @@ window.TermUpl = function (conn, input) { } if (inline_pos === 0) { - curLine = lines[line_i++] + nl_str + curLine = '' + if (line_i === 0) { + if (screen.bracketedPaste) { + curLine = '\x1b[200~' + } + } + + curLine += lines[line_i++] + nl_str + + if (line_i === lines.length) { + if (screen.bracketedPaste) { + curLine += '\x1b[201~' + } + } } let chunk @@ -84,14 +97,14 @@ window.TermUpl = function (conn, input) { inline_pos += MAX_LINE_LEN } + console.log(chunk) if (!input.sendString(chunk)) { updateStatus('FAILED!') return } - let all = lines.length - - updateStatus(line_i + ' / ' + all + ' (' + (Math.round((line_i / all) * 1000) / 10) + '%)') + let pt = Math.round((line_i / lines.length) * 1000) / 10 + updateStatus(`${line_i} / ${lines.length} (${pt}%)`) if (lines.length > line_i || inline_pos > 0) { fuTout = setTimeout(uploadLine, send_delay_ms) @@ -108,9 +121,7 @@ window.TermUpl = function (conn, input) { } else { updateStatus('Done.') // delay to show it - setTimeout(function () { - fuClose() - }, 100) + fuClose() } }