Thanks for taking an interest. Bug reports, new word lists, themes and gameplay tweaks are all welcome.
git clone https://github.com/kanakOS01/gravitype.git
cd gravitype
uv sync # installs runtime + dev dependencies
uv run pre-commit install --hook-type pre-commit --hook-type commit-msgBoth hook types matter: pre-commit runs Ruff, commit-msg runs Commitizen on your message.
Run the game:
uv run gravitypeFor development, run it under the Textual dev console so print() and tracebacks are visible instead of being swallowed by the TUI:
uv run textual console # terminal 1
uv run textual run --dev gravitype.tui.app:GravitypeApp # terminal 2watch_css=True is set on the app and points at ~/.gravitype/theme_active.tcss, so writing to that file reloads live. Edits to base.tcss or a theme file in the repo only take effect after a restart, since the active file is recompiled from them on startup.
Ruff handles both linting and formatting; the pre-commit hook runs ruff check --fix and ruff format. To run them yourself:
uv run ruff check --fix .
uv run ruff format .Beyond that, match what's already there:
- Type hints on function signatures, docstrings on classes and non-obvious methods.
- Widgets live in
gravitype/tui/widgets/, one concern per module. Pure game logic (word selection, config) belongs ingravitype/core/and should not import Textual. - Never write to a path inside the installed package. Runtime state goes through
gravitype/core/paths.py, which resolves~/.gravitype/(orGRAVITYPE_HOME) — site-packages may be read-only, and writing there leaks one user's state into everyone else's. SetGRAVITYPE_HOMEwhen testing so you don't clobber your own save. - Cross-widget communication goes through Textual messages (see
GameBoard.WordMissed) or app-level reactives — not by reaching into another widget's internals. - No
print()in committed code.
pytest with everything under tests/. The commit hooks don't run it — the suite takes about 25 seconds, which is too long to pay on every commit — so run it yourself before you push. CI runs it on every PR.
Run the whole suite, or narrow it down:
uv run pytest # everything
uv run pytest tests/test_stats.py # one file
uv run pytest -k pause # one idea
uv run pytest -x -q # stop at the first failureTwo layers:
core/— plain unit tests forconfig,paths,statsandwords. No Textual, no event loop, fast.- TUI —
test_app_runs.py,test_app_ui.py,test_gameplay.pyandtest_game_board.pydrive the real app through Textual'srun_test()pilot, pressing keys and asserting on what the widgets end up holding.asyncio_mode = "auto"is set inpyproject.toml, so a test is async just by beingasync def— no decorator needed.
Things worth knowing before you add a test:
- The autouse
isolated_homefixture inconftest.pypointsGRAVITYPE_HOMEat a temp directory and re-initialises theconfigandstatssingletons, so no test can see or clobber your real save. It also pins the working directory, becausepaths.legacy_config_file()resolves against the cwd and the repo root contains a.gravitype_config.json. - Use the
appfixture to get aGravitypeAppbuilt after that isolation is in place. - Don't monkeypatch
time.monotonic—asyncioreads it too, and patching it deadlocks the event loop. To test elapsed time, backdateapp._run_started_atinstead (seetest_app_runs.py). - Don't replace a widget's
post_messageto capture events; that is Textual's own message pump and swapping it hangs the widget. Assert on the consequence instead — a missed word is visible asapp.livesgoing down. await pilot.pause()after anything that changes state, so the app has a chance to process it.
Commit messages must follow Conventional Commits; Commitizen enforces this at commit time.
feat: add sound toggle to settings
fix: reset board state on play again
refactor: move word filtering into core
docs: document theme pipeline
If you'd rather be prompted through the format, install Commitizen (uv tool install commitizen) and use cz commit.
- Branch off
main—feat/short-descriptionorfix/short-description. - Make the change and play a few rounds to confirm nothing regressed: start a game, miss words, pause, game over, play again, main menu, change theme and lives in settings.
- Add or update tests for what you changed, and run
uv run pytest. - Push and open a PR against
maindescribing what changed and how you tested it. A screenshot or terminal recording helps a lot for anything visual. CI runs Ruff and the test suite on Python 3.9 through 3.13; it has to be green before a PR can merge.
Adding words — append to TECH_WORDS or GENERAL_WORDS in gravitype/core/words.py. Keep them lowercase, no spaces or punctuation, and note that word length decides which level a word can appear at (see get_random_word), so short words are as valuable as long ones. (The built-in pools hold to that rule; a player's own set is deliberately looser and may contain phrases and capitals.)
Adding a category — usually no code is needed: a .txt file in ~/.gravitype/words/ becomes a category on its own (see Custom word sets). To add one that ships with the game, add the pool to gravitype/core/words.py, list its name in BUILTIN_CATEGORIES and return it from word_pool. The menu builds its dropdown from available_categories(), so nothing in the UI needs touching.
Adding a theme — copy an existing file in gravitype/tui/styles/themes/, keep the same variable names, and add an option to the theme Select in gravitype/tui/widgets/screens.py. Note that theme_active.tcss is generated output living in ~/.gravitype/ — don't put changes there, they'll be overwritten on next launch.
Tuning difficulty — GameBoard.get_ticks_for_level controls fall speed and spawn rate; POINTS_PER_LEVEL and the per-word points live in gravitype/tui/app.py. Note that WIN_LEVEL is tied to that curve: the game is won at the level where get_ticks_for_level stops changing, so retuning the decay means moving the cap too. test_win_level_sits_at_the_difficulty_plateau fails if the two drift apart.
The GIFs in the README are recorded with asciinema and converted with agg:
brew install asciinema aggRecord a session, play through the beats, then stop with Ctrl+D:
export GRAVITYPE_SEED=7 GRAVITYPE_HOME=$(mktemp -d)
asciinema rec docs/demo.cast --overwrite
gravitypeConvert it to a GIF:
agg docs/demo.cast docs/demo.gif --font-size 18 --theme draculaMaintainers only — see RELEASING.md for the full checklist.
Open an issue with your OS and terminal, Python version, what you did, what you expected, and what happened. Terminal size matters for TUI layout bugs, so include it if the issue looks like a rendering problem.