cmd-case-open 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.
- cmd_case_open-0.1.0/LICENSE +21 -0
- cmd_case_open-0.1.0/PKG-INFO +202 -0
- cmd_case_open-0.1.0/README.md +190 -0
- cmd_case_open-0.1.0/cmd_case_open/__init__.py +4 -0
- cmd_case_open-0.1.0/cmd_case_open/ascii_to_listOfStrings.py +56 -0
- cmd_case_open-0.1.0/cmd_case_open/core/__init__.py +1 -0
- cmd_case_open-0.1.0/cmd_case_open/core/constants.py +38 -0
- cmd_case_open-0.1.0/cmd_case_open/core/rendering.py +89 -0
- cmd_case_open-0.1.0/cmd_case_open/core/utils.py +38 -0
- cmd_case_open-0.1.0/cmd_case_open/data/__init__.py +1 -0
- cmd_case_open-0.1.0/cmd_case_open/data/spectrum-case.json +2108 -0
- cmd_case_open-0.1.0/cmd_case_open/domain/__init__.py +1 -0
- cmd_case_open-0.1.0/cmd_case_open/domain/case_catalog.py +58 -0
- cmd_case_open-0.1.0/cmd_case_open/inventory.py +128 -0
- cmd_case_open-0.1.0/cmd_case_open/scripts/hooks.powershell.ps1 +85 -0
- cmd_case_open-0.1.0/cmd_case_open/scripts/hooks.zsh +67 -0
- cmd_case_open-0.1.0/cmd_case_open/shell_hooks.py +119 -0
- cmd_case_open-0.1.0/cmd_case_open/src/CSCLI.py +22 -0
- cmd_case_open-0.1.0/cmd_case_open/src/__init__.py +5 -0
- cmd_case_open-0.1.0/cmd_case_open/src/__main__.py +7 -0
- cmd_case_open-0.1.0/cmd_case_open/src/handlers.py +24 -0
- cmd_case_open-0.1.0/cmd_case_open/src/parser.py +19 -0
- cmd_case_open-0.1.0/cmd_case_open.egg-info/PKG-INFO +202 -0
- cmd_case_open-0.1.0/cmd_case_open.egg-info/SOURCES.txt +47 -0
- cmd_case_open-0.1.0/cmd_case_open.egg-info/dependency_links.txt +1 -0
- cmd_case_open-0.1.0/cmd_case_open.egg-info/entry_points.txt +2 -0
- cmd_case_open-0.1.0/cmd_case_open.egg-info/requires.txt +1 -0
- cmd_case_open-0.1.0/cmd_case_open.egg-info/top_level.txt +1 -0
- cmd_case_open-0.1.0/pyproject.toml +28 -0
- cmd_case_open-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ShravanPH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cmd-case-open
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI for terminal case opening experiments
|
|
5
|
+
Author-email: ShravanPH <shravan_ph@yahoo.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: terminaltexteffects>=0.11
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# cmd_case_open
|
|
14
|
+
|
|
15
|
+
A CLI project that simulates **Counter-Strike–style case openings** directly in your terminal.
|
|
16
|
+
|
|
17
|
+
Open cases, reveal randomized items with rarity tiers, and track your inventory all from your shell.
|
|
18
|
+
|
|
19
|
+
## Demo
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- Counter-Strike–inspired case opening system
|
|
28
|
+
- Rarity-based item generation
|
|
29
|
+
- Persistent inventory + stats tracking
|
|
30
|
+
- Shell-integrated commands (run after any terminal command)
|
|
31
|
+
- Supports Zsh and PowerShell
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
You can install `cmd_case_open` in two ways:
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
### Option 1: Install via pip (Recommended)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install <project-link>
|
|
45
|
+
````
|
|
46
|
+
|
|
47
|
+
Then initialize the CLI:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
cmd-case-open
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
During setup:
|
|
54
|
+
|
|
55
|
+
* Your shell configuration (`.zshrc` or PowerShell profile) will be automatically updated
|
|
56
|
+
* You will be prompted to **restart your terminal**
|
|
57
|
+
|
|
58
|
+
After restarting, the CLI is fully active.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Option 2: Install from source (Git clone)
|
|
63
|
+
|
|
64
|
+
Clone the repository:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
git clone https://github.com/ShravanPH/CSCLI.git
|
|
68
|
+
cd CSCLI
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Install locally in editable mode:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install -e .
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Run setup:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
cmd-case-open
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Restart your terminal when prompted.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## How It Works
|
|
87
|
+
|
|
88
|
+
After installation and terminal restart:
|
|
89
|
+
|
|
90
|
+
Every time you run a command in your terminal, you’ll be given the option to:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
case-reveal # Open a case
|
|
94
|
+
case-reveal-stats # View your inventory + stats
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This behavior is powered by **shell hooks** that are automatically added to:
|
|
98
|
+
|
|
99
|
+
* `~/.zshrc` (Zsh)
|
|
100
|
+
* PowerShell profile (Windows)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Shell Integration
|
|
104
|
+
|
|
105
|
+
The CLI modifies your shell configuration to inject its behavior.
|
|
106
|
+
|
|
107
|
+
* The startup + execution logic lives inside your shell config files
|
|
108
|
+
* This controls when `cmd-case-open` is triggered
|
|
109
|
+
|
|
110
|
+
### Customization
|
|
111
|
+
|
|
112
|
+
If you want to tweak behavior (frequency, triggers, etc.), you can edit:
|
|
113
|
+
|
|
114
|
+
* `~/.zshrc`
|
|
115
|
+
* PowerShell profile
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Project Structure
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
CSCLI/
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Contains the core logic for:
|
|
125
|
+
|
|
126
|
+
* Case randomization
|
|
127
|
+
* Item rarity system
|
|
128
|
+
* Rendering output
|
|
129
|
+
* Case data definitions
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## Data Storage
|
|
133
|
+
|
|
134
|
+
Inventory data is stored locally as JSON Lines:
|
|
135
|
+
|
|
136
|
+
Primary location:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
~/.local/state/cmd_case_open/inventory.jsonl
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Fallback:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
/tmp/cmd_case_open_state/inventory.jsonl
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Each entry includes:
|
|
149
|
+
|
|
150
|
+
* Timestamp
|
|
151
|
+
* Item name
|
|
152
|
+
* Rarity
|
|
153
|
+
* Rarity key
|
|
154
|
+
* Colorized rarity snapshot
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
## Commands
|
|
158
|
+
|
|
159
|
+
### Setup
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
cmd-case-open
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Runtime Commands
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
case-reveal
|
|
169
|
+
case-reveal-stats
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
## Supported Shells
|
|
174
|
+
|
|
175
|
+
* Zsh
|
|
176
|
+
* PowerShell
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
## Notes
|
|
180
|
+
|
|
181
|
+
* First run modifies your shell config automatically
|
|
182
|
+
* A terminal restart is required after installation
|
|
183
|
+
* Behavior is shell-driven — not a continuously running process
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
## Future Improvements (Ideas)
|
|
187
|
+
|
|
188
|
+
* More cases and skins
|
|
189
|
+
* Inventory UI improvements
|
|
190
|
+
* Drop rate customization
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
* MIT License
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
## Contributing
|
|
200
|
+
|
|
201
|
+
Contributions, issues, and ideas are welcome!
|
|
202
|
+
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# cmd_case_open
|
|
2
|
+
|
|
3
|
+
A CLI project that simulates **Counter-Strike–style case openings** directly in your terminal.
|
|
4
|
+
|
|
5
|
+
Open cases, reveal randomized items with rarity tiers, and track your inventory all from your shell.
|
|
6
|
+
|
|
7
|
+
## Demo
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Counter-Strike–inspired case opening system
|
|
16
|
+
- Rarity-based item generation
|
|
17
|
+
- Persistent inventory + stats tracking
|
|
18
|
+
- Shell-integrated commands (run after any terminal command)
|
|
19
|
+
- Supports Zsh and PowerShell
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
You can install `cmd_case_open` in two ways:
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
### Option 1: Install via pip (Recommended)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install <project-link>
|
|
33
|
+
````
|
|
34
|
+
|
|
35
|
+
Then initialize the CLI:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cmd-case-open
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
During setup:
|
|
42
|
+
|
|
43
|
+
* Your shell configuration (`.zshrc` or PowerShell profile) will be automatically updated
|
|
44
|
+
* You will be prompted to **restart your terminal**
|
|
45
|
+
|
|
46
|
+
After restarting, the CLI is fully active.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### Option 2: Install from source (Git clone)
|
|
51
|
+
|
|
52
|
+
Clone the repository:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/ShravanPH/CSCLI.git
|
|
56
|
+
cd CSCLI
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Install locally in editable mode:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install -e .
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Run setup:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
cmd-case-open
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Restart your terminal when prompted.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## How It Works
|
|
75
|
+
|
|
76
|
+
After installation and terminal restart:
|
|
77
|
+
|
|
78
|
+
Every time you run a command in your terminal, you’ll be given the option to:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
case-reveal # Open a case
|
|
82
|
+
case-reveal-stats # View your inventory + stats
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This behavior is powered by **shell hooks** that are automatically added to:
|
|
86
|
+
|
|
87
|
+
* `~/.zshrc` (Zsh)
|
|
88
|
+
* PowerShell profile (Windows)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Shell Integration
|
|
92
|
+
|
|
93
|
+
The CLI modifies your shell configuration to inject its behavior.
|
|
94
|
+
|
|
95
|
+
* The startup + execution logic lives inside your shell config files
|
|
96
|
+
* This controls when `cmd-case-open` is triggered
|
|
97
|
+
|
|
98
|
+
### Customization
|
|
99
|
+
|
|
100
|
+
If you want to tweak behavior (frequency, triggers, etc.), you can edit:
|
|
101
|
+
|
|
102
|
+
* `~/.zshrc`
|
|
103
|
+
* PowerShell profile
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Project Structure
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
CSCLI/
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Contains the core logic for:
|
|
113
|
+
|
|
114
|
+
* Case randomization
|
|
115
|
+
* Item rarity system
|
|
116
|
+
* Rendering output
|
|
117
|
+
* Case data definitions
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## Data Storage
|
|
121
|
+
|
|
122
|
+
Inventory data is stored locally as JSON Lines:
|
|
123
|
+
|
|
124
|
+
Primary location:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
~/.local/state/cmd_case_open/inventory.jsonl
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Fallback:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
/tmp/cmd_case_open_state/inventory.jsonl
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Each entry includes:
|
|
137
|
+
|
|
138
|
+
* Timestamp
|
|
139
|
+
* Item name
|
|
140
|
+
* Rarity
|
|
141
|
+
* Rarity key
|
|
142
|
+
* Colorized rarity snapshot
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
## Commands
|
|
146
|
+
|
|
147
|
+
### Setup
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
cmd-case-open
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Runtime Commands
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
case-reveal
|
|
157
|
+
case-reveal-stats
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Supported Shells
|
|
162
|
+
|
|
163
|
+
* Zsh
|
|
164
|
+
* PowerShell
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
## Notes
|
|
168
|
+
|
|
169
|
+
* First run modifies your shell config automatically
|
|
170
|
+
* A terminal restart is required after installation
|
|
171
|
+
* Behavior is shell-driven — not a continuously running process
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## Future Improvements (Ideas)
|
|
175
|
+
|
|
176
|
+
* More cases and skins
|
|
177
|
+
* Inventory UI improvements
|
|
178
|
+
* Drop rate customization
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
* MIT License
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
## Contributing
|
|
188
|
+
|
|
189
|
+
Contributions, issues, and ideas are welcome!
|
|
190
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import json
|
|
2
|
+
str = """
|
|
3
|
+
|
|
4
|
+
+##
|
|
5
|
+
*####
|
|
6
|
+
**######
|
|
7
|
+
**######%
|
|
8
|
+
+*########%%
|
|
9
|
+
+*###########%%
|
|
10
|
+
*###############%
|
|
11
|
+
+*####################
|
|
12
|
+
++*#####################
|
|
13
|
+
*+#####################%
|
|
14
|
+
*+*####################%% #*
|
|
15
|
+
+**#####################%%%%
|
|
16
|
+
*+*###################%###%%%
|
|
17
|
+
++*#################%#%%%%%%%
|
|
18
|
+
****###################%%%%%%%
|
|
19
|
+
*##############%%#%%%%#%%%%%
|
|
20
|
+
###########%%%%%%%%%%%%%%
|
|
21
|
+
##%#####%%%%%%%%%%%%%%%%%%
|
|
22
|
+
%%%###%%##%#+*##%%#######%%%
|
|
23
|
+
%%##%%%#+ *%%#%#########%%%%
|
|
24
|
+
%###% %%%#######%###%%%%
|
|
25
|
+
%#####%########%%%%%
|
|
26
|
+
#***##########%%%%%%%
|
|
27
|
+
=++##########%%%%%%%
|
|
28
|
+
*#%###%%#%%%%%%%%%
|
|
29
|
+
#%##%#%%%%%%%%%%
|
|
30
|
+
#*++##%%%%%%%#%%
|
|
31
|
+
%%#%###%%%%%%
|
|
32
|
+
@%#%%%%%%%%%%%
|
|
33
|
+
%%##%%%%%%%%%%
|
|
34
|
+
%%#####%%%%%%%%
|
|
35
|
+
:=* -#%%%%%%%%%
|
|
36
|
+
%%#%#%%%%
|
|
37
|
+
%##%%%%%
|
|
38
|
+
%%#%%%%%
|
|
39
|
+
%%#%%%%%
|
|
40
|
+
%###%%
|
|
41
|
+
%%#%%@
|
|
42
|
+
%%%%
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
id = 33
|
|
47
|
+
split = str.splitlines()
|
|
48
|
+
|
|
49
|
+
with open("data/spectrum-case.json","r") as r:
|
|
50
|
+
caseFile = json.load(r)
|
|
51
|
+
caseFile[id]["ascii"] = split
|
|
52
|
+
with open("data/spectrum-case.json","w") as w:
|
|
53
|
+
json.dump(caseFile,w, indent=3)
|
|
54
|
+
|
|
55
|
+
# print(json.loads(caseFile)[0]["ascii"])
|
|
56
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Core utilities for rendering and formatting."""
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
ANSI_RESET = "\x1b[0m"
|
|
6
|
+
BANNER_COLOR = "\x1b[38;2;255;255;255m"
|
|
7
|
+
|
|
8
|
+
RARITY_TO_COLOR = {
|
|
9
|
+
"mil-spec": "\x1b[38;2;59;130;246m",
|
|
10
|
+
"restricted": "\x1b[38;2;139;92;246m",
|
|
11
|
+
"classified": "\x1b[38;2;236;72;153m",
|
|
12
|
+
"covert": "\x1b[38;2;239;68;68m",
|
|
13
|
+
"extraordinary": "\x1b[38;2;245;158;11m",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
RARITY_ORDER = ("mil-spec", "restricted", "classified", "covert", "extraordinary")
|
|
17
|
+
|
|
18
|
+
TTE_EFFECT_POOL = (
|
|
19
|
+
"blackhole",
|
|
20
|
+
"burn",
|
|
21
|
+
"decrypt",
|
|
22
|
+
"middleout",
|
|
23
|
+
"wipe",
|
|
24
|
+
"slice",
|
|
25
|
+
"smoke",
|
|
26
|
+
"rain",
|
|
27
|
+
"randomsequence",
|
|
28
|
+
"beams",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
TTE_EFFECT_POOL_WINDOWS = (
|
|
32
|
+
"middleout",
|
|
33
|
+
"wipe",
|
|
34
|
+
"slice",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
ANSI_PATTERN = re.compile(r"\x1b\[[0-9;]*m")
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
from .constants import ANSI_RESET, BANNER_COLOR, RARITY_TO_COLOR, TTE_EFFECT_POOL, TTE_EFFECT_POOL_WINDOWS
|
|
9
|
+
from .utils import colorize_rarity, rarity_key
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def render_display_block(name: str, rarity: str, ascii_art: str) -> str:
|
|
13
|
+
width = shutil.get_terminal_size(fallback=(120, 40)).columns
|
|
14
|
+
width = max(80, width)
|
|
15
|
+
rarity_color = RARITY_TO_COLOR.get(rarity_key(rarity), "\x1b[37m")
|
|
16
|
+
|
|
17
|
+
border = f"{BANNER_COLOR}{'=' * width}{ANSI_RESET}"
|
|
18
|
+
title = f" DROP UNLOCKED | {name} | {rarity} "
|
|
19
|
+
title_line = f"{rarity_color}{title.center(width, '=')[:width]}{ANSI_RESET}"
|
|
20
|
+
|
|
21
|
+
content_lines: list[str] = [border, title_line, border]
|
|
22
|
+
if isinstance(ascii_art, list):
|
|
23
|
+
raw_ascii = "\n".join(str(line) for line in ascii_art).strip("\n")
|
|
24
|
+
else:
|
|
25
|
+
raw_ascii = str(ascii_art or "").strip("\n")
|
|
26
|
+
|
|
27
|
+
if raw_ascii:
|
|
28
|
+
for ascii_line in raw_ascii.splitlines():
|
|
29
|
+
centered = ascii_line[:width].center(width)
|
|
30
|
+
content_lines.append(f"{rarity_color}{centered}{ANSI_RESET}")
|
|
31
|
+
else:
|
|
32
|
+
fallback = f"[ no ascii configured for {name} ]".center(width)
|
|
33
|
+
content_lines.append(f"{rarity_color}{fallback}{ANSI_RESET}")
|
|
34
|
+
|
|
35
|
+
content_lines.append(border)
|
|
36
|
+
return "\n".join(content_lines)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def run_random_tte(display_block: str, timeout_seconds: float = 120.0) -> bool:
|
|
40
|
+
frameRate = ""
|
|
41
|
+
selected_effect = ""
|
|
42
|
+
if os.name == "nt":
|
|
43
|
+
frameRate = "240"
|
|
44
|
+
selected_effect = random.choice(TTE_EFFECT_POOL_WINDOWS)
|
|
45
|
+
else:
|
|
46
|
+
frameRate = "0"
|
|
47
|
+
selected_effect = random.choice(TTE_EFFECT_POOL)
|
|
48
|
+
|
|
49
|
+
command = [
|
|
50
|
+
"tte",
|
|
51
|
+
"--frame-rate",
|
|
52
|
+
frameRate,
|
|
53
|
+
"--canvas-width",
|
|
54
|
+
"0",
|
|
55
|
+
"--existing-color-handling",
|
|
56
|
+
"always",
|
|
57
|
+
selected_effect,
|
|
58
|
+
]
|
|
59
|
+
try:
|
|
60
|
+
subprocess.run(
|
|
61
|
+
command,
|
|
62
|
+
input=display_block,
|
|
63
|
+
text=True,
|
|
64
|
+
check=True,
|
|
65
|
+
timeout=timeout_seconds,
|
|
66
|
+
encoding="utf-8"
|
|
67
|
+
)
|
|
68
|
+
except subprocess.TimeoutExpired as e:
|
|
69
|
+
print("Process time out:", e)
|
|
70
|
+
return True
|
|
71
|
+
except (FileNotFoundError, subprocess.CalledProcessError,UnicodeEncodeError) as e:
|
|
72
|
+
print("Error:", e)
|
|
73
|
+
return False
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def print_case_open_fallback(name: str, rarity: str, ascii_art: str) -> None:
|
|
78
|
+
colored_rarity = colorize_rarity(rarity)
|
|
79
|
+
print(f"Unlocked: {name} [{colored_rarity}]")
|
|
80
|
+
if not ascii_art:
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
color = RARITY_TO_COLOR.get(rarity_key(rarity), "")
|
|
84
|
+
reset = ANSI_RESET if color else ""
|
|
85
|
+
if isinstance(ascii_art, list):
|
|
86
|
+
fallback_ascii = "\n".join(str(line) for line in ascii_art)
|
|
87
|
+
else:
|
|
88
|
+
fallback_ascii = str(ascii_art)
|
|
89
|
+
print(f"{color}{fallback_ascii}{reset}")
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from .constants import ANSI_PATTERN, ANSI_RESET, RARITY_TO_COLOR
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def rarity_key(rarity: str) -> str:
|
|
9
|
+
return (rarity or "").split()[0].lower()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def rarity_label(key: str) -> str:
|
|
13
|
+
labels = {
|
|
14
|
+
"mil-spec": "Mil-Spec",
|
|
15
|
+
"restricted": "Restricted",
|
|
16
|
+
"classified": "Classified",
|
|
17
|
+
"covert": "Covert",
|
|
18
|
+
"extraordinary": "Extraordinary",
|
|
19
|
+
}
|
|
20
|
+
return labels.get(key, key.title())
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def force_colorize_rarity(rarity: str) -> str:
|
|
24
|
+
key = rarity_key(rarity)
|
|
25
|
+
color = RARITY_TO_COLOR.get(key, "")
|
|
26
|
+
if not color:
|
|
27
|
+
return rarity
|
|
28
|
+
return f"{color}{rarity}{ANSI_RESET}"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def colorize_rarity(rarity: str) -> str:
|
|
32
|
+
if os.getenv("NO_COLOR") or not os.isatty(1):
|
|
33
|
+
return rarity
|
|
34
|
+
return force_colorize_rarity(rarity)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def visible_length(text: str) -> int:
|
|
38
|
+
return len(ANSI_PATTERN.sub("", text))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Packaged data assets for cmd_case_open."""
|