heapwolf / prompt-sync

a synchronous prompt for node.js
MIT License
211 stars 42 forks source link

Pasting does not work #21

Closed mcollina closed 7 years ago

mcollina commented 7 years ago

As titled, pasting something into prompt-sync does not work :(. I'm using node v4.4.5.

cc @davidmarkclements

heapwolf commented 7 years ago

Hmm, I have a program that I created where I paste into prompt-sync almost daily, so i know it works fine in at least one configuration. Can you add some detail?

mcollina commented 7 years ago

Mac OS X, tmux, iTerm2 (v3), node v4.4.5 and this code:

'use strict'

const prompt = require('prompt-sync')()
const n = prompt('Hello? ')

console.log(n)
davidmarkclements commented 7 years ago

yah I'm able to reproduce - OS x, iterm 3 (not using tmux), node 6

davidmarkclements commented 7 years ago

this could be tricky - the awesome thing about prompt-sync is no native dependencies, not sure how we fix this without using native deps

davidmarkclements commented 7 years ago

I mean - sure you we can tap into pbcopy/pbpaste, xclip etc., and we can detect cmd+v / ctrl + v but not sure how we cover right click & paste (or edit menu -> paste) etc.

heapwolf commented 7 years ago

Still confused, my pxx program works perfectly, I paste into it every day, it's worked for over a year, different versions of node and iTerm, are we talking about different things?

heapwolf commented 7 years ago

I take that back, pxx isn't using prompt-sync... Hmm, not sure what I'm using prompt-sync for any more ;)

heapwolf commented 7 years ago

@davidmarkclements ok, so i just cloned and took a quick look. i copied some text and tried to paste it. What happens is that i get a single character of the text that i copied. For instance if i copy FOO, it only pastes O. I think this just needs to detect the paste key combination and then insert that value into the buffer.

davidmarkclements commented 7 years ago

ok just looked into real quick and it's totally fixable - it's because we assume one character per stdin buffer - all we have to do is analyse the buffer a little more and do the right thing (it currently already detects a 3 char input for control characters, we just do something similar for paste)