implemented bracketed paste for file upload

cpsdqs/unified-input
Ondřej Hruška 7 years ago
parent fd2a6df245
commit 58dd0c929f
  1. 4
      js/term.js
  2. 3
      js/term_screen.js
  3. 27
      js/term_upload.js

@ -1,11 +1,11 @@
/** Init the terminal sub-module - called from HTML */ /** Init the terminal sub-module - called from HTML */
window.termInit = function (opts) { window.termInit = function (opts) {
let { labels, theme, allFn } = opts let { labels, theme, allFn } = opts
const screen = new TermScreen() const screen = new TermScreen()
const conn = Conn(screen) const conn = Conn(screen)
const input = Input(conn) const input = Input(conn)
const termUpload = TermUpl(conn, input) const termUpload = TermUpl(conn, input, screen)
screen.input = input screen.input = input
conn.init() conn.init()

@ -159,6 +159,7 @@ window.TermScreen = class TermScreen {
} }
}) })
this.bracketedPaste = false
this.blinkingCellCount = 0 this.blinkingCellCount = 0
this.screen = [] this.screen = []
@ -1129,6 +1130,8 @@ window.TermScreen = class TermScreen {
$('.x-term-conf-btn').toggleClass('hidden', !showConfigLinks) $('.x-term-conf-btn').toggleClass('hidden', !showConfigLinks)
$('#action-buttons').toggleClass('hidden', !showButtons) $('#action-buttons').toggleClass('hidden', !showButtons)
this.bracketedPaste = !!(attributes & (1 << 13))
// content // content
let fg = 7 let fg = 7
let bg = 0 let bg = 0

@ -1,5 +1,5 @@
/** File upload utility */ /** File upload utility */
window.TermUpl = function (conn, input) { window.TermUpl = function (conn, input, screen) {
let lines, // array of lines without newlines let lines, // array of lines without newlines
line_i, // current line index line_i, // current line index
fuTout, // timeout handle for line sending fuTout, // timeout handle for line sending
@ -72,7 +72,20 @@ window.TermUpl = function (conn, input) {
} }
if (inline_pos === 0) { 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 let chunk
@ -84,14 +97,14 @@ window.TermUpl = function (conn, input) {
inline_pos += MAX_LINE_LEN inline_pos += MAX_LINE_LEN
} }
console.log(chunk)
if (!input.sendString(chunk)) { if (!input.sendString(chunk)) {
updateStatus('FAILED!') updateStatus('FAILED!')
return return
} }
let all = lines.length let pt = Math.round((line_i / lines.length) * 1000) / 10
updateStatus(`${line_i} / ${lines.length} (${pt}%)`)
updateStatus(line_i + ' / ' + all + ' (' + (Math.round((line_i / all) * 1000) / 10) + '%)')
if (lines.length > line_i || inline_pos > 0) { if (lines.length > line_i || inline_pos > 0) {
fuTout = setTimeout(uploadLine, send_delay_ms) fuTout = setTimeout(uploadLine, send_delay_ms)
@ -108,9 +121,7 @@ window.TermUpl = function (conn, input) {
} else { } else {
updateStatus('Done.') updateStatus('Done.')
// delay to show it // delay to show it
setTimeout(function () { fuClose()
fuClose()
}, 100)
} }
} }

Loading…
Cancel
Save