fix: assume 200char terminal if no terminal size is available
closes #11477
This commit is contained in:
@@ -17,11 +17,11 @@ def start_list_exchanges(args: dict[str, Any]) -> None:
|
|||||||
:param args: Cli args from Arguments()
|
:param args: Cli args from Arguments()
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
from rich.console import Console
|
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
from freqtrade.exchange import list_available_exchanges
|
from freqtrade.exchange import list_available_exchanges
|
||||||
|
from freqtrade.loggers.rich_console import get_rich_console
|
||||||
|
|
||||||
available_exchanges: list[ValidExchangesType] = list_available_exchanges(
|
available_exchanges: list[ValidExchangesType] = list_available_exchanges(
|
||||||
args["list_exchanges_all"]
|
args["list_exchanges_all"]
|
||||||
@@ -77,15 +77,16 @@ def start_list_exchanges(args: dict[str, Any]) -> None:
|
|||||||
)
|
)
|
||||||
# table.add_row(*[exchange[header] for header in headers])
|
# table.add_row(*[exchange[header] for header in headers])
|
||||||
|
|
||||||
console = Console()
|
console = get_rich_console()
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
|
|
||||||
def _print_objs_tabular(objs: list, print_colorized: bool) -> None:
|
def _print_objs_tabular(objs: list, print_colorized: bool) -> None:
|
||||||
from rich.console import Console
|
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
|
from freqtrade.loggers.rich_console import get_rich_console
|
||||||
|
|
||||||
names = [s["name"] for s in objs]
|
names = [s["name"] for s in objs]
|
||||||
objs_to_print: list[dict[str, Text | str]] = [
|
objs_to_print: list[dict[str, Text | str]] = [
|
||||||
{
|
{
|
||||||
@@ -118,10 +119,7 @@ def _print_objs_tabular(objs: list, print_colorized: bool) -> None:
|
|||||||
for row in objs_to_print:
|
for row in objs_to_print:
|
||||||
table.add_row(*[row[header] for header in objs_to_print[0].keys()])
|
table.add_row(*[row[header] for header in objs_to_print[0].keys()])
|
||||||
|
|
||||||
console = Console(
|
console = get_rich_console(color_system="auto" if print_colorized else None)
|
||||||
color_system="auto" if print_colorized else None,
|
|
||||||
width=200 if "pytest" in sys.modules else None,
|
|
||||||
)
|
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ from logging import Formatter
|
|||||||
from logging.handlers import RotatingFileHandler, SysLogHandler
|
from logging.handlers import RotatingFileHandler, SysLogHandler
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from rich.console import Console
|
|
||||||
|
|
||||||
from freqtrade.constants import Config
|
from freqtrade.constants import Config
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.loggers.buffering_handler import FTBufferingHandler
|
from freqtrade.loggers.buffering_handler import FTBufferingHandler
|
||||||
from freqtrade.loggers.ft_rich_handler import FtRichHandler
|
from freqtrade.loggers.ft_rich_handler import FtRichHandler
|
||||||
|
from freqtrade.loggers.rich_console import get_rich_console
|
||||||
from freqtrade.loggers.set_log_levels import set_loggers
|
from freqtrade.loggers.set_log_levels import set_loggers
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +21,8 @@ LOGFORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|||||||
bufferHandler = FTBufferingHandler(1000)
|
bufferHandler = FTBufferingHandler(1000)
|
||||||
bufferHandler.setFormatter(Formatter(LOGFORMAT))
|
bufferHandler.setFormatter(Formatter(LOGFORMAT))
|
||||||
|
|
||||||
error_console = Console(stderr=True, color_system=None)
|
|
||||||
|
error_console = get_rich_console(stderr=True, color_system=None)
|
||||||
|
|
||||||
|
|
||||||
def get_existing_handlers(handlertype):
|
def get_existing_handlers(handlertype):
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import sys
|
||||||
|
from shutil import get_terminal_size
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
def console_width() -> int | None:
|
||||||
|
"""
|
||||||
|
Get the width of the console
|
||||||
|
"""
|
||||||
|
if any(module in ["pytest", "ipykernel"] for module in sys.modules):
|
||||||
|
return 200
|
||||||
|
|
||||||
|
width, _ = get_terminal_size((1, 24))
|
||||||
|
# Fall back to 200 if terminal size is not available.
|
||||||
|
# This is determined by assuming an insane width of 1char, which is unlikely.
|
||||||
|
w = None if width > 1 else 200
|
||||||
|
return w
|
||||||
|
|
||||||
|
|
||||||
|
def get_rich_console(**kwargs) -> Console:
|
||||||
|
"""
|
||||||
|
Get a rich console with default settings
|
||||||
|
"""
|
||||||
|
kwargs["width"] = kwargs.get("width", console_width())
|
||||||
|
return Console(**kwargs)
|
||||||
@@ -7,7 +7,6 @@ from rich.progress import (
|
|||||||
TimeRemainingColumn,
|
TimeRemainingColumn,
|
||||||
)
|
)
|
||||||
|
|
||||||
from freqtrade.loggers import error_console
|
|
||||||
from freqtrade.util.rich_progress import CustomProgress
|
from freqtrade.util.rich_progress import CustomProgress
|
||||||
|
|
||||||
|
|
||||||
@@ -21,6 +20,8 @@ def get_progress_tracker(**kwargs) -> CustomProgress:
|
|||||||
"""
|
"""
|
||||||
Get progress Bar with custom columns.
|
Get progress Bar with custom columns.
|
||||||
"""
|
"""
|
||||||
|
from freqtrade.loggers import error_console
|
||||||
|
|
||||||
return CustomProgress(
|
return CustomProgress(
|
||||||
TextColumn("[progress.description]{task.description}"),
|
TextColumn("[progress.description]{task.description}"),
|
||||||
BarColumn(bar_width=None),
|
BarColumn(bar_width=None),
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import sys
|
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Any, TypeAlias
|
from typing import Any, TypeAlias
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from rich.console import Console
|
|
||||||
from rich.table import Column, Table
|
from rich.table import Column, Table
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
|
from freqtrade.loggers.rich_console import get_rich_console
|
||||||
|
|
||||||
|
|
||||||
TextOrString: TypeAlias = str | Text
|
TextOrString: TypeAlias = str | Text
|
||||||
|
|
||||||
@@ -38,11 +38,7 @@ def print_rich_table(
|
|||||||
row_to_add: list[str | Text] = [r if isinstance(r, Text) else str(r) for r in row]
|
row_to_add: list[str | Text] = [r if isinstance(r, Text) else str(r) for r in row]
|
||||||
table.add_row(*row_to_add)
|
table.add_row(*row_to_add)
|
||||||
|
|
||||||
width = None
|
console = get_rich_console()
|
||||||
if any(module in ["pytest", "ipykernel"] for module in sys.modules):
|
|
||||||
width = 200
|
|
||||||
|
|
||||||
console = Console(width=width)
|
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
|
|
||||||
@@ -74,9 +70,5 @@ def print_df_rich_table(
|
|||||||
row = [_format_value(x, floatfmt=".3f") for x in value_list]
|
row = [_format_value(x, floatfmt=".3f") for x in value_list]
|
||||||
table.add_row(*row)
|
table.add_row(*row)
|
||||||
|
|
||||||
width = None
|
console = get_rich_console()
|
||||||
if any(module in ["pytest", "ipykernel"] for module in sys.modules):
|
|
||||||
width = 200
|
|
||||||
|
|
||||||
console = Console(width=width)
|
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|||||||
Reference in New Issue
Block a user