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. 25
      js/term_upload.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()

@ -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

@ -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)
}
}

Loading…
Cancel
Save