diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-05 12:07:02 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-05 18:15:24 +0900 |
commit | 5e124e7561b355758a68f79d3ecf10148f8ecdd5 (patch) | |
tree | 48c0b1d65133aaa351584c48f5b8165007fb2b34 /src | |
parent | 40dce0ca6e7eaffcc214327f72ba17d307daad44 (diff) |
add Completion class
Diffstat (limited to 'src')
-rw-r--r-- | src/console/completion.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/console/completion.js b/src/console/completion.js new file mode 100644 index 0000000..0c21cb0 --- /dev/null +++ b/src/console/completion.js @@ -0,0 +1,26 @@ +export default class Completion { + constructor(completions) { + if (typeof completions.length !== 'number') { + throw new TypeError('completions does not have a length in number'); + } + this.completions = completions + this.index = 0; + } + + prev() { + if (this.completions.length === 0) { + return null; + } + this.index = (this.index + this.completions.length - 1) % this.completions.length + return this.completions[this.index]; + } + + next() { + if (this.completions.length === 0) { + return null; + } + let item = this.completions[this.index]; + this.index = (this.index + 1) % this.completions.length + return item; + } +} |