Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add multiline support #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

GavinRay97
Copy link

This will allow you to press shift + enter by maintaining a queue of 2 keycodes from last pressed keys.

I had to use iohook library to be able to capture JUST shift key presses. I did not take a ton of time to set it up properly, so it does not teardown listener and has a memory leak.

Also, I cant get the evaluate to work properly with multiline, but this is a good start I think.

		ioHook.on('keypress', (event: IOHookEvent) => {
			if (lastKeys.length < 2) lastKeys.push(event)
		          else {
				lastKeys.pop()
				lastKeys.unshift(event)
			}
		});
			else if (name === 'return') {
				const lastKey = lastKeys.concat().pop()
				if (lastKey!.shiftKey) {
					stdout.write('\n')
					rl.write('\n')
				} 

This will allow you to press shift + enter by maintaining a queue of 2 keycodes from last pressed keys.

I had to use `iohook` library to be able to capture JUST shift key presses. I did not take a ton of time to set it up properly, so it does not teardown listener and has a memory leak.

Also, I cant get the evaluate to work properly with multiline, but this is a good start I think.

```ts
		ioHook.on('keypress', (event: IOHookEvent) => {
			if (lastKeys.length < 2) lastKeys.push(event)
		          else {
				lastKeys.pop()
				lastKeys.unshift(event)
			}
		});```
```ts
			} else if (name === 'return') {
				const lastKey = lastKeys.concat().pop()
				if (lastKey!.shiftKey) {
					stdout.write('\n')
					rl.write('\n')
				} else {
```
@GavinRay97
Copy link
Author

Whoops, forgot to add you need to npm install iohook

@schfkt
Copy link

schfkt commented Dec 16, 2019

@GavinRay97

Whoops, forgot to add you need to npm install iohook

Add it into dependencies in the package.json then: https://github.com/nikersify/jay/blob/master/package.json#L29 . More info https://docs.npmjs.com/files/package.json#dependencies

@GavinRay97
Copy link
Author

@GavinRay97

Whoops, forgot to add you need to npm install iohook

Add it into dependencies in the package.json then: https://github.com/nikersify/jay/blob/master/package.json#L29 . More info https://docs.npmjs.com/files/package.json#dependencies

Yeah for sure, I am super familiar with JS/TS dev I just blanked on commit the dependency.
It still will not work properly due to not triggering the evaluation on enter though, so might need someone else (maybe @nikersify) to help figure out that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants