pyrebound 0.1.0__tar.gz

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.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1 @@
1
+ 3.14
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyrebound
3
+ Version: 0.1.0
4
+ Summary: Brick-breaker game for terminal
5
+ Author: Siddharth Pandey
6
+ License: MIT
7
+ Requires-Python: >=3.14
8
+ Requires-Dist: rich>=15.0.0
File without changes
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "pyrebound"
3
+ version = "0.1.0"
4
+ description = "Brick-breaker game for terminal"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = { text = "MIT" }
8
+
9
+ authors = [
10
+ { name = "Siddharth Pandey" }
11
+ ]
12
+
13
+ dependencies = [
14
+ "rich>=15.0.0",
15
+ ]
16
+
17
+ [project.scripts]
18
+ brick-breaker = "brick_breaker.cli:main"
19
+
20
+ [build-system]
21
+ requires = ["hatchling"]
22
+ build-backend = "hatchling.build"
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["brick_breaker"]
26
+
@@ -0,0 +1,165 @@
1
+
2
+ # Brick-Breaker game for Command-Line interface
3
+
4
+ Getting Bothered of typing code take a break !!
5
+
6
+ A minimal Brick Breaker game that runs in your terminal, built with [Rich](https://github.com/Textualize/rich).
7
+
8
+ One ball, one paddle, and four rows of bricks that break in a single hit. Clear them all to win.
9
+
10
+ ```text
11
+ ╭──────────── BRICK BREAKER ────────────╮
12
+ │ ████████████████████████████████████ │
13
+ │ ████████████████████████████████████ │
14
+ │ ████████████████████████████████████ │
15
+ │ ████████████████████████████████████ │
16
+ │ │
17
+ │ ● │
18
+ │ │
19
+ │ ▀▀▀▀▀ │
20
+ ╰──────────── Score 0/80 ──────────────╯
21
+ ```
22
+
23
+ ## ✨ Features
24
+
25
+ - Runs entirely in the terminal, with no window or GUI.
26
+ - Smooth, flicker-free rendering using Rich's live display.
27
+ - Arrow keys or A / D controls.
28
+ - The ball steers depending on where it hits the paddle.
29
+ - Works on Windows, macOS and Linux.
30
+
31
+ ## 📋 Requirements
32
+
33
+ - Python 3.10 or newer.
34
+ - A real terminal (Windows Terminal, PowerShell, macOS Terminal, iTerm2, GNOME Terminal, and so on).
35
+
36
+ > **Note:** The game won't run when input is piped or redirected.
37
+
38
+ ## 📦 Installation
39
+
40
+ ### With uv (recommended)
41
+
42
+ ```bash
43
+ uv tool install pyrebound
44
+ ```
45
+
46
+ ### With pipx
47
+
48
+ ```bash
49
+ pipx install pyrebound
50
+ ```
51
+
52
+ ### With pip
53
+
54
+ ```bash
55
+ pip install pyrebound
56
+ ```
57
+
58
+ ### Directly from GitHub
59
+
60
+ ```bash
61
+ uv tool install git+https://github.com/Nihithius/CLI-Brick-Breaker
62
+ ```
63
+
64
+ ## 🚀 Usage
65
+
66
+ Start the game:
67
+
68
+ ```bash
69
+ brick-breaker --break
70
+ ```
71
+
72
+ Other options:
73
+
74
+ ```bash
75
+ brick-breaker --help # Show usage
76
+ brick-breaker --version # Show version
77
+ ```
78
+
79
+ Running `brick-breaker` with no flag prints the help text.
80
+
81
+ If the `brick-breaker` command isn't available on your system, run it through Python instead:
82
+
83
+ ```bash
84
+ python -m brick_breaker --break
85
+ ```
86
+
87
+ ## 🎮 Controls
88
+
89
+ | Key | Action |
90
+ |:---:|---|
91
+ | ← / A | Move paddle left |
92
+ | → / D | Move paddle right |
93
+ | Q / Esc | Quit |
94
+ | Ctrl+C | Quit |
95
+
96
+ ## 🕹️ How to Play
97
+
98
+ 1. Keep the ball in play by bouncing it off your paddle.
99
+ 2. Each brick you hit disappears and adds one point to your score.
100
+ 3. Hitting the paddle near its left or right edge sends the ball in that direction.
101
+ 4. You win when every brick is gone.
102
+ 5. You lose if the ball gets past the paddle.
103
+
104
+ ## 🛠️ Development
105
+
106
+ Clone the repository and set up the environment:
107
+
108
+ ```bash
109
+ git clone https://github.com/Nihithius/CLI-Brick-Breaker
110
+ cd CLI-Brick-Breaker
111
+ uv sync
112
+ ```
113
+
114
+ Run the game from source:
115
+
116
+ ```bash
117
+ uv run python -m brick_breaker --break
118
+ ```
119
+
120
+ Or use the installed script inside the project environment:
121
+
122
+ ```bash
123
+ uv run brick-breaker --break
124
+ ```
125
+
126
+ ## 📁 Project Structure
127
+
128
+ ```text
129
+ brick_breaker/
130
+ ├── __init__.py
131
+ ├── __main__.py # Enables `python -m brick_breaker`
132
+ ├── cli.py # Command-line interface
133
+ ├── game.py # Game class: state, physics, rendering, main loop
134
+ └── input_handler.py # Cross-platform non-blocking keyboard input
135
+
136
+ pyproject.toml
137
+ README.md
138
+ LICENSE
139
+ ```
140
+
141
+
142
+
143
+ ## 🐛 Troubleshooting
144
+
145
+ ### Failed to spawn: brick-breaker ... An Application Control policy has blocked this file (Windows)
146
+
147
+ Windows security settings (Smart App Control, WDAC or AppLocker) may be blocking the generated `.exe` launcher.
148
+
149
+ Run the game through Python instead:
150
+
151
+ ```bash
152
+ uv run python -m brick_breaker --break
153
+ ```
154
+
155
+ ### RuntimeError: stdin is not a terminal (macOS / Linux)
156
+
157
+ Run the game directly in an interactive terminal, not through a pipe, a script runner or an IDE output panel.
158
+
159
+ ### Terminal looks broken after a crash
160
+
161
+ Type `reset` and press Enter (macOS / Linux), or close and reopen the terminal.
162
+
163
+ ## 📄 License
164
+
165
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE) file for details.
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()
@@ -0,0 +1,31 @@
1
+ import argparse
2
+ import sys
3
+ from .game import Game
4
+
5
+ def game_parser() -> argparse.ArgumentParser:
6
+
7
+ parser = argparse.ArgumentParser(prog="Brick-breaker", description="Brick breaker game for terminal")
8
+
9
+ parser.add_argument("--break",
10
+ dest="start_game",action="store_true",help="Start the Brick-breaker game")
11
+ parser.add_argument("--version",action="version",version="brick-breaker 0.1.0")
12
+
13
+ return parser
14
+
15
+
16
+ def main():
17
+ parser = game_parser()
18
+ args = parser.parse_args()
19
+
20
+ if args.start_game:
21
+ game = Game()
22
+ game.run()
23
+ else:
24
+ parser.print_help()
25
+
26
+ return 0
27
+
28
+
29
+ if __name__ =="__main__":
30
+ main()
31
+
@@ -0,0 +1,149 @@
1
+ """Minimal terminal Brick Breaker (Rich edition).
2
+
3
+ One ball, one paddle, bricks that break in a single hit.
4
+ Controls: LEFT/RIGHT arrows (or A/D), Q or Esc to quit.
5
+
6
+ Works on Windows, Linux, macOS.
7
+ """
8
+
9
+ import time
10
+
11
+ from rich.console import Console, Group
12
+ from rich.live import Live
13
+ from rich.panel import Panel
14
+ from rich.text import Text
15
+
16
+ from .input_handler import InputHandler
17
+
18
+ WIDTH = 20
19
+ HEIGHT = 20
20
+ BRICK_ROWS = 4
21
+ PADDLE_W = 5
22
+ TICK = 0.07
23
+
24
+ ROW_STYLES = ["#fc0313", "#fcdf00", "#49fc03", "#1002d1"]
25
+
26
+
27
+ class Game:
28
+ def __init__(self):
29
+ self.bricks = {(x, y) for y in range(1, 1 + BRICK_ROWS) for x in range(WIDTH)}
30
+ self.total = len(self.bricks)
31
+ self.paddle_x = (WIDTH - PADDLE_W) // 2
32
+ self.bx = WIDTH // 2
33
+ self.by = HEIGHT - 3
34
+ self.dx, self.dy = 1, -1
35
+ self.state = "playing" # "playing" | "won" | "lost"
36
+
37
+ @property
38
+ def score(self):
39
+ return self.total - len(self.bricks)
40
+
41
+ def move_paddle(self, delta):
42
+ self.paddle_x = max(0, min(WIDTH - PADDLE_W, self.paddle_x + delta))
43
+
44
+ def step(self):
45
+ nx, ny = self.bx + self.dx, self.by + self.dy
46
+
47
+ # side walls and ceiling
48
+ if nx < 0 or nx >= WIDTH:
49
+ self.dx = -self.dx
50
+ nx = self.bx + self.dx
51
+ if ny < 0:
52
+ self.dy = -self.dy
53
+ ny = self.by + self.dy
54
+
55
+ # remove brick and bounce vertically
56
+ if (nx, ny) in self.bricks:
57
+ self.bricks.discard((nx, ny))
58
+ self.dy = -self.dy
59
+ ny = self.by + self.dy
60
+ if not self.bricks:
61
+ self.bx, self.by = nx, ny
62
+ self.state = "won"
63
+ return
64
+
65
+ # paddle row
66
+ if ny >= HEIGHT - 1:
67
+ if self.paddle_x <= nx < self.paddle_x + PADDLE_W:
68
+ self.dy = -1
69
+ ny = self.by + self.dy
70
+ pos = nx - self.paddle_x # steer by where it hit
71
+ if pos < PADDLE_W // 3:
72
+ self.dx = -1
73
+ elif pos >= PADDLE_W - PADDLE_W // 3:
74
+ self.dx = 1
75
+ else:
76
+ self.bx, self.by = nx, ny
77
+ self.state = "lost"
78
+ return
79
+
80
+ self.bx, self.by = nx, ny
81
+
82
+
83
+
84
+
85
+ def render(self):
86
+ # rich renderable for Current frames
87
+ field = Text(no_wrap=True)
88
+ for y in range(HEIGHT):
89
+ for x in range(WIDTH):
90
+ if (x, y) == (self.bx, self.by):
91
+ field.append("● ", style="bold white")
92
+ elif (x, y) in self.bricks:
93
+ field.append("██", style=ROW_STYLES[(y - 1) % len(ROW_STYLES)])
94
+ elif y == HEIGHT - 1 and self.paddle_x <= x < self.paddle_x + PADDLE_W:
95
+ field.append("▀▀", style="#fc03b6") # "▀▀" -> these are just unicode blocks
96
+ else:
97
+ field.append(" ")
98
+ if y < HEIGHT - 1:
99
+ field.append("\n")
100
+
101
+ panel = Panel(
102
+ field,
103
+ title="BRICK BREAKER",
104
+ subtitle=f"Score {self.score}/{self.total}",
105
+ width=WIDTH * 2 + 4,
106
+ border_style="#fcd703",
107
+ )
108
+ help_line = Text("←/→ or A/D move Q quit", style="dim", justify="center")
109
+ return Group(panel, help_line)
110
+
111
+
112
+ def run(self):
113
+ console = Console()
114
+ quit_requested = False
115
+
116
+ with InputHandler() as inp, Live(self.render(), console=console, screen=True, auto_refresh=False) as live:
117
+ while self.state == "playing":
118
+ start = time.time()
119
+
120
+ for key in inp.get_keys():
121
+ if key in ("LEFT", "a", "A"):
122
+ self.move_paddle(-3)
123
+ elif key in ("RIGHT", "d", "D"):
124
+ self.move_paddle(3)
125
+ elif key in ("q", "Q", "ESC"):
126
+ quit_requested = True
127
+
128
+ if quit_requested:
129
+ break
130
+
131
+ self.step()
132
+ live.update(self.render(), refresh=True)
133
+
134
+ time.sleep(max(0, TICK - (time.time() - start)))
135
+
136
+ # Live(screen=True) restores the normal screen, so print the result afterwards
137
+ if self.state == "won":
138
+ console.print("[bold green]You cleared all the bricks. You win !! >>__<< [/]")
139
+ elif self.state == "lost":
140
+ console.print(f"[bold red]Game over.[/] You broke {self.score} bricks.")
141
+ else:
142
+ console.print("Bye!")
143
+
144
+
145
+
146
+
147
+
148
+
149
+
@@ -0,0 +1,136 @@
1
+ import atexit
2
+ import os
3
+ import sys
4
+
5
+ IS_WINDOWS = os.name == "nt"
6
+
7
+ if IS_WINDOWS:
8
+ import msvcrt
9
+ else:
10
+ import select
11
+ import termios
12
+
13
+
14
+ class InputHandler:
15
+
16
+ def __init__(self):
17
+ self.active = False
18
+ self.foreD = None
19
+ self.old_term = None
20
+
21
+ if not IS_WINDOWS:
22
+ if not sys.stdin.isatty():
23
+ raise RuntimeError("stdin is not a terminal: run the game in real terminal ")
24
+ self.foreD = sys.stdin.fileno()
25
+ self.start_setup()
26
+
27
+ # Safety net (restore terminal even is the program crashes)
28
+ atexit.register(self.stop)
29
+
30
+
31
+ # setup
32
+ def start_setup(self):
33
+ if self.active:
34
+ return
35
+ if not IS_WINDOWS:
36
+ self.old_term = termios.tcgetattr(self.foreD)
37
+ new = termios.tcgetattr(self.foreD)
38
+
39
+ # index 3 = lflags: disable line buffering and echo.
40
+ new[3] &= ~(termios.ICANON | termios.ECHO)
41
+ new[6][termios.VMIN] = 1
42
+ new[6][termios.VTIME] = 0
43
+ termios.tcsetattr(self.foreD,termios.TCSADRAIN, new)
44
+
45
+ self.active = True
46
+
47
+
48
+ def stop(self):
49
+ if not self.active:
50
+ return
51
+ if not IS_WINDOWS and self.old_term is not None:
52
+ termios.tcsetattr(self.foreD, termios.TCSADRAIN, self.old_term)
53
+ self.active = False
54
+
55
+ ''' context manager support '''
56
+ def __enter__(self):
57
+ self.start_setup()
58
+ return self
59
+
60
+ def __exit__(self, *exc):
61
+ self.stop()
62
+
63
+ # input
64
+ def is_pending(self):
65
+ # True if at least one key is waiting to be read
66
+ if IS_WINDOWS:
67
+ return msvcrt.kbhit()
68
+ r, _, _ = select.select([self.foreD], [], [], 0)
69
+ return bool(r)
70
+
71
+ def get_key(self):
72
+ # return one key (blocking if none pending or check is_pending() first)
73
+ return self._get_key_windows() if IS_WINDOWS else self._get_key_posix()
74
+
75
+ def get_keys(self):
76
+ # return a list of all pending keys (empty list if none)
77
+ keys = []
78
+ while self.is_pending():
79
+ keys.append(self.get_key())
80
+ return keys
81
+
82
+ def flush(self):
83
+ # discard any pending keys
84
+ self.get_keys()
85
+
86
+ # FOR Windows
87
+ _WIN_ARROWS = {"H": "UP", "P": "DOWN", "K": "LEFT", "M": "RIGHT"}
88
+
89
+ def _get_key_windows(self):
90
+ ch = msvcrt.getwch()
91
+ if ch in ("\x00", "\xe0"): # prefix for arrows / function keys
92
+ return self._WIN_ARROWS.get(msvcrt.getwch(), "")
93
+ if ch == "\x1b":
94
+ return "ESC"
95
+ if ch == "\x03": # Ctrl+C is not auto-raised by getwch
96
+ raise KeyboardInterrupt
97
+ return ch
98
+
99
+ # FOR Linux / Mac
100
+ _POSIX_ARROWS = {"A": "UP", "B": "DOWN", "C": "RIGHT", "D": "LEFT"}
101
+
102
+ def _read_byte(self, timeout=None):
103
+ """Read one byte from the foreD, or None on timeout."""
104
+ if timeout is not None:
105
+ r, _, _ = select.select([self.foreD], [], [], timeout)
106
+ if not r:
107
+ return None
108
+ data = os.read(self.foreD, 1)
109
+ return data.decode("utf-8", errors="ignore") if data else None
110
+
111
+ def _get_key_posix(self):
112
+ ch = self._read_byte()
113
+ if ch is None:
114
+ return ""
115
+ if ch != "\x1b":
116
+ return ch
117
+
118
+ # ESC may be a lone Esc press or the start of an arrow-key sequence
119
+ nxt = self._read_byte(timeout=0.02)
120
+ if nxt not in ("[", "O"):
121
+ return "ESC"
122
+ code = self._read_byte(timeout=0.02)
123
+ return self._POSIX_ARROWS.get(code, "")
124
+
125
+
126
+ if __name__ == "__main__":
127
+ import time
128
+ print("Press keys (arrows, letters). 'q' to quit.")
129
+
130
+ with InputHandler() as inp:
131
+ while True:
132
+ for k in inp.get_keys():
133
+ print("key:", repr(k), end="\r\n", flush=True)
134
+ if k == "q":
135
+ sys.exit(0)
136
+ time.sleep(0.03)
@@ -0,0 +1,2 @@
1
+ rich
2
+
@@ -0,0 +1,57 @@
1
+ version = 1
2
+ revision = 3
3
+ requires-python = ">=3.14"
4
+
5
+ [[package]]
6
+ name = "markdown-it-py"
7
+ version = "4.3.0"
8
+ source = { registry = "https://pypi.org/simple" }
9
+ dependencies = [
10
+ { name = "mdurl" },
11
+ ]
12
+ sdist = { url = "https://files.pythonhosted.org/packages/16/fc/cee2c45553c9a9bf77d8b0c391560c556d7ed756b1f0bb35eb5d48db09ea/markdown_it_py-4.3.0.tar.gz", hash = "sha256:91a58fa5b72c71a40cf7177250fd767480d7a2bb3ac426ccfb76fb90305fdaaa", size = 242701, upload-time = "2026-11-10T16:18:30.467Z" }
13
+ wheels = [
14
+ { url = "https://files.pythonhosted.org/packages/c9/31/5f0ac2f1a1c67423c995c731a11cd4ad05d081a2be969d74f868bdb9cc70/markdown_it_py-4.3.0-py3-none-any.whl", hash = "sha256:7aa1511a46c39138de78d9eba92ce47e63124d8003fc98b3a351909e04239efa", size = 96951, upload-time = "2026-11-10T16:18:28.975Z" },
15
+ ]
16
+
17
+ [[package]]
18
+ name = "mdurl"
19
+ version = "0.1.2"
20
+ source = { registry = "https://pypi.org/simple" }
21
+ sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729, upload-time = "2022-08-14T12:40:10.846Z" }
22
+ wheels = [
23
+ { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" },
24
+ ]
25
+
26
+ [[package]]
27
+ name = "pygments"
28
+ version = "2.21.0"
29
+ source = { registry = "https://pypi.org/simple" }
30
+ sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" }
31
+ wheels = [
32
+ { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" },
33
+ ]
34
+
35
+ [[package]]
36
+ name = "pyrebound"
37
+ version = "0.1.0"
38
+ source = { editable = "." }
39
+ dependencies = [
40
+ { name = "rich" },
41
+ ]
42
+
43
+ [package.metadata]
44
+ requires-dist = [{ name = "rich", specifier = ">=15.0.0" }]
45
+
46
+ [[package]]
47
+ name = "rich"
48
+ version = "15.0.0"
49
+ source = { registry = "https://pypi.org/simple" }
50
+ dependencies = [
51
+ { name = "markdown-it-py" },
52
+ { name = "pygments" },
53
+ ]
54
+ sdist = { url = "https://files.pythonhosted.org/packages/c0/8f/0722ca900cc807c13a6a0c696dacf35430f72e0ec571c4275d2371fca3e9/rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36", size = 230680, upload-time = "2026-04-12T08:24:00.75Z" }
55
+ wheels = [
56
+ { url = "https://files.pythonhosted.org/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb", size = 310654, upload-time = "2026-04-12T08:24:02.83Z" },
57
+ ]