Skip to content

Commit 6d0c868

Browse files
authored
Merge pull request #18 from bnbong/dev
[HOTFIX, RELEASE] fix console object searching error, add console size adjustment feature
2 parents 44b6397 + 5657e04 commit 6d0c868

File tree

11 files changed

+389
-40
lines changed

11 files changed

+389
-40
lines changed

.github/workflows/distribute.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ jobs:
2727
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
2828

2929
- name: Update version in __init__.py
30-
run: |
31-
echo "__version__ = '${{ steps.tag.outputs.TAG_NAME }}'" > src/fastapi_fastkit/__init__.py
30+
run: echo "__version__ = '${{ steps.tag.outputs.TAG_NAME }}'" > src/fastapi_fastkit/__init__.py
3231

3332
- name: Build package
3433
run: pdm build

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# Changelog
22

3+
## v1.1.5 (2025-09-14)
4+
5+
### Improvements
6+
7+
- **Adaptive Console Sizing**: Enhanced terminal output display
8+
- Console width is 80% of terminal width, capped at 120 characters
9+
- Console height is terminal height minus buffer (5 lines)
10+
- Automatic terminal size detection with fallback to default sizes (80x24)
11+
- Dynamic sizing based on actual terminal dimensions
12+
13+
### Fixes
14+
15+
- **Text Truncation Prevention**: Completely eliminated text truncation in CLI output
16+
- Template names and descriptions are now fully displayed without "..." truncation
17+
- Table columns automatically adjust to content length to prevent text cutting
18+
- Added `overflow="fold"` and `no_wrap=False` settings to Rich tables
19+
- Template listing now shows complete template names (e.g., `fastapi-custom-response` instead of `fastapi-custom-respo...`)
20+
- **Fixing the object `console` not found error**
21+
- this critical error was occurred every version before this version.
22+
- this error was occurred because of the mismatched logic between distribute github actions workflow and the top `__init__.py` file of fastkit project package.
23+
- This issue was discovered during the development of version 1.1.2, and I spent a lot of time troubleshooting it. I believe this was due to my lack of development experience. I sincerely apologize.
24+
25+
## v1.1.4 (deprecated)
26+
27+
this version was hotfix build, but it is deprecated.
28+
29+
The issues that were being addressed during the development of this version remained unresolved and were fixed in version v1.1.5.
30+
31+
For more details, please refer to the CHANGELOG.md file for v1.1.5.
32+
333
## v1.1.3 (2025-09-13)
434

535
### Templates

src/fastapi_fastkit/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
__version__ = "1.1.3"
2-
3-
import os
4-
5-
from rich.console import Console
6-
7-
if "PYTEST_CURRENT_TEST" in os.environ:
8-
console = Console(no_color=True)
9-
else:
10-
console = Console()
1+
__version__ = "1.1.5"

src/fastapi_fastkit/backend/package_managers/pdm_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
import sys
99
from typing import List
1010

11-
from fastapi_fastkit import console
1211
from fastapi_fastkit.core.exceptions import BackendExceptions
1312
from fastapi_fastkit.utils.logging import debug_log, get_logger
14-
from fastapi_fastkit.utils.main import handle_exception, print_error, print_success
13+
from fastapi_fastkit.utils.main import (
14+
console,
15+
handle_exception,
16+
print_error,
17+
print_success,
18+
)
1519

1620
from .base import BasePackageManager
1721

src/fastapi_fastkit/backend/package_managers/pip_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
import sys
99
from typing import List
1010

11-
from fastapi_fastkit import console
1211
from fastapi_fastkit.core.exceptions import BackendExceptions
1312
from fastapi_fastkit.utils.logging import debug_log, get_logger
14-
from fastapi_fastkit.utils.main import handle_exception, print_error, print_success
13+
from fastapi_fastkit.utils.main import (
14+
console,
15+
handle_exception,
16+
print_error,
17+
print_success,
18+
)
1519

1620
from .base import BasePackageManager
1721

src/fastapi_fastkit/backend/package_managers/poetry_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import subprocess
77
from typing import List
88

9-
from fastapi_fastkit import console
109
from fastapi_fastkit.core.exceptions import BackendExceptions
1110
from fastapi_fastkit.utils.logging import debug_log, get_logger
12-
from fastapi_fastkit.utils.main import handle_exception, print_error, print_success
11+
from fastapi_fastkit.utils.main import (
12+
console,
13+
handle_exception,
14+
print_error,
15+
print_success,
16+
)
1317

1418
from .base import BasePackageManager
1519

src/fastapi_fastkit/backend/package_managers/uv_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
import subprocess
88
from typing import List
99

10-
from fastapi_fastkit import console
1110
from fastapi_fastkit.core.exceptions import BackendExceptions
1211
from fastapi_fastkit.utils.logging import debug_log, get_logger
13-
from fastapi_fastkit.utils.main import handle_exception, print_error, print_success
12+
from fastapi_fastkit.utils.main import (
13+
console,
14+
handle_exception,
15+
print_error,
16+
print_success,
17+
)
1418

1519
from .base import BasePackageManager
1620

src/fastapi_fastkit/cli.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO : add a feature to automatically fix appropriate fastkit output console size
21
# --------------------------------------------------------------------------
32
# The Module defines main and core CLI operations for FastAPI-fastkit.
43
#
@@ -31,6 +30,7 @@
3130
from fastapi_fastkit.core.exceptions import CLIExceptions
3231
from fastapi_fastkit.core.settings import FastkitConfig
3332
from fastapi_fastkit.utils.logging import get_logger, setup_logging
33+
from fastapi_fastkit.utils.main import console as utils_console
3434
from fastapi_fastkit.utils.main import (
3535
create_info_table,
3636
is_fastkit_project,
@@ -41,7 +41,9 @@
4141
validate_email,
4242
)
4343

44-
from . import __version__, console
44+
console = utils_console
45+
46+
from . import __version__
4547

4648

4749
@click.group()
@@ -97,6 +99,7 @@ def echo(ctx: Context) -> None:
9799
Deploy FastAPI app foundation instantly at your local!
98100
99101
---
102+
100103
- Project Maintainer : [link=mailto:bbbong9@gmail.com]bnbong(JunHyeok Lee)[/link]
101104
- Current Version : {__version__}
102105
- Github : [link]https://github.com/bnbong/FastAPI-fastkit[/link]
@@ -135,8 +138,7 @@ def list_templates(ctx: Context) -> None:
135138
print_warning("No available templates.")
136139
return
137140

138-
table = create_info_table("Available Templates")
139-
141+
template_data = {}
140142
for template in templates:
141143
template_path = os.path.join(template_dir, template)
142144
readme_path = os.path.join(template_path, "README.md-tpl")
@@ -148,8 +150,9 @@ def list_templates(ctx: Context) -> None:
148150
if first_line.startswith("# "):
149151
description = first_line[2:]
150152

151-
table.add_row(template, description)
153+
template_data[template] = description
152154

155+
table = create_info_table("Available Templates", template_data)
153156
console.print(table)
154157

155158

src/fastapi_fastkit/utils/main.py

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from rich.table import Table
1616
from rich.text import Text
1717

18-
from fastapi_fastkit import console
1918
from fastapi_fastkit.core.settings import settings
2019
from fastapi_fastkit.utils.logging import debug_log, get_logger
2120

@@ -25,6 +24,66 @@
2524
REGEX = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b"
2625

2726

27+
def get_optimal_console_size() -> tuple[int, int]:
28+
"""
29+
Get optimal console size based on terminal dimensions.
30+
31+
Returns:
32+
tuple: (width, height) - optimal console dimensions
33+
"""
34+
try:
35+
# Get terminal size
36+
terminal_size = os.get_terminal_size()
37+
width = terminal_size.columns
38+
height = terminal_size.lines
39+
40+
# Set minimum and maximum constraints
41+
min_width = 80
42+
max_width = 120
43+
min_height = 24
44+
45+
# Calculate optimal width (80% of terminal width, but within constraints)
46+
optimal_width = max(min_width, min(max_width, int(width * 0.8)))
47+
# Calculate optimal height (leave some space for prompt and buffer)
48+
optimal_height = max(min_height, height - 5)
49+
50+
return optimal_width, optimal_height
51+
except (OSError, ValueError):
52+
# Fallback to default size if terminal size detection fails
53+
return 80, 24
54+
55+
56+
def create_adaptive_console() -> Console:
57+
"""
58+
Create a console instance with adaptive sizing based on terminal dimensions.
59+
60+
Returns:
61+
Console: Rich console instance with optimal sizing
62+
"""
63+
if "PYTEST_CURRENT_TEST" in os.environ:
64+
return Console(no_color=True)
65+
66+
width, height = get_optimal_console_size()
67+
return Console(width=width, height=height)
68+
69+
70+
# Initialize console with adaptive sizing
71+
console = create_adaptive_console()
72+
73+
74+
def _get_adaptive_panel_width(message: str) -> int:
75+
"""
76+
Calculate optimal panel width based on message length and terminal size.
77+
78+
:param message: Message content
79+
:return: Optimal panel width
80+
"""
81+
optimal_width, _ = get_optimal_console_size()
82+
# Use message length + padding, but constrain to reasonable bounds
83+
min_width = min(len(message) + 10, optimal_width - 4)
84+
return max(40, min_width) # Minimum 40 chars, leave margin for borders
85+
86+
2887
def print_error(
2988
message: str,
3089
title: str = "Error",
@@ -42,7 +101,9 @@ def print_error(
42101
error_text = Text()
43102
error_text.append("❌ ", style="bold red")
44103
error_text.append(message)
45-
console.print(Panel(error_text, border_style="red", title=title))
104+
105+
panel_width = _get_adaptive_panel_width(message)
106+
console.print(Panel(error_text, border_style="red", title=title, width=panel_width))
46107

47108
# Log error for debugging purposes (internal logging)
48109
debug_log(f"Error: {message}", "error")
@@ -81,7 +142,11 @@ def print_success(
81142
success_text = Text()
82143
success_text.append("✨ ", style="bold yellow")
83144
success_text.append(message, style="bold green")
84-
console.print(Panel(success_text, border_style="green", title=title))
145+
146+
panel_width = _get_adaptive_panel_width(message)
147+
console.print(
148+
Panel(success_text, border_style="green", title=title, width=panel_width)
149+
)
85150

86151

87152
def print_warning(
@@ -97,7 +162,11 @@ def print_warning(
97162
warning_text = Text()
98163
warning_text.append("⚠️ ", style="bold yellow")
99164
warning_text.append(message)
100-
console.print(Panel(warning_text, border_style="yellow", title=title))
165+
166+
panel_width = _get_adaptive_panel_width(message)
167+
console.print(
168+
Panel(warning_text, border_style="yellow", title=title, width=panel_width)
169+
)
101170

102171

103172
def print_info(message: str, title: str = "Info", console: Console = console) -> None:
@@ -111,7 +180,9 @@ def print_info(message: str, title: str = "Info", console: Console = console) ->
111180
info_text = Text()
112181
info_text.append("ℹ ", style="bold blue")
113182
info_text.append(message)
114-
console.print(Panel(info_text, border_style="blue", title=title))
183+
184+
panel_width = _get_adaptive_panel_width(message)
185+
console.print(Panel(info_text, border_style="blue", title=title, width=panel_width))
115186

116187

117188
def create_info_table(
@@ -121,21 +192,61 @@ def create_info_table(
121192
console: Console = console,
122193
) -> Table:
123194
"""
124-
Create a table for displaying information.
195+
Create a table for displaying information that never truncates text.
125196
126197
:param title: Title for the table
127198
:param data: Dictionary of data to populate the table
128199
:param show_header: Whether to show table headers
129200
:param console: Rich console instance
130201
:return: Configured Rich Table instance
131202
"""
132-
table = Table(title=title, show_header=show_header, title_style="bold magenta")
133-
table.add_column("Field", style="cyan")
134-
table.add_column("Value", style="green")
203+
# Calculate exact content lengths if data exists
204+
if data:
205+
max_field_length = max(len(str(key)) for key in data.keys())
206+
max_value_length = max(len(str(value)) for value in data.values())
207+
208+
# Set column widths to exactly match the longest content
209+
# Add small padding to ensure content fits comfortably
210+
field_width = max_field_length + 2
211+
value_width = max_value_length + 2
212+
else:
213+
# Default widths for empty tables
214+
field_width = 15
215+
value_width = 30
216+
217+
# Create table that prioritizes full text display over terminal fitting
218+
table = Table(
219+
title=title,
220+
show_header=show_header,
221+
title_style="bold magenta",
222+
expand=False, # Never expand to terminal width
223+
width=None, # Let table size itself based on content
224+
pad_edge=False, # Reduce padding to save space
225+
)
226+
227+
# Add columns with settings that prevent any truncation
228+
table.add_column(
229+
"Field",
230+
style="cyan",
231+
no_wrap=False, # Allow wrapping instead of truncating
232+
width=field_width, # Exact width for content
233+
min_width=field_width, # Minimum width to prevent shrinking
234+
max_width=None, # No maximum width limit
235+
overflow="fold", # Fold text instead of truncating
236+
)
237+
table.add_column(
238+
"Value",
239+
style="green",
240+
no_wrap=False, # Allow wrapping instead of truncating
241+
width=value_width, # Exact width for content
242+
min_width=value_width, # Minimum width to prevent shrinking
243+
max_width=None, # No maximum width limit
244+
overflow="fold", # Fold text instead of truncating
245+
)
135246

136247
if data:
137248
for key, value in data.items():
138-
table.add_row(key, value)
249+
table.add_row(str(key), str(value))
139250

140251
return table
141252

0 commit comments

Comments
 (0)