ttyping 0.1.0__py3-none-any.whl
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.
- ttyping/__init__.py +3 -0
- ttyping/__main__.py +61 -0
- ttyping/app.py +70 -0
- ttyping/screens.py +553 -0
- ttyping/storage.py +36 -0
- ttyping/words.py +69 -0
- ttyping-0.1.0.dist-info/METADATA +53 -0
- ttyping-0.1.0.dist-info/RECORD +11 -0
- ttyping-0.1.0.dist-info/WHEEL +4 -0
- ttyping-0.1.0.dist-info/entry_points.txt +2 -0
- ttyping-0.1.0.dist-info/licenses/LICENSE +201 -0
ttyping/__init__.py
ADDED
ttyping/__main__.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""CLI entry point for ttyping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main() -> None:
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="ttyping",
|
|
12
|
+
description="A minimal terminal typing test",
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"--lang",
|
|
16
|
+
choices=["en", "ko"],
|
|
17
|
+
default="en",
|
|
18
|
+
help="language for random words (default: en)",
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"--file",
|
|
22
|
+
type=str,
|
|
23
|
+
default=None,
|
|
24
|
+
help="path to a text file for typing practice",
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--words",
|
|
28
|
+
type=int,
|
|
29
|
+
default=25,
|
|
30
|
+
help="number of words to type (default: 25)",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--time",
|
|
34
|
+
"-t",
|
|
35
|
+
type=int,
|
|
36
|
+
default=None,
|
|
37
|
+
help="duration of the test in seconds (overrides --words)",
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"command",
|
|
41
|
+
nargs="?",
|
|
42
|
+
choices=["history"],
|
|
43
|
+
help="subcommand (history: view past results)",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
args = parser.parse_args()
|
|
47
|
+
|
|
48
|
+
from ttyping.app import TypingApp
|
|
49
|
+
|
|
50
|
+
app = TypingApp(
|
|
51
|
+
lang=args.lang,
|
|
52
|
+
file_path=args.file,
|
|
53
|
+
word_count=args.words,
|
|
54
|
+
duration=args.time,
|
|
55
|
+
show_history=args.command == "history",
|
|
56
|
+
)
|
|
57
|
+
app.run()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
main()
|
ttyping/app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Main Textual application for ttyping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from textual.app import App
|
|
8
|
+
|
|
9
|
+
from ttyping.screens import HistoryScreen, TypingScreen
|
|
10
|
+
from ttyping.words import get_words, words_from_file
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TypingApp(App):
|
|
14
|
+
"""A minimal terminal typing test."""
|
|
15
|
+
|
|
16
|
+
TITLE = "ttyping"
|
|
17
|
+
|
|
18
|
+
CSS = """
|
|
19
|
+
Screen {
|
|
20
|
+
background: #323437;
|
|
21
|
+
}
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
lang: str = "en",
|
|
27
|
+
file_path: str | None = None,
|
|
28
|
+
word_count: int = 25,
|
|
29
|
+
duration: int | None = None,
|
|
30
|
+
show_history: bool = False,
|
|
31
|
+
) -> None:
|
|
32
|
+
super().__init__()
|
|
33
|
+
self._lang = lang
|
|
34
|
+
self._file_path = file_path
|
|
35
|
+
self._word_count = word_count
|
|
36
|
+
self._duration = duration
|
|
37
|
+
self._show_history = show_history
|
|
38
|
+
|
|
39
|
+
def on_mount(self) -> None:
|
|
40
|
+
if self._show_history:
|
|
41
|
+
self.push_screen(HistoryScreen())
|
|
42
|
+
else:
|
|
43
|
+
self._start_typing()
|
|
44
|
+
|
|
45
|
+
def _start_typing(self) -> None:
|
|
46
|
+
words = self._get_words()
|
|
47
|
+
self.push_screen(TypingScreen(words, lang=self._lang, duration=self._duration))
|
|
48
|
+
|
|
49
|
+
def _get_words(self) -> list[str]:
|
|
50
|
+
count = self._word_count
|
|
51
|
+
if self._duration:
|
|
52
|
+
# For timed tests, provide plenty of words.
|
|
53
|
+
# 500 is likely more than enough for 1-2 minutes.
|
|
54
|
+
count = 500
|
|
55
|
+
|
|
56
|
+
if self._file_path:
|
|
57
|
+
return words_from_file(self._file_path, count)
|
|
58
|
+
return get_words(self._lang, count)
|
|
59
|
+
|
|
60
|
+
def restart(self) -> None:
|
|
61
|
+
"""Pop current screens and start a new typing test."""
|
|
62
|
+
while len(self.screen_stack) > 1:
|
|
63
|
+
self.pop_screen()
|
|
64
|
+
self._start_typing()
|
|
65
|
+
|
|
66
|
+
def show_result(self, result: dict[str, Any]) -> None:
|
|
67
|
+
"""Push the result screen after a test."""
|
|
68
|
+
from ttyping.screens import ResultScreen
|
|
69
|
+
|
|
70
|
+
self.push_screen(ResultScreen(result))
|
ttyping/screens.py
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
"""Screens for ttyping: typing test, results, and history."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections import Counter
|
|
6
|
+
import time
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from rich.text import Text
|
|
11
|
+
from textual import events
|
|
12
|
+
from textual.app import ComposeResult
|
|
13
|
+
from textual.binding import Binding
|
|
14
|
+
from textual.containers import Center, Vertical
|
|
15
|
+
from textual.screen import Screen
|
|
16
|
+
from textual.widgets import DataTable, Input, Static
|
|
17
|
+
|
|
18
|
+
from ttyping.storage import load_results, save_result
|
|
19
|
+
|
|
20
|
+
# ── Colours (monkeytype-inspired) ─────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
COL_BG = "#323437"
|
|
23
|
+
COL_DIM = "#646669"
|
|
24
|
+
COL_TEXT = "#d1d0c5"
|
|
25
|
+
COL_CORRECT = "#d1d0c5"
|
|
26
|
+
COL_ERROR = "#ca4754"
|
|
27
|
+
COL_ACCENT = "#e2b714"
|
|
28
|
+
COL_SUB_BG = "#2c2e31"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# ── TypingScreen ───────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TypingScreen(Screen):
|
|
35
|
+
"""Main typing test screen."""
|
|
36
|
+
|
|
37
|
+
BINDINGS = [
|
|
38
|
+
Binding("tab", "restart", "Restart", priority=True),
|
|
39
|
+
Binding("escape", "quit_app", "Quit", priority=True),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
DEFAULT_CSS = """
|
|
43
|
+
TypingScreen {
|
|
44
|
+
align: center middle;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#typing-container {
|
|
48
|
+
width: 76;
|
|
49
|
+
height: auto;
|
|
50
|
+
max-height: 100%;
|
|
51
|
+
align: center middle;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#stats {
|
|
55
|
+
width: 100%;
|
|
56
|
+
height: 2;
|
|
57
|
+
content-align: center middle;
|
|
58
|
+
text-align: center;
|
|
59
|
+
color: """ + COL_ACCENT + """;
|
|
60
|
+
margin-bottom: 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#text-display {
|
|
64
|
+
width: 100%;
|
|
65
|
+
height: auto;
|
|
66
|
+
min-height: 3;
|
|
67
|
+
max-height: 8;
|
|
68
|
+
padding: 0 2;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#input-area {
|
|
72
|
+
width: 100%;
|
|
73
|
+
margin-top: 1;
|
|
74
|
+
border: round """ + COL_DIM + """;
|
|
75
|
+
background: """ + COL_SUB_BG + """;
|
|
76
|
+
color: """ + COL_TEXT + """;
|
|
77
|
+
padding: 0 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#input-area:focus {
|
|
81
|
+
border: round """ + COL_ACCENT + """;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#hints {
|
|
85
|
+
width: 100%;
|
|
86
|
+
height: 1;
|
|
87
|
+
content-align: center middle;
|
|
88
|
+
text-align: center;
|
|
89
|
+
color: """ + COL_DIM + """;
|
|
90
|
+
margin-top: 1;
|
|
91
|
+
}
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
def __init__(self, words: list[str], lang: str = "en", duration: int | None = None) -> None:
|
|
95
|
+
super().__init__()
|
|
96
|
+
self.words = words
|
|
97
|
+
self.lang = lang
|
|
98
|
+
self.duration = duration
|
|
99
|
+
self.current_word_idx = 0
|
|
100
|
+
self.current_input = ""
|
|
101
|
+
self.word_correct: list[bool | None] = [None] * len(words)
|
|
102
|
+
self.start_time: float | None = None
|
|
103
|
+
self.total_correct_chars = 0
|
|
104
|
+
self.total_keystrokes = 0
|
|
105
|
+
self._timer_handle: Any = None
|
|
106
|
+
self._finished = False
|
|
107
|
+
self.errors = Counter() # Tracks characters missed
|
|
108
|
+
self.word_errors = Counter() # Tracks words missed
|
|
109
|
+
|
|
110
|
+
def compose(self) -> ComposeResult:
|
|
111
|
+
with Center():
|
|
112
|
+
with Vertical(id="typing-container"):
|
|
113
|
+
yield Static("", id="stats")
|
|
114
|
+
yield Static("", id="text-display")
|
|
115
|
+
yield Input(placeholder="start typing…", id="input-area")
|
|
116
|
+
yield Static("tab restart · esc quit", id="hints")
|
|
117
|
+
|
|
118
|
+
def on_mount(self) -> None:
|
|
119
|
+
self._render_display()
|
|
120
|
+
self.query_one("#input-area", Input).focus()
|
|
121
|
+
|
|
122
|
+
# ── input handling ─────────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
def on_input_changed(self, event: Input.Changed) -> None:
|
|
125
|
+
if self._finished:
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
value = event.value
|
|
129
|
+
|
|
130
|
+
# Space → complete current word
|
|
131
|
+
if value.endswith(" "):
|
|
132
|
+
self._complete_word(value[:-1])
|
|
133
|
+
event.input.value = ""
|
|
134
|
+
return
|
|
135
|
+
|
|
136
|
+
# Track character errors as they happen
|
|
137
|
+
if value and self.current_word_idx < len(self.words):
|
|
138
|
+
target_word = self.words[self.current_word_idx]
|
|
139
|
+
last_typed_idx = len(value) - 1
|
|
140
|
+
if last_typed_idx < len(target_word):
|
|
141
|
+
if value[last_typed_idx] != target_word[last_typed_idx]:
|
|
142
|
+
# User typed the wrong character
|
|
143
|
+
self.errors[target_word[last_typed_idx]] += 1
|
|
144
|
+
|
|
145
|
+
self.current_input = value
|
|
146
|
+
|
|
147
|
+
# Start timer on first keystroke
|
|
148
|
+
if self.start_time is None and value:
|
|
149
|
+
self.start_time = time.time()
|
|
150
|
+
self._timer_handle = self.set_interval(0.5, self._tick_stats)
|
|
151
|
+
|
|
152
|
+
self._render_display()
|
|
153
|
+
self._update_stats()
|
|
154
|
+
|
|
155
|
+
def on_key(self, event: events.Key) -> None:
|
|
156
|
+
if self._finished:
|
|
157
|
+
return
|
|
158
|
+
# Enter also completes the current word (handy for last word)
|
|
159
|
+
if event.key == "enter":
|
|
160
|
+
event.prevent_default()
|
|
161
|
+
inp = self.query_one("#input-area", Input)
|
|
162
|
+
if inp.value:
|
|
163
|
+
self._complete_word(inp.value)
|
|
164
|
+
inp.value = ""
|
|
165
|
+
|
|
166
|
+
# ── word completion ────────────────────────────────────────────────
|
|
167
|
+
|
|
168
|
+
def _complete_word(self, typed: str) -> None:
|
|
169
|
+
target = self.words[self.current_word_idx]
|
|
170
|
+
is_correct = typed == target
|
|
171
|
+
|
|
172
|
+
self.word_correct[self.current_word_idx] = is_correct
|
|
173
|
+
self.total_keystrokes += len(typed) + 1 # +1 for space/enter
|
|
174
|
+
if is_correct:
|
|
175
|
+
self.total_correct_chars += len(target) + 1
|
|
176
|
+
else:
|
|
177
|
+
self.word_errors[target] += 1
|
|
178
|
+
|
|
179
|
+
self.current_word_idx += 1
|
|
180
|
+
self.current_input = ""
|
|
181
|
+
|
|
182
|
+
if self.current_word_idx >= len(self.words):
|
|
183
|
+
self._end_test()
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
self._render_display()
|
|
187
|
+
self._update_stats()
|
|
188
|
+
|
|
189
|
+
# ── end test ───────────────────────────────────────────────────────
|
|
190
|
+
|
|
191
|
+
def _end_test(self) -> None:
|
|
192
|
+
if self._finished:
|
|
193
|
+
return
|
|
194
|
+
|
|
195
|
+
self._finished = True
|
|
196
|
+
if self._timer_handle:
|
|
197
|
+
self._timer_handle.stop()
|
|
198
|
+
|
|
199
|
+
elapsed = time.time() - self.start_time if self.start_time else 0.01
|
|
200
|
+
minutes = elapsed / 60
|
|
201
|
+
wpm = (self.total_correct_chars / 5) / minutes if minutes > 0 else 0
|
|
202
|
+
accuracy = (
|
|
203
|
+
(self.total_correct_chars / max(self.total_keystrokes, 1)) * 100
|
|
204
|
+
)
|
|
205
|
+
correct_words = sum(1 for w in self.word_correct if w is True)
|
|
206
|
+
|
|
207
|
+
# Get top errors
|
|
208
|
+
top_char_errors = self.errors.most_common(5)
|
|
209
|
+
top_word_errors = self.word_errors.most_common(5)
|
|
210
|
+
|
|
211
|
+
result: dict[str, Any] = {
|
|
212
|
+
"wpm": round(wpm, 1),
|
|
213
|
+
"accuracy": round(accuracy, 1),
|
|
214
|
+
"time": round(elapsed, 1),
|
|
215
|
+
"lang": self.lang,
|
|
216
|
+
"words": self.current_word_idx, # Number of words attempted
|
|
217
|
+
"correct": correct_words,
|
|
218
|
+
"top_char_errors": top_char_errors,
|
|
219
|
+
"top_word_errors": top_word_errors,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
save_result(result)
|
|
223
|
+
self.app.show_result(result) # type: ignore[attr-defined]
|
|
224
|
+
|
|
225
|
+
# ── rendering ──────────────────────────────────────────────────────
|
|
226
|
+
|
|
227
|
+
def _render_display(self) -> None:
|
|
228
|
+
text = Text()
|
|
229
|
+
# Only show a window of words around current index to keep it clean,
|
|
230
|
+
# especially for long timed tests.
|
|
231
|
+
start = max(0, self.current_word_idx - 10)
|
|
232
|
+
end = min(len(self.words), self.current_word_idx + 20)
|
|
233
|
+
|
|
234
|
+
for i in range(start, end):
|
|
235
|
+
word = self.words[i]
|
|
236
|
+
if i > start:
|
|
237
|
+
text.append(" ")
|
|
238
|
+
|
|
239
|
+
if i < self.current_word_idx:
|
|
240
|
+
# Past word
|
|
241
|
+
if self.word_correct[i]:
|
|
242
|
+
text.append(word, style=f"dim {COL_CORRECT}")
|
|
243
|
+
else:
|
|
244
|
+
text.append(word, style=f"{COL_ERROR} strike")
|
|
245
|
+
elif i == self.current_word_idx:
|
|
246
|
+
# Current word — per-character colouring
|
|
247
|
+
typed = self.current_input
|
|
248
|
+
for j, ch in enumerate(word):
|
|
249
|
+
if j < len(typed):
|
|
250
|
+
if typed[j] == ch:
|
|
251
|
+
text.append(ch, style=f"bold {COL_CORRECT}")
|
|
252
|
+
else:
|
|
253
|
+
text.append(ch, style=f"bold {COL_ERROR}")
|
|
254
|
+
elif j == len(typed):
|
|
255
|
+
text.append(ch, style=f"underline {COL_TEXT}")
|
|
256
|
+
else:
|
|
257
|
+
text.append(ch, style=COL_DIM)
|
|
258
|
+
# Extra chars beyond word length
|
|
259
|
+
if len(typed) > len(word):
|
|
260
|
+
text.append(typed[len(word):], style=f"bold {COL_ERROR}")
|
|
261
|
+
else:
|
|
262
|
+
# Future word
|
|
263
|
+
text.append(word, style=COL_DIM)
|
|
264
|
+
|
|
265
|
+
self.query_one("#text-display", Static).update(text)
|
|
266
|
+
|
|
267
|
+
def _update_stats(self) -> None:
|
|
268
|
+
if self.start_time is None:
|
|
269
|
+
self.query_one("#stats", Static).update("")
|
|
270
|
+
return
|
|
271
|
+
|
|
272
|
+
elapsed = time.time() - self.start_time
|
|
273
|
+
minutes = elapsed / 60
|
|
274
|
+
wpm = (self.total_correct_chars / 5) / minutes if minutes > 0 else 0
|
|
275
|
+
accuracy = (
|
|
276
|
+
(self.total_correct_chars / max(self.total_keystrokes, 1)) * 100
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
t = Text()
|
|
280
|
+
t.append(f"{wpm:.0f}", style=f"bold {COL_ACCENT}")
|
|
281
|
+
t.append(" wpm ", style=COL_DIM)
|
|
282
|
+
t.append(f"{accuracy:.0f}%", style=f"bold {COL_ACCENT}")
|
|
283
|
+
t.append(" acc ", style=COL_DIM)
|
|
284
|
+
|
|
285
|
+
if self.duration:
|
|
286
|
+
remaining = max(0, self.duration - elapsed)
|
|
287
|
+
t.append(f"{remaining:.0f}s", style=f"bold {COL_ACCENT}")
|
|
288
|
+
else:
|
|
289
|
+
t.append(f"{elapsed:.0f}s", style=f"bold {COL_ACCENT}")
|
|
290
|
+
|
|
291
|
+
self.query_one("#stats", Static).update(t)
|
|
292
|
+
|
|
293
|
+
def _tick_stats(self) -> None:
|
|
294
|
+
"""Called by timer to keep stats ticking even when not typing."""
|
|
295
|
+
if not self._finished:
|
|
296
|
+
if self.duration:
|
|
297
|
+
elapsed = time.time() - self.start_time if self.start_time else 0
|
|
298
|
+
if elapsed >= self.duration:
|
|
299
|
+
self._end_test()
|
|
300
|
+
return
|
|
301
|
+
self._update_stats()
|
|
302
|
+
|
|
303
|
+
# ── actions ────────────────────────────────────────────────────────
|
|
304
|
+
|
|
305
|
+
def action_restart(self) -> None:
|
|
306
|
+
self.app.restart() # type: ignore[attr-defined]
|
|
307
|
+
|
|
308
|
+
def action_quit_app(self) -> None:
|
|
309
|
+
self.app.exit()
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
# ── ResultScreen ───────────────────────────────────────────────────────────
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class ResultScreen(Screen):
|
|
316
|
+
"""Post-test results."""
|
|
317
|
+
|
|
318
|
+
BINDINGS = [
|
|
319
|
+
Binding("tab", "retry", "Retry", priority=True),
|
|
320
|
+
Binding("h", "history", "History"),
|
|
321
|
+
Binding("escape", "quit_app", "Quit"),
|
|
322
|
+
]
|
|
323
|
+
|
|
324
|
+
DEFAULT_CSS = """
|
|
325
|
+
ResultScreen {
|
|
326
|
+
align: center middle;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
#result-container {
|
|
330
|
+
width: 60;
|
|
331
|
+
height: auto;
|
|
332
|
+
align: center middle;
|
|
333
|
+
padding: 2 4;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.result-big {
|
|
337
|
+
width: 100%;
|
|
338
|
+
text-align: center;
|
|
339
|
+
margin-bottom: 1;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.result-detail {
|
|
343
|
+
width: 100%;
|
|
344
|
+
text-align: center;
|
|
345
|
+
color: """ + COL_DIM + """;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
#top-errors-title {
|
|
349
|
+
width: 100%;
|
|
350
|
+
text-align: center;
|
|
351
|
+
margin-top: 1;
|
|
352
|
+
color: """ + COL_DIM + """;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#top-errors-graph {
|
|
356
|
+
width: 100%;
|
|
357
|
+
margin-top: 1;
|
|
358
|
+
content-align: center middle;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
#result-hints {
|
|
362
|
+
width: 100%;
|
|
363
|
+
text-align: center;
|
|
364
|
+
color: """ + COL_DIM + """;
|
|
365
|
+
margin-top: 2;
|
|
366
|
+
}
|
|
367
|
+
"""
|
|
368
|
+
|
|
369
|
+
def __init__(self, result: dict[str, Any]) -> None:
|
|
370
|
+
super().__init__()
|
|
371
|
+
self.result = result
|
|
372
|
+
|
|
373
|
+
def compose(self) -> ComposeResult:
|
|
374
|
+
r = self.result
|
|
375
|
+
with Center():
|
|
376
|
+
with Vertical(id="result-container"):
|
|
377
|
+
wpm_text = Text()
|
|
378
|
+
wpm_text.append(f"{r['wpm']:.0f}", style=f"bold {COL_ACCENT}")
|
|
379
|
+
wpm_text.append(" wpm", style=COL_DIM)
|
|
380
|
+
yield Static(wpm_text, classes="result-big")
|
|
381
|
+
|
|
382
|
+
acc_text = Text()
|
|
383
|
+
acc_text.append(f"{r['accuracy']:.1f}%", style=f"bold {COL_TEXT}")
|
|
384
|
+
acc_text.append(" accuracy", style=COL_DIM)
|
|
385
|
+
yield Static(acc_text, classes="result-big")
|
|
386
|
+
|
|
387
|
+
detail = Text()
|
|
388
|
+
detail.append(f"{r['time']:.1f}s", style=COL_TEXT)
|
|
389
|
+
detail.append(f" · {r['correct']}/{r['words']} words", style=COL_DIM)
|
|
390
|
+
detail.append(f" · {r['lang']}", style=COL_DIM)
|
|
391
|
+
yield Static(detail, classes="result-detail")
|
|
392
|
+
|
|
393
|
+
if r.get("top_word_errors"):
|
|
394
|
+
yield Static("top missed words", id="top-errors-title")
|
|
395
|
+
yield Static(self._render_bar_graph(r["top_word_errors"]), id="top-errors-graph")
|
|
396
|
+
elif r.get("top_char_errors"):
|
|
397
|
+
yield Static("top missed characters", id="top-errors-title")
|
|
398
|
+
yield Static(self._render_bar_graph(r["top_char_errors"]), id="top-errors-graph")
|
|
399
|
+
|
|
400
|
+
yield Static(
|
|
401
|
+
"tab retry · h history · esc quit",
|
|
402
|
+
id="result-hints",
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
def _render_bar_graph(self, data: list[tuple[str, int]]) -> Text:
|
|
406
|
+
from rich.cells import cell_len
|
|
407
|
+
|
|
408
|
+
if not data:
|
|
409
|
+
return Text()
|
|
410
|
+
|
|
411
|
+
max_val = max(count for _, count in data)
|
|
412
|
+
max_bar_width = 30
|
|
413
|
+
|
|
414
|
+
# Determine necessary label cell width
|
|
415
|
+
max_label_cell_len = 0
|
|
416
|
+
for label, _ in data:
|
|
417
|
+
max_label_cell_len = max(max_label_cell_len, cell_len(label))
|
|
418
|
+
|
|
419
|
+
# Cap label width and add padding
|
|
420
|
+
label_cell_width = min(max_label_cell_len, 15)
|
|
421
|
+
|
|
422
|
+
t = Text()
|
|
423
|
+
for i, (label, count) in enumerate(data):
|
|
424
|
+
if i > 0:
|
|
425
|
+
t.append("\n")
|
|
426
|
+
|
|
427
|
+
# Truncate and pad label based on cell width
|
|
428
|
+
curr_cell_len = cell_len(label)
|
|
429
|
+
if curr_cell_len > label_cell_width:
|
|
430
|
+
# Truncate label to fit within label_cell_width-1 cells and add '…'
|
|
431
|
+
display_label = ""
|
|
432
|
+
acc_len = 0
|
|
433
|
+
for char in label:
|
|
434
|
+
char_len = cell_len(char)
|
|
435
|
+
if acc_len + char_len > label_cell_width - 1:
|
|
436
|
+
break
|
|
437
|
+
display_label += char
|
|
438
|
+
acc_len += char_len
|
|
439
|
+
display_label += "…"
|
|
440
|
+
padding = " " * (label_cell_width - cell_len(display_label))
|
|
441
|
+
else:
|
|
442
|
+
display_label = label
|
|
443
|
+
padding = " " * (label_cell_width - curr_cell_len)
|
|
444
|
+
|
|
445
|
+
bar_len = int((count / max_val) * max_bar_width) if max_val > 0 else 0
|
|
446
|
+
if count > 0 and bar_len == 0:
|
|
447
|
+
bar_len = 1
|
|
448
|
+
|
|
449
|
+
bar = "█" * bar_len
|
|
450
|
+
t.append(padding + display_label + " ", style=COL_DIM)
|
|
451
|
+
t.append(bar, style=COL_ERROR)
|
|
452
|
+
t.append(f" {count}", style=COL_TEXT)
|
|
453
|
+
return t
|
|
454
|
+
|
|
455
|
+
def action_retry(self) -> None:
|
|
456
|
+
self.app.restart() # type: ignore[attr-defined]
|
|
457
|
+
|
|
458
|
+
def action_history(self) -> None:
|
|
459
|
+
self.app.push_screen(HistoryScreen())
|
|
460
|
+
|
|
461
|
+
def action_quit_app(self) -> None:
|
|
462
|
+
self.app.exit()
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
# ── HistoryScreen ──────────────────────────────────────────────────────────
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
class HistoryScreen(Screen):
|
|
469
|
+
"""Past typing results."""
|
|
470
|
+
|
|
471
|
+
BINDINGS = [
|
|
472
|
+
Binding("escape", "go_back", "Back"),
|
|
473
|
+
]
|
|
474
|
+
|
|
475
|
+
DEFAULT_CSS = """
|
|
476
|
+
HistoryScreen {
|
|
477
|
+
align: center middle;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
#history-container {
|
|
481
|
+
width: 80;
|
|
482
|
+
height: auto;
|
|
483
|
+
max-height: 90%;
|
|
484
|
+
align: center middle;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
#history-title {
|
|
488
|
+
width: 100%;
|
|
489
|
+
text-align: center;
|
|
490
|
+
color: """ + COL_ACCENT + """;
|
|
491
|
+
text-style: bold;
|
|
492
|
+
margin-bottom: 1;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
#history-table {
|
|
496
|
+
width: 100%;
|
|
497
|
+
height: auto;
|
|
498
|
+
max-height: 20;
|
|
499
|
+
background: """ + COL_SUB_BG + """;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
#history-empty {
|
|
503
|
+
width: 100%;
|
|
504
|
+
text-align: center;
|
|
505
|
+
color: """ + COL_DIM + """;
|
|
506
|
+
padding: 2;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
#history-hints {
|
|
510
|
+
width: 100%;
|
|
511
|
+
text-align: center;
|
|
512
|
+
color: """ + COL_DIM + """;
|
|
513
|
+
margin-top: 1;
|
|
514
|
+
}
|
|
515
|
+
"""
|
|
516
|
+
|
|
517
|
+
def compose(self) -> ComposeResult:
|
|
518
|
+
results = load_results()
|
|
519
|
+
|
|
520
|
+
with Center():
|
|
521
|
+
with Vertical(id="history-container"):
|
|
522
|
+
yield Static("History", id="history-title")
|
|
523
|
+
|
|
524
|
+
if not results:
|
|
525
|
+
yield Static("No results yet — go type!", id="history-empty")
|
|
526
|
+
else:
|
|
527
|
+
table = DataTable(id="history-table")
|
|
528
|
+
table.add_columns("Date", "WPM", "Acc", "Lang", "Time", "Words")
|
|
529
|
+
for r in reversed(results[-50:]):
|
|
530
|
+
date_str = ""
|
|
531
|
+
if "date" in r:
|
|
532
|
+
try:
|
|
533
|
+
dt = datetime.fromisoformat(r["date"])
|
|
534
|
+
date_str = dt.strftime("%Y-%m-%d %H:%M")
|
|
535
|
+
except (ValueError, TypeError):
|
|
536
|
+
date_str = str(r["date"])[:16]
|
|
537
|
+
table.add_row(
|
|
538
|
+
date_str,
|
|
539
|
+
f"{r.get('wpm', 0):.0f}",
|
|
540
|
+
f"{r.get('accuracy', 0):.1f}%",
|
|
541
|
+
r.get("lang", "?"),
|
|
542
|
+
f"{r.get('time', 0):.0f}s",
|
|
543
|
+
f"{r.get('correct', 0)}/{r.get('words', 0)}",
|
|
544
|
+
)
|
|
545
|
+
yield table
|
|
546
|
+
|
|
547
|
+
yield Static("esc back", id="history-hints")
|
|
548
|
+
|
|
549
|
+
def action_go_back(self) -> None:
|
|
550
|
+
if len(self.app.screen_stack) > 1:
|
|
551
|
+
self.app.pop_screen()
|
|
552
|
+
else:
|
|
553
|
+
self.app.exit()
|
ttyping/storage.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Local JSON storage for typing results."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
STORAGE_DIR = Path.home() / ".ttyping"
|
|
11
|
+
RESULTS_FILE = STORAGE_DIR / "results.json"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _ensure_storage() -> None:
|
|
15
|
+
STORAGE_DIR.mkdir(parents=True, exist_ok=True)
|
|
16
|
+
if not RESULTS_FILE.exists():
|
|
17
|
+
RESULTS_FILE.write_text("[]", encoding="utf-8")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def save_result(result: dict[str, Any]) -> None:
|
|
21
|
+
"""Append a result to the local storage."""
|
|
22
|
+
_ensure_storage()
|
|
23
|
+
results = load_results()
|
|
24
|
+
result["date"] = datetime.now(timezone.utc).isoformat()
|
|
25
|
+
results.append(result)
|
|
26
|
+
RESULTS_FILE.write_text(json.dumps(results, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def load_results() -> list[dict[str, Any]]:
|
|
30
|
+
"""Load all results from local storage."""
|
|
31
|
+
_ensure_storage()
|
|
32
|
+
text = RESULTS_FILE.read_text(encoding="utf-8")
|
|
33
|
+
try:
|
|
34
|
+
return json.loads(text)
|
|
35
|
+
except json.JSONDecodeError:
|
|
36
|
+
return []
|
ttyping/words.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Word lists and file reader for ttyping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import random
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
ENGLISH: list[str] = [
|
|
9
|
+
"the", "be", "to", "of", "and", "a", "in", "that", "have", "i",
|
|
10
|
+
"it", "for", "not", "on", "with", "he", "as", "you", "do", "at",
|
|
11
|
+
"this", "but", "his", "by", "from", "they", "we", "say", "her", "she",
|
|
12
|
+
"or", "an", "will", "my", "one", "all", "would", "there", "their", "what",
|
|
13
|
+
"so", "up", "out", "if", "about", "who", "get", "which", "go", "me",
|
|
14
|
+
"when", "make", "can", "like", "time", "no", "just", "him", "know", "take",
|
|
15
|
+
"people", "into", "year", "your", "good", "some", "could", "them", "see", "other",
|
|
16
|
+
"than", "then", "now", "look", "only", "come", "its", "over", "think", "also",
|
|
17
|
+
"back", "after", "use", "two", "how", "our", "work", "first", "well", "way",
|
|
18
|
+
"even", "new", "want", "because", "any", "these", "give", "day", "most", "us",
|
|
19
|
+
"great", "between", "need", "large", "often", "hand", "high", "place", "small", "found",
|
|
20
|
+
"live", "where", "before", "must", "home", "big", "long", "much", "right", "still",
|
|
21
|
+
"world", "start", "house", "every", "under", "keep", "never", "last", "let", "each",
|
|
22
|
+
"begin", "while", "next", "should", "same", "name", "help", "talk", "turn", "move",
|
|
23
|
+
"point", "city", "play", "away", "end", "part", "lead", "stand", "own", "page",
|
|
24
|
+
"learn", "change", "group", "always", "music", "those", "both", "mark", "book", "letter",
|
|
25
|
+
"until", "life", "children", "write", "close", "open", "run", "read", "line", "set",
|
|
26
|
+
"air", "animal", "answer", "around", "ask", "best", "better", "black", "body", "boy",
|
|
27
|
+
"bring", "build", "call", "came", "car", "care", "carry", "child", "city", "cold",
|
|
28
|
+
"country", "cut", "dear", "door", "draw", "earth", "eat", "face", "fall", "family",
|
|
29
|
+
"far", "father", "few", "fish", "food", "form", "four", "girl", "got", "green",
|
|
30
|
+
"grow", "hard", "head", "hear", "hot", "idea", "important", "inside", "keep", "kind",
|
|
31
|
+
"king", "land", "late", "left", "light", "list", "love", "man", "many", "might",
|
|
32
|
+
"money", "morning", "mother", "mountain", "near", "night", "nothing", "number", "off", "old",
|
|
33
|
+
"once", "order", "paper", "picture", "plant", "problem", "put", "quite", "river", "room",
|
|
34
|
+
"school", "sea", "second", "side", "soon", "story", "stop", "sun", "sure", "table",
|
|
35
|
+
"tell", "though", "today", "together", "took", "tree", "try", "voice", "walk", "watch",
|
|
36
|
+
"water", "white", "word", "young", "system", "program", "question", "during", "without", "again",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
KOREAN: list[str] = [
|
|
40
|
+
"사람", "시간", "우리", "세계", "나라", "사회", "학교", "생각", "문제", "오늘",
|
|
41
|
+
"내일", "어제", "회사", "가족", "친구", "사랑", "행복", "음식", "하늘", "바다",
|
|
42
|
+
"여행", "공부", "노력", "경험", "기억", "마음", "이유", "방법", "계획", "결과",
|
|
43
|
+
"의미", "가능", "필요", "중요", "다양", "특별", "자유", "평화", "희망", "미래",
|
|
44
|
+
"역사", "문화", "예술", "음악", "영화", "도시", "자연", "환경", "건강", "교육",
|
|
45
|
+
"기술", "과학", "경제", "정치", "법률", "뉴스", "정보", "인터넷", "컴퓨터", "전화",
|
|
46
|
+
"이름", "나이", "직업", "취미", "여름", "겨울", "봄", "가을", "아침", "저녁",
|
|
47
|
+
"동물", "식물", "꽃", "나무", "강", "산", "비", "눈", "바람", "구름",
|
|
48
|
+
"집", "방", "문", "길", "차", "버스", "지하철", "비행기", "기차", "배",
|
|
49
|
+
"물", "밥", "고기", "과일", "커피", "빵", "국", "김치", "라면", "치킨",
|
|
50
|
+
"약속", "준비", "시작", "끝", "변화", "성장", "발전", "성공", "실패", "도전",
|
|
51
|
+
"감사", "미안", "부탁", "인사", "대화", "연락", "소식", "선물", "축하", "응원",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_words(lang: str = "en", count: int = 25) -> list[str]:
|
|
56
|
+
"""Return a random selection of words for the given language."""
|
|
57
|
+
source = ENGLISH if lang == "en" else KOREAN
|
|
58
|
+
return [random.choice(source) for _ in range(count)]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def words_from_file(path: str, count: int = 25) -> list[str]:
|
|
62
|
+
"""Read words from a file and return up to `count` words."""
|
|
63
|
+
text = Path(path).read_text(encoding="utf-8")
|
|
64
|
+
words = text.split()
|
|
65
|
+
if not words:
|
|
66
|
+
raise ValueError(f"No words found in {path}")
|
|
67
|
+
if len(words) > count:
|
|
68
|
+
words = words[:count]
|
|
69
|
+
return words
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttyping
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A minimal terminal typing test — English & Korean, monkeytype-inspired
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: monkeytype,terminal,textual,tui,typing
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Games/Entertainment
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: textual>=0.40
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# ttyping
|
|
19
|
+
|
|
20
|
+
A minimal, monkeytype-inspired terminal typing test. English & Korean.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install ttyping
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or with uv:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
uv tool install ttyping
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
ttyping # English, 25 random words
|
|
38
|
+
ttyping --lang ko # Korean random words
|
|
39
|
+
ttyping --file path.txt # Practice from file
|
|
40
|
+
ttyping --words 50 # Custom word count
|
|
41
|
+
ttyping --time 30 # 30-second timed test
|
|
42
|
+
ttyping history # View past results
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Keybindings
|
|
46
|
+
|
|
47
|
+
| Key | Action |
|
|
48
|
+
|-------|----------------|
|
|
49
|
+
| Tab | Restart test |
|
|
50
|
+
| Esc | Quit |
|
|
51
|
+
| Space | Next word |
|
|
52
|
+
|
|
53
|
+
Results are saved locally at `~/.ttyping/results.json`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
ttyping/__init__.py,sha256=E9Pdsw0XMEuhKdVMqp4H7miouohIjHo7HI5AO1GceIw,73
|
|
2
|
+
ttyping/__main__.py,sha256=a8hwPu7I1STgyyvTkyacL8QcudUNBxIeCENG-r0at0c,1325
|
|
3
|
+
ttyping/app.py,sha256=0sZ_IBGE_x_fj7xa5RK14QUcZHpeQigukUR5HG0F4Mw,1916
|
|
4
|
+
ttyping/screens.py,sha256=Gr-v7O2CqYkx384Igdzfk9HSKPT8ACcy7wFJK8_5bqM,18432
|
|
5
|
+
ttyping/storage.py,sha256=-Mm5E0dVi9wJa1FYD6bIsuqfXwLifQgH2W_aidwdm00,1033
|
|
6
|
+
ttyping/words.py,sha256=l0LLzwDg-ojYW8rj77o4X8rz8MyY3UYVnyMy3jpoFcY,4373
|
|
7
|
+
ttyping-0.1.0.dist-info/METADATA,sha256=TYPSIq7LBcJ5CbYWj-BBsTODa-oeEIZLdl8q3eF6TUk,1272
|
|
8
|
+
ttyping-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
9
|
+
ttyping-0.1.0.dist-info/entry_points.txt,sha256=QGUQo8_hblcl7egPGHAXreTOZZ-ZDxfIu9xEj3s9pLk,50
|
|
10
|
+
ttyping-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
+
ttyping-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|