typing-game-cli 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Results.js CHANGED
@@ -7,7 +7,8 @@ import Menu from './Menu.js';
7
7
  export default function Results({
8
8
  sortBy,
9
9
  isShowAllHistory,
10
- isCompactFormat
10
+ isCompactFormat,
11
+ topN
11
12
  }) {
12
13
  return isCompactFormat ? /*#__PURE__*/React.createElement(Box, {
13
14
  flexDirection: "column",
@@ -27,7 +28,8 @@ export default function Results({
27
28
  flexDirection: "column"
28
29
  }, getResults({
29
30
  sortBy: '-cpm',
30
- showAll: false
31
+ showAll: false,
32
+ topN
31
33
  }).map((result, i, array) => /*#__PURE__*/React.createElement(Box, {
32
34
  key: nanoid(),
33
35
  justifyContent: "center",
package/dist/app.js CHANGED
@@ -7,7 +7,7 @@ import Gradient from 'ink-gradient';
7
7
  import { proxy, useSnapshot } from 'valtio';
8
8
  import random from 'just-random';
9
9
  import { formatISO } from 'date-fns';
10
- import { getBorderColor, getDefaultSuite, getRobotBorderColor, getStatusVariant, getMessageOrPlaceholder, isFinished, isWordTyped, calculateWPM, getTypingWord, getRemainingPart, getWpmTextColor, calculateCPS, calculateCPM, getBestResult, getScoreTextColor, getCompetitionResult, registerResult, registerBestFrames, getBestFrames, getOpponentFrames } from './helpers.js';
10
+ import { getBorderColor, getDefaultSuite, getRobotBorderColor, getStatusVariant, getMessageOrPlaceholder, isFinished, isWordTyped, calculateWPM, getTypingWord, getRemainingPart, getWpmTextColor, calculateCPS, calculateCPM, getBestResult, getScoreTextColor, getCompetitionResult, registerResult, registerBestFrames, getBestFrames, getOpponentFrames, getSuiteByTopic } from './helpers.js';
11
11
  import { optionKeyColor } from './constants.js';
12
12
  import Results from './Results.js';
13
13
  import { config } from './config.js';
@@ -16,6 +16,7 @@ import { exitNow } from './cli.js';
16
16
  const currentTime = () => Date.now();
17
17
  const state = proxy({
18
18
  status: 'PAUSED',
19
+ topic: null,
19
20
  suite: getDefaultSuite(),
20
21
  source: null,
21
22
  firstPart: '',
@@ -53,15 +54,18 @@ const state = proxy({
53
54
  isTimerVisible: true,
54
55
  timerVisibilityCounter: 0,
55
56
  isAnimatingEnd: false,
56
- showGameResult: false
57
+ showGameResult: false,
58
+ topN: undefined
57
59
  });
58
60
  export default function App({
59
61
  robotLevel,
62
+ topic,
60
63
  displayResults = false,
61
64
  sortBy,
62
65
  isShowAllHistory,
63
66
  isCompactFormat,
64
- isCompetingAgainstBestResult
67
+ isCompetingAgainstBestResult,
68
+ topN
65
69
  }) {
66
70
  const snap = useSnapshot(state);
67
71
  const {
@@ -77,7 +81,14 @@ export default function App({
77
81
  if (isCompetingAgainstBestResult) {
78
82
  state.isAgainstMyselft = true;
79
83
  }
80
- }, [displayResults, isCompetingAgainstBestResult]);
84
+ if (topN) {
85
+ state.topN = topN;
86
+ }
87
+ if (topic) {
88
+ state.topic = topic;
89
+ state.suite = getSuiteByTopic(topic);
90
+ }
91
+ }, [displayResults, isCompetingAgainstBestResult, topN, topic]);
81
92
  useInput((input, key) => {
82
93
  if (input === 'y') {
83
94
  const foundBestResult = getBestResult();
@@ -216,7 +227,8 @@ export default function App({
216
227
  return /*#__PURE__*/React.createElement(Results, {
217
228
  sortBy: sortBy,
218
229
  isShowAllHistory: isShowAllHistory,
219
- isCompactFormat: isCompactFormat
230
+ isCompactFormat: isCompactFormat,
231
+ topN: topN
220
232
  });
221
233
  }
222
234
  return snap.status === 'PAUSED' ? /*#__PURE__*/React.createElement(Box, {
package/dist/cli.js CHANGED
@@ -25,6 +25,8 @@ const cli = meow(`
25
25
  --display-results Show cpm and wpm results
26
26
  --sort-by Sort results by specified value (-cpm, cpm, -wpm, wpm, -date, date), Starting "-" indicates descending order, default is "-date"
27
27
  --all-history Show all history when displaying results (otherwise (default) display last 10 results respecting sorting parameter)
28
+ --topic Use sentences from works written by specified author
29
+ --top-n Display top n results in displaying results mode
28
30
 
29
31
  Short flags and aliases for options:
30
32
  --against-my-best: -b, --best, --my-best, --myself, --against-my-best-result
@@ -36,6 +38,8 @@ const cli = meow(`
36
38
  --sort-by -s
37
39
  --show-all-history: -a, --all, --all-history
38
40
  --clear-results: -c, --clear
41
+ --topic: --author
42
+ --top-n: --top
39
43
 
40
44
 
41
45
  Examples
@@ -47,11 +51,14 @@ const cli = meow(`
47
51
  $ typing-game-cli -m
48
52
  $ typing-game-cli --low
49
53
  $ typing-game-cli --display-results
54
+ $ typing-game-cli --display-results --top 5
50
55
  $ typing-game-cli -r
51
56
  $ typing-game-cli -r --sort-by="-wpm"
52
57
  $ typing-game-cli -r -s="wpm"
53
58
  $ typing-game-cli -r -s="-wpm" --all-history
54
59
  $ typing-game-cli -r -s="-wpm" -a
60
+ $ typing-game-cli --topic mark-twain
61
+ $ typing-game-cli --author ambrose-bierce
55
62
  `, {
56
63
  importMeta: import.meta,
57
64
  flags: {
@@ -104,6 +111,14 @@ const cli = meow(`
104
111
  type: 'boolean',
105
112
  aliases: ['cmpc'],
106
113
  default: false
114
+ },
115
+ topN: {
116
+ type: 'number',
117
+ aliases: ['top']
118
+ },
119
+ topic: {
120
+ type: 'string',
121
+ aliases: ['author']
107
122
  }
108
123
  }
109
124
  });
@@ -119,7 +134,9 @@ const {
119
134
  sortBy,
120
135
  showAllHistory,
121
136
  againstMyBest,
122
- compactResult
137
+ compactResult,
138
+ topN,
139
+ topic
123
140
  } = cli.flags;
124
141
  render(/*#__PURE__*/React.createElement(App, {
125
142
  robotLevel: robotLevel,
@@ -127,6 +144,8 @@ render(/*#__PURE__*/React.createElement(App, {
127
144
  sortBy: sortBy,
128
145
  isShowAllHistory: showAllHistory,
129
146
  isCompetingAgainstBestResult: againstMyBest,
130
- isCompactFormat: compactResult
147
+ isCompactFormat: compactResult,
148
+ topN: topN,
149
+ topic: topic
131
150
  }));
132
151
  export { exitNow };
package/dist/helpers.js CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { fdir as Fdir } from 'fdir';
5
5
  import random from 'just-random';
6
+ import compose from 'just-compose';
6
7
  import sortBy from 'just-sort-by';
7
8
  import { format, formatISO, isValid, parseISO } from 'date-fns';
8
9
  import Config from './config.js';
@@ -15,6 +16,13 @@ const sourcesPath = path.join(__dirname, 'sentences');
15
16
  const isWon = value => value === won;
16
17
  const isLost = value => value === lost;
17
18
  const files = new Fdir().filter((path, _isDirectory) => path.endsWith('.json')).withFullPaths().crawl(sourcesPath).sync();
19
+ const getFilesByTopic = topic => {
20
+ return new Fdir().filter((path, _isDirectory) => path.endsWith('.json')).withFullPaths().crawl(path.join(sourcesPath, topic)).sync();
21
+ };
22
+ const readFile = file => fs.readFileSync(file, 'utf8');
23
+ const getSuiteByTopic = topic => {
24
+ return compose(getFilesByTopic, random, readFile, JSON.parse)(topic);
25
+ };
18
26
  const getDefaultSuite = () => {
19
27
  return JSON.parse(fs.readFileSync(random(files), 'utf8'));
20
28
  };
@@ -109,7 +117,8 @@ const getRemainingPart = (source, typed, hasErroredPart = false) => {
109
117
  };
110
118
  const getResults = ({
111
119
  sortBy: sortByValue = '-wpm',
112
- showAll = false
120
+ showAll = false,
121
+ topN
113
122
  }) => {
114
123
  const config = new Config();
115
124
  const data = config.get();
@@ -140,7 +149,7 @@ const getResults = ({
140
149
  return -parseISO(item.date);
141
150
  });
142
151
  if (!showAll) {
143
- return result.slice(0, 10);
152
+ return result.slice(0, topN === undefined ? 10 : topN);
144
153
  }
145
154
  return result;
146
155
  };
@@ -210,4 +219,4 @@ const registerBestFrames = (config, frames) => {
210
219
  bestFrames: frames
211
220
  });
212
221
  };
213
- export { getDefaultSuite, getStatusVariant, getWpmTextColor, getScoreTextColor, getMessage, getMessageOrPlaceholder, getBorderColor, getRobotBorderColor, getIntervalMs, isFinished, isWordTyped, calculateWPM, calculateCPS, calculateCPM, getCompetitionResult, getTypingWord, getRemainingPart, getResults, getBestResult, getBestResultCompactString, getBestFrames, getOpponentFrames, getResultByWordCount, getBestWpmResult, getSortedByString, getWordCount, registerResult, registerBestFrames };
222
+ export { getDefaultSuite, getStatusVariant, getWpmTextColor, getScoreTextColor, getMessage, getMessageOrPlaceholder, getBorderColor, getRobotBorderColor, getIntervalMs, isFinished, isWordTyped, calculateWPM, calculateCPS, calculateCPM, getCompetitionResult, getTypingWord, getRemainingPart, getResults, getBestResult, getBestResultCompactString, getBestFrames, getOpponentFrames, getResultByWordCount, getBestWpmResult, getSortedByString, getWordCount, getSuiteByTopic, registerResult, registerBestFrames };
@@ -0,0 +1,16 @@
1
+ {
2
+ "sentences": [
3
+ "For several days, in snow and rain, General Schofield's little army had crouched in its hastily constructed defenses at Columbia, Tennessee. It had retreated in hot haste from Pulaski, thirty miles to the south, arriving just in time to foil Hood, who, marching from Florence, Alabama, by another road, with a force of more than double our strength, had hoped to intercept us. Had he succeeded, he would indubitably have bagged the whole bunch of us.",
4
+ "As it was, he simply took position in front of us and gave us plenty of employment, but did not attack; he knew a trick worth two of that. Duck River was directly in our rear; I suppose both our flanks rested on it. The town was between them. One night--that of November 27, 1864--we pulled up stakes and crossed to the north bank to continue our retreat to Nashville, where Thomas and safety lay - such safety as is known in war.",
5
+ "It was high time too, for before noon of the next day Forrest's cavalry forded the river a few miles above us and began pushing back our own horse toward Spring Hill, ten miles in our rear, on our only road. Why our infantry was not immediately put in motion toward the threatened point, so vital to our safety, General Schofield could have told better than I. Howbeit, we lay there inactive all day. The next morning - a bright and beautiful one - the brigade of Colonel P. Sidney Post was thrown out, up the river four or five miles, to see what it could see.",
6
+ "What it saw was Hood's head-of-column coming over on a pontoon bridge, and a right pretty spectacle it would have been to one whom it did not concern. It concerned us rather keenly. As a member of Colonel Post's staff, I was naturally favored with a good view of the performance. We formed in line of battle at a distance of perhaps a half-mile from the bridge-head, but that unending column of gray and steel gave us no more attention than if we had been a crowd of farmer-folk. Why should it?",
7
+ "It had only to face to the left to be itself a line of battle. Meantime it had more urgent business on hand than brushing away a small brigade whose only offense was curiosity; it was making for Spring Hill with all its legs and wheels. Hour after hour we watched that unceasing flow of infantry and artillery toward the rear of our army. It was an unnerving spectacle, yet we never for a moment doubted that, acting on the intelligence supplied by our succession of couriers, our entire force was moving rapidly to the point of contact. The battle of Spring Hill was obviously decreed.",
8
+ "Obviously, too, our brigade of observation would be among the last to have a hand in it. The thought annoyed us, made us restless and resentful. Our mounted men rode forward and back behind the line, nervous and distressed; the men in the ranks sought relief in frequent changes of posture, in shifting their weight from one leg to the other, in needless inspection of their weapons and in that unfailing resource of the discontented soldier, audible damning of those in the saddles of authority. But never for more than a moment at a time did anyone remove his eyes from that fascinating and portentous pageant.",
9
+ "Toward evening we were recalled, to learn that of our five divisions of infantry, with their batteries, numbering twenty-three thousand men, only one--Stanley's, four thousand weak--had been sent to Spring Hill to meet that formidable movement of Hood's three veteran corps! Why Stanley was not immediately effaced is still a matter of controversy. Hood, who was early on the ground, declared that he gave the needful orders and tried vainly to enforce them; Cheatham, in command of his leading corps, declared that he did not.",
10
+ "Doubtless the dispute is still being carried on between these chieftains from their beds of asphodel and moly in Elysium. So much is certain: Stanley drove away Forrest and successfully held the junction of the roads against Cleburne's division, the only infantry that attacked him. That night the entire Confederate army lay within a half mile of our road, while we all sneaked by, infantry, artillery, and trains. The enemy's camp-fires shone redly - miles of them - seeming only a stone's throw from our hurrying column.",
11
+ "His men were plainly visible about them, cooking their suppers - a sight so incredible that many of our own, thinking them friends, strayed over to them and did not return. At intervals of a few hundred yards we passed dim figures on horseback by the roadside, enjoining silence. Needless precaution; we could not have spoken if we had tried, for our hearts were in our throats. But fools are God's peculiar care, and one of his protective methods is the stupidity of other fools. By daybreak our last man and last wagon had passed the fateful spot unchallenged, and our first were entering Franklin, ten miles away.",
12
+ "Despite spirited cavalry attacks on trains and rear-guard, all were in Franklin by noon and such of the men as could be kept awake were throwing up a slight line of defense, inclosing the town. Franklin lies - or at that time did lie; I know not what exploration might now disclose - on the south bank of a small river, the Harpeth by name. For two miles southward was a nearly flat, open plain, extending to a range of low hills through which passed the turnpike by which we had come.",
13
+ "From some bluffs on the precipitous north bank of the river was a commanding overlook of all this open ground, which, although more than a mile away, seemed almost at one's feet. On this elevated ground the wagon-train had been parked and General Schofield had stationed himself - the former for security, the latter for outlook. Both were guarded by General Wood's infantry division, of which my brigade was a part. \"We are in beautiful luck,\" said a member of the division staff. With some prevision of what was to come and a lively recollection of the nervous strain of helpless observation, I did not think it luck."
14
+ ],
15
+ "tags": ["ambrose-bierce", "what-occured-at-franklin"]
16
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typing-game-cli",
3
3
  "description": "Command line game to practice your typing speed by competing against typer-robot or against your best result",
4
- "version": "5.0.0",
4
+ "version": "6.0.0",
5
5
  "homepage": "https://github.com/akgondber/typing-game-cli",
6
6
  "repository": "akgondber/typing-game-cli",
7
7
  "author": "Rushan Alyautdinov <akgondber@gmail.com>",
package/readme.md CHANGED
@@ -31,6 +31,8 @@ $ npm install --global typing-game-cli
31
31
  --sort-by Sort results by specified value (-cpm, cpm, -wpm, wpm, -date, date), Starting "-" indicates descending order, default is "-date"
32
32
  --all-hostory Show all history when displaying results (otherwise (default) display last 10 results respecting sorting parameter)
33
33
  --compact-result Display top result in compact format
34
+ --topic Use sentences from works written by specified author
35
+ --top-n Display top n results when `--display-results` is being used
34
36
 
35
37
  Short flags and aliases for options:
36
38
  --against-my-best: -b, --best, --my-best, --myself, --against-my-best-result
@@ -43,6 +45,8 @@ $ npm install --global typing-game-cli
43
45
  --show-all-history: -a, --all, --all-history
44
46
  --clear-results: -c, --clear
45
47
  --compact-result --cmpc
48
+ --topic --author
49
+ --top-n --top
46
50
 
47
51
 
48
52
  Examples
@@ -54,11 +58,14 @@ $ npm install --global typing-game-cli
54
58
  $ typing-game-cli -m
55
59
  $ typing-game-cli --low
56
60
  $ typing-game-cli --display-results
61
+ $ typing-game-cli --display-results --top 3
57
62
  $ typing-game-cli -r
58
63
  $ typing-game-cli -r --sort-by="-wpm"
59
64
  $ typing-game-cli -r -s="wpm"
60
65
  $ typing-game-cli -r -s="-wpm" --all-history
61
66
  $ typing-game-cli -r -s="-wpm" -a
67
+ $ typing-game-cli --topic ambrose-bierce
68
+ $ typing-game-cli --author mark-twain
62
69
  ```
63
70
 
64
71
  ## Demo
@@ -93,6 +100,10 @@ $ tgc -b
93
100
 
94
101
  ![](media/competition-against-best-result-2.png)
95
102
 
103
+ #### Example - Display top n results
104
+
105
+ ![](media/display-top-n-results.png)
106
+
96
107
  ## License
97
108
 
98
109
  MIT © [Rushan Alyautdinov](https://github.com/akgondber)