Skip to content

Commit

Permalink
Fix cursor in terminal app (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeliog authored and SimenB committed Jan 22, 2019
1 parent bd33979 commit ddaa93a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"format": "prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
},
"dependencies": {
"ansi-escapes": "^3.0.0",
"chalk": "^2.4.1",
"jest-watcher": "^23.1.0",
"slash": "^1.0.0",
Expand Down
21 changes: 14 additions & 7 deletions src/file_name_plugin/__tests__/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

exports[`can select a pattern that matches multiple files 1`] = `
[MOCK - cursorLeft]
pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 3 files
Expand All @@ -18,10 +19,11 @@ exports[`can select a pattern that matches multiple files 1`] = `
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
[MOCK - cursorLeft]
pattern › fi
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 files
Expand All @@ -35,10 +37,11 @@ exports[`can select a pattern that matches multiple files 1`] = `

exports[`can use arrows to select a specific file 1`] = `
[MOCK - cursorLeft]
pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 3 files
Expand All @@ -51,10 +54,11 @@ exports[`can use arrows to select a specific file 1`] = `
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
[MOCK - cursorLeft]
pattern › fi
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 files
Expand All @@ -65,10 +69,11 @@ exports[`can use arrows to select a specific file 1`] = `
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
[MOCK - cursorLeft]
pattern › fi
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 files
Expand All @@ -82,10 +87,11 @@ exports[`can use arrows to select a specific file 1`] = `

exports[`file matching is case insensitive 1`] = `
[MOCK - cursorLeft]
pattern › fI
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 files
Expand All @@ -108,10 +114,11 @@ Pattern Mode Usage
[MOCK - cursorShow]
[MOCK - cursorLeft]
pattern ›
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Start typing to filter by a filename regex pattern.
Expand Down
3 changes: 3 additions & 0 deletions src/file_name_plugin/prompt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import chalk from 'chalk';
import ansiEscapes from 'ansi-escapes';
import stringLength from 'string-length';
import {
Prompt,
Expand Down Expand Up @@ -46,6 +47,8 @@ export default class FileNamePatternPrompt extends PatternPrompt {

printPatternCaret(pattern, pipe);

pipe.write(ansiEscapes.cursorLeft);

if (pattern) {
printPatternMatches(total, 'file', pipe);

Expand Down
24 changes: 16 additions & 8 deletions src/test_name_plugin/__tests__/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

exports[`can select a pattern that matches multiple tests 1`] = `
[MOCK - cursorLeft]
pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 tests from cached test suites
Expand All @@ -16,10 +17,11 @@ exports[`can select a pattern that matches multiple tests 1`] = `
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
[MOCK - cursorLeft]
pattern › fo
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 tests from cached test suites
Expand All @@ -33,10 +35,11 @@ exports[`can select a pattern that matches multiple tests 1`] = `

exports[`can use arrows to select a specific test 1`] = `
[MOCK - cursorLeft]
pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 tests from cached test suites
Expand All @@ -47,10 +50,11 @@ exports[`can use arrows to select a specific test 1`] = `
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
[MOCK - cursorLeft]
pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 tests from cached test suites
Expand All @@ -61,10 +65,11 @@ exports[`can use arrows to select a specific test 1`] = `
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
[MOCK - cursorLeft]
pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 tests from cached test suites
Expand All @@ -87,10 +92,11 @@ Pattern Mode Usage
[MOCK - cursorShow]
[MOCK - cursorLeft]
pattern ›
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Start typing to filter by a test name regex pattern.
Expand All @@ -109,10 +115,11 @@ Pattern Mode Usage
[MOCK - cursorShow]
[MOCK - cursorLeft]
pattern ›
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Start typing to filter by a test name regex pattern.
Expand All @@ -122,10 +129,11 @@ Pattern Mode Usage

exports[`test matching is case insensitive 1`] = `
[MOCK - cursorLeft]
pattern › fO
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
Pattern matches 2 tests from cached test suites
Expand Down
3 changes: 3 additions & 0 deletions src/test_name_plugin/prompt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import chalk from 'chalk';
import ansiEscapes from 'ansi-escapes';
import {
Prompt,
PatternPrompt,
Expand Down Expand Up @@ -45,6 +46,8 @@ class TestNamePatternPrompt extends PatternPrompt {

printPatternCaret(pattern, pipe);

pipe.write(ansiEscapes.cursorLeft);

if (pattern) {
printPatternMatches(
total,
Expand Down
1 change: 1 addition & 0 deletions src/test_utils/pluginTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ expect.addSnapshotSerializer({
jest.mock('ansi-escapes', () => ({
clearScreen: '[MOCK - clearScreen]',
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
cursorLeft: '[MOCK - cursorLeft]',
cursorHide: '[MOCK - cursorHide]',
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
cursorSavePosition: '[MOCK - cursorSavePosition]',
Expand Down

0 comments on commit ddaa93a

Please sign in to comment.