Skip to content

Commit

Permalink
remove std dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriytat committed May 9, 2022
1 parent b9cfee6 commit b538516
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Reads key from stdin.

### Try

```deno run --unstable https://deno.land/x/keypress@0.0.7/readKeypress_test.ts```
```deno run --unstable https://deno.land/x/keypress@0.0.8/readKeypress_test.ts```

```ts
// CTRL + C keypress
Expand All @@ -25,7 +25,7 @@ const keypress: Keypress = {
Read from Deno.stdin by default:

```ts
import { readKeypress } from "https://deno.land/x/keypress@0.0.7/mod.ts";
import { readKeypress } from "https://deno.land/x/keypress@0.0.8/mod.ts";

for await (const keypress of readKeypress()) {
console.log(keypress);
Expand All @@ -39,7 +39,7 @@ for await (const keypress of readKeypress()) {
Read from TTY:

```ts
import { readKeypress } from "https://deno.land/x/keypress@0.0.7/mod.ts";
import { readKeypress } from "https://deno.land/x/keypress@0.0.8/mod.ts";

const tty = await Deno.open("/dev/ttys003");

Expand Down
1 change: 0 additions & 1 deletion dep.ts

This file was deleted.

7 changes: 3 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {decode, encode} from "./dep.ts";

export interface Keypress {
key: string | undefined,
code: string | undefined,
Expand Down Expand Up @@ -46,7 +44,7 @@ const charsRe = /^[A-zА-яЁё]$/;
export function decodeKeypress(message: Uint8Array): Keypress[] {
let parts;

let sequence = decode(message);
let sequence = new TextDecoder().decode(message);
let event: Keypress = {
key: undefined,
code: undefined,
Expand Down Expand Up @@ -380,8 +378,9 @@ export function decodeKeypress(message: Uint8Array): Keypress[] {
} else if (sequence.length > 1 && sequence[0] !== '\x1b') {
// Got a longer-than-one string of characters.
// Probably a paste, since it wasn't a control sequence.
const encoder = new TextEncoder();
const results: Keypress[][] = sequence.split('')
.map(character => decodeKeypress(encode(character)));
.map(character => decodeKeypress(encoder.encode(character)));

return results.flat();
}
Expand Down

0 comments on commit b538516

Please sign in to comment.