-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Add arrows selection to typeahead #3386
Merged
+582
−294
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3d6f27e
Add typeahead arrow selection
rogeliog 0bfdbf0
Handle max typeahead max offset
rogeliog 0ed7001
Add tests for scroll list
rogeliog 3d9991e
Add simple tests to typeheahead selection
rogeliog 8aa6fb9
Clear typeahead selection on enter
rogeliog ffc8b94
Fix prompt test
rogeliog 4ff8918
Refactor pattern prompts
thymikee b253111
Stress 'cached' in TestNamePatternPrompt
thymikee 23ea04c
Fix eslint
thymikee 06ed992
Fix scrolling edgecase
thymikee 6370943
Live update number of remaining typeahead items
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {ScrollOptions} from './lib/scrollList'; | ||
|
||
const chalk = require('chalk'); | ||
const ansiEscapes = require('ansi-escapes'); | ||
const Prompt = require('./lib/Prompt'); | ||
|
||
const usage = (entity: string) => | ||
`\n${chalk.bold('Pattern Mode Usage')}\n` + | ||
` ${chalk.dim('\u203A Press')} Esc ${chalk.dim('to exit pattern mode.')}\n` + | ||
` ${chalk.dim('\u203A Press')} Enter ` + | ||
`${chalk.dim(`to apply pattern to all ${entity}.`)}\n` + | ||
`\n`; | ||
|
||
const usageRows = usage('').split('\n').length; | ||
|
||
module.exports = class PatternPrompt { | ||
_pipe: stream$Writable | tty$WriteStream; | ||
_prompt: Prompt; | ||
_entityName: string; | ||
_currentUsageRows: number; | ||
|
||
constructor(pipe: stream$Writable | tty$WriteStream, prompt: Prompt) { | ||
this._pipe = pipe; | ||
this._prompt = prompt; | ||
this._currentUsageRows = usageRows; | ||
} | ||
|
||
run(onSuccess: Function, onCancel: Function, options?: {header: string}) { | ||
this._pipe.write(ansiEscapes.cursorHide); | ||
this._pipe.write(ansiEscapes.clearScreen); | ||
|
||
if (options && options.header) { | ||
this._pipe.write(options.header + '\n'); | ||
this._currentUsageRows = usageRows + options.header.split('\n').length; | ||
} else { | ||
this._currentUsageRows = usageRows; | ||
} | ||
|
||
this._pipe.write(usage(this._entityName)); | ||
this._pipe.write(ansiEscapes.cursorShow); | ||
|
||
this._prompt.enter(this._onChange.bind(this), onSuccess, onCancel); | ||
} | ||
|
||
_onChange(pattern: string, options: ScrollOptions) { | ||
this._pipe.write(ansiEscapes.eraseLine); | ||
this._pipe.write(ansiEscapes.cursorLeft); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could use this._entityName, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, nevermind, it's more of a coincidence that they line up. Let's keep it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now that I'm mixing singular with plural in couple of places, need to fix it properly.