gac 2.2.0__py3-none-any.whl → 2.4.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.
Potentially problematic release.
This version of gac might be problematic. Click here for more details.
- gac/__version__.py +1 -1
- gac/ai.py +26 -0
- gac/ai_utils.py +28 -13
- gac/cli.py +7 -1
- gac/config.py +1 -0
- gac/constants.py +1 -1
- gac/git.py +107 -8
- gac/init_cli.py +305 -73
- gac/language_cli.py +177 -9
- gac/main.py +505 -169
- gac/prompt.py +101 -15
- gac/security.py +1 -1
- gac/utils.py +104 -3
- gac/workflow_utils.py +131 -0
- {gac-2.2.0.dist-info → gac-2.4.0.dist-info}/METADATA +36 -9
- {gac-2.2.0.dist-info → gac-2.4.0.dist-info}/RECORD +19 -18
- {gac-2.2.0.dist-info → gac-2.4.0.dist-info}/WHEEL +0 -0
- {gac-2.2.0.dist-info → gac-2.4.0.dist-info}/entry_points.txt +0 -0
- {gac-2.2.0.dist-info → gac-2.4.0.dist-info}/licenses/LICENSE +0 -0
gac/language_cli.py
CHANGED
|
@@ -1,16 +1,165 @@
|
|
|
1
1
|
"""CLI for selecting commit message language interactively."""
|
|
2
2
|
|
|
3
|
+
import os
|
|
4
|
+
import unicodedata
|
|
3
5
|
from pathlib import Path
|
|
4
6
|
|
|
5
7
|
import click
|
|
6
8
|
import questionary
|
|
7
|
-
from dotenv import
|
|
9
|
+
from dotenv import load_dotenv, set_key
|
|
8
10
|
|
|
9
11
|
from gac.constants import Languages
|
|
10
12
|
|
|
11
13
|
GAC_ENV_PATH = Path.home() / ".gac.env"
|
|
12
14
|
|
|
13
15
|
|
|
16
|
+
def should_show_rtl_warning() -> bool:
|
|
17
|
+
"""Check if RTL warning should be shown based on saved preference.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
True if warning should be shown, False if user previously confirmed
|
|
21
|
+
"""
|
|
22
|
+
# Load the current config to check RTL confirmation
|
|
23
|
+
if GAC_ENV_PATH.exists():
|
|
24
|
+
load_dotenv(GAC_ENV_PATH)
|
|
25
|
+
rtl_confirmed = os.getenv("GAC_RTL_CONFIRMED", "false").lower() in ("true", "1", "yes", "on")
|
|
26
|
+
return not rtl_confirmed
|
|
27
|
+
return True # Show warning if no config exists
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_rtl_text(text: str) -> bool:
|
|
31
|
+
"""Detect if text contains RTL characters or is a known RTL language.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
text: Text to analyze
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
True if text contains RTL script characters or is RTL language
|
|
38
|
+
"""
|
|
39
|
+
# Known RTL language names (case insensitive)
|
|
40
|
+
rtl_languages = {
|
|
41
|
+
"arabic",
|
|
42
|
+
"ar",
|
|
43
|
+
"العربية",
|
|
44
|
+
"hebrew",
|
|
45
|
+
"he",
|
|
46
|
+
"עברית",
|
|
47
|
+
"persian",
|
|
48
|
+
"farsi",
|
|
49
|
+
"fa",
|
|
50
|
+
"urdu",
|
|
51
|
+
"ur",
|
|
52
|
+
"اردو",
|
|
53
|
+
"pashto",
|
|
54
|
+
"ps",
|
|
55
|
+
"kurdish",
|
|
56
|
+
"ku",
|
|
57
|
+
"کوردی",
|
|
58
|
+
"yiddish",
|
|
59
|
+
"yi",
|
|
60
|
+
"ייִדיש",
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Check if it's a known RTL language name or code (case insensitive)
|
|
64
|
+
if text.lower().strip() in rtl_languages:
|
|
65
|
+
return True
|
|
66
|
+
|
|
67
|
+
rtl_scripts = {"Arabic", "Hebrew", "Thaana", "Nko", "Syriac", "Mandeic", "Samaritan", "Mongolian", "Phags-Pa"}
|
|
68
|
+
|
|
69
|
+
for char in text:
|
|
70
|
+
if unicodedata.name(char, "").startswith(("ARABIC", "HEBREW")):
|
|
71
|
+
return True
|
|
72
|
+
script = unicodedata.name(char, "").split()[0] if unicodedata.name(char, "") else ""
|
|
73
|
+
if script in rtl_scripts:
|
|
74
|
+
return True
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def center_text(text: str, width: int = 80) -> str:
|
|
79
|
+
"""Center text within specified width, handling display width properly.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
text: Text to center
|
|
83
|
+
width: Terminal width to center within (default 80)
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
Centered text with proper padding
|
|
87
|
+
"""
|
|
88
|
+
import unicodedata
|
|
89
|
+
|
|
90
|
+
def get_display_width(s: str) -> int:
|
|
91
|
+
"""Get the display width of a string, accounting for wide characters."""
|
|
92
|
+
width = 0
|
|
93
|
+
for char in s:
|
|
94
|
+
# East Asian characters are typically 2 columns wide
|
|
95
|
+
if unicodedata.east_asian_width(char) in ("W", "F"):
|
|
96
|
+
width += 2
|
|
97
|
+
else:
|
|
98
|
+
width += 1
|
|
99
|
+
return width
|
|
100
|
+
|
|
101
|
+
# Handle multi-line text
|
|
102
|
+
lines = text.split("\n")
|
|
103
|
+
centered_lines = []
|
|
104
|
+
|
|
105
|
+
for line in lines:
|
|
106
|
+
# Strip existing whitespace to avoid double padding
|
|
107
|
+
stripped_line = line.strip()
|
|
108
|
+
if stripped_line:
|
|
109
|
+
# Calculate padding using display width for accurate centering
|
|
110
|
+
display_width = get_display_width(stripped_line)
|
|
111
|
+
padding = max(0, (width - display_width) // 2)
|
|
112
|
+
centered_line = " " * padding + stripped_line
|
|
113
|
+
centered_lines.append(centered_line)
|
|
114
|
+
else:
|
|
115
|
+
centered_lines.append("")
|
|
116
|
+
|
|
117
|
+
return "\n".join(centered_lines)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def get_terminal_width() -> int:
|
|
121
|
+
"""Get the current terminal width.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Terminal width in characters, or default if can't be determined
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
import shutil
|
|
128
|
+
|
|
129
|
+
return shutil.get_terminal_size().columns
|
|
130
|
+
except (OSError, AttributeError):
|
|
131
|
+
return 80 # Fallback to 80 columns
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def show_rtl_warning(language_name: str) -> bool:
|
|
135
|
+
"""Show RTL language warning and ask for confirmation.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
language_name: Name of the RTL language
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
True if user wants to proceed, False if they cancel
|
|
142
|
+
"""
|
|
143
|
+
terminal_width = get_terminal_width()
|
|
144
|
+
|
|
145
|
+
# Center just the title
|
|
146
|
+
title = center_text("⚠️ RTL Language Detected", terminal_width)
|
|
147
|
+
|
|
148
|
+
click.echo()
|
|
149
|
+
click.echo(click.style(title, fg="yellow", bold=True))
|
|
150
|
+
click.echo()
|
|
151
|
+
click.echo("Right-to-left (RTL) languages may not display correctly in gac due to terminal limitations.")
|
|
152
|
+
click.echo("However, the commit messages will work fine and should be readable in Git clients")
|
|
153
|
+
click.echo("that properly support RTL text (like most web interfaces and modern tools).\n")
|
|
154
|
+
|
|
155
|
+
proceed = questionary.confirm("Do you want to proceed anyway?").ask()
|
|
156
|
+
if proceed:
|
|
157
|
+
# Remember that user has confirmed RTL acceptance
|
|
158
|
+
set_key(str(GAC_ENV_PATH), "GAC_RTL_CONFIRMED", "true")
|
|
159
|
+
click.echo("✓ RTL preference saved - you won't see this warning again")
|
|
160
|
+
return proceed if proceed is not None else False
|
|
161
|
+
|
|
162
|
+
|
|
14
163
|
@click.command()
|
|
15
164
|
def language() -> None:
|
|
16
165
|
"""Set the language for commit messages interactively."""
|
|
@@ -18,7 +167,7 @@ def language() -> None:
|
|
|
18
167
|
|
|
19
168
|
display_names = [lang[0] for lang in Languages.LANGUAGES]
|
|
20
169
|
selection = questionary.select(
|
|
21
|
-
"Choose your language:", choices=display_names, use_shortcuts=True, use_arrow_keys=True
|
|
170
|
+
"Choose your language:", choices=display_names, use_shortcuts=True, use_arrow_keys=True, use_jk_keys=False
|
|
22
171
|
).ask()
|
|
23
172
|
|
|
24
173
|
if not selection:
|
|
@@ -30,14 +179,14 @@ def language() -> None:
|
|
|
30
179
|
GAC_ENV_PATH.touch()
|
|
31
180
|
click.echo(f"Created {GAC_ENV_PATH}")
|
|
32
181
|
|
|
33
|
-
# Handle English
|
|
182
|
+
# Handle English - set explicitly
|
|
34
183
|
if selection == "English":
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
184
|
+
set_key(str(GAC_ENV_PATH), "GAC_LANGUAGE", "English")
|
|
185
|
+
set_key(str(GAC_ENV_PATH), "GAC_TRANSLATE_PREFIXES", "false")
|
|
186
|
+
click.echo("✓ Set language to English")
|
|
187
|
+
click.echo(" GAC_LANGUAGE=English")
|
|
188
|
+
click.echo(" GAC_TRANSLATE_PREFIXES=false")
|
|
189
|
+
click.echo(f"\n Configuration saved to {GAC_ENV_PATH}")
|
|
41
190
|
return
|
|
42
191
|
|
|
43
192
|
# Handle custom input
|
|
@@ -47,10 +196,29 @@ def language() -> None:
|
|
|
47
196
|
click.echo("No language entered. Cancelled.")
|
|
48
197
|
return
|
|
49
198
|
language_value = custom_language.strip()
|
|
199
|
+
|
|
200
|
+
# Check if the custom language appears to be RTL
|
|
201
|
+
if is_rtl_text(language_value):
|
|
202
|
+
if not should_show_rtl_warning():
|
|
203
|
+
click.echo(f"\nℹ️ Using RTL language {language_value} (RTL warning previously confirmed)")
|
|
204
|
+
else:
|
|
205
|
+
if not show_rtl_warning(language_value):
|
|
206
|
+
click.echo("Language selection cancelled.")
|
|
207
|
+
return
|
|
208
|
+
|
|
50
209
|
else:
|
|
51
210
|
# Find the English name for the selected language
|
|
52
211
|
language_value = next(lang[1] for lang in Languages.LANGUAGES if lang[0] == selection)
|
|
53
212
|
|
|
213
|
+
# Check if predefined language is RTL
|
|
214
|
+
if is_rtl_text(language_value):
|
|
215
|
+
if not should_show_rtl_warning():
|
|
216
|
+
click.echo(f"\nℹ️ Using RTL language {language_value} (RTL warning previously confirmed)")
|
|
217
|
+
else:
|
|
218
|
+
if not show_rtl_warning(language_value):
|
|
219
|
+
click.echo("Language selection cancelled.")
|
|
220
|
+
return
|
|
221
|
+
|
|
54
222
|
# Ask about prefix translation
|
|
55
223
|
click.echo() # Blank line for spacing
|
|
56
224
|
prefix_choice = questionary.select(
|