summaryrefslogtreecommitdiffstats
path: root/cli/openbb_cli/config/setup.py
blob: 09bbe50527012a87d9e18dbb9154194d2bfcd127 (plain)
1
2
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Configuration for the CLI."""

import copy
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, TypeVar

import i18n

from openbb_cli.config.constants import ENV_FILE_SETTINGS, I18N_FILE, SETTINGS_DIRECTORY
from openbb_cli.session import Session

if TYPE_CHECKING:
    from openbb_charting.core.openbb_figure import OpenBBFigure

# ruff: noqa:PLW0603

OpenBBFigureT = TypeVar("OpenBBFigureT", bound="OpenBBFigure")
HOLD: bool = False
COMMAND_ON_CHART: bool = True
current_figure: Optional[OpenBBFigureT] = None  # type: ignore
new_axis: bool = True
legends: List = []
last_legend = ""


# pylint: disable=global-statement
def set_last_legend(leg: str):
    """Set the last legend."""
    global last_legend
    last_legend = copy.deepcopy(leg)


def reset_legend() -> None:
    """Reset the legend."""
    global legends
    legends = []


def get_legends() -> list:
    """Get the legends."""
    return legends


def set_same_axis() -> None:
    """Set the same axis."""
    global new_axis
    new_axis = False


def set_new_axis() -> None:
    """Set the new axis."""
    global new_axis
    new_axis = True


def make_new_axis() -> bool:
    """Make a new axis."""
    return new_axis


def get_current_figure() -> Optional["OpenBBFigure"]:
    """Get the current figure."""
    return current_figure


def set_current_figure(fig: Optional[OpenBBFigureT] = None):
    """Set the current figure."""
    # pylint: disable=global-statement
    global current_figure
    current_figure = fig


def setup_i18n(i18n_path: Path = I18N_FILE, lang: str = "en"):
    """Select the CLI translation language."""
    i18n.load_path.append(i18n_path)
    i18n.set("locale", lang)
    i18n.set("filename_format", "{locale}.{format}")


def bootstrap():
    """Setup pre-launch configurations for the CLI."""
    SETTINGS_DIRECTORY.mkdir(parents=True, exist_ok=True)
    Path(ENV_FILE_SETTINGS).touch(exist_ok=True)

    setup_i18n(lang=Session().settings.USE_LANGUAGE)