|
18 | 18 | from simple_websocket_server import WebSocket |
19 | 19 | from simple_websocket_server import WebSocketServer |
20 | 20 |
|
21 | | -BUILD_VERSION: str = "v0.5.0" |
| 21 | +BUILD_VERSION: str = "v0.5.1" |
22 | 22 |
|
23 | 23 | WINDOWS: bool = os.name == "nt" |
24 | 24 | LOCALHOST: str = "127.0.0.1" if WINDOWS else "localhost" |
25 | | -SUPER_QUIET: bool = bool(os.environ.get("NVIM_GHOST_SUPER_QUIET", False)) |
26 | | -SERVER_PORT: str = os.environ.get("GHOSTTEXT_SERVER_PORT", "4001") |
27 | | -FOCUSED_NVIM_ADDRESS = os.environ.get("NVIM_LISTEN_ADDRESS", None) |
28 | 25 | LOGGING_ENABLED: bool = False |
29 | | -VERBOSE_LOGGING: bool = bool(os.environ.get("NVIM_GHOST_VERBOSE_LOGGING")) |
30 | | -if os.environ.get("NVIM_GHOST_LOGGING_ENABLED") is not None: |
31 | | - if os.environ.get("NVIM_GHOST_LOGGING_ENABLED").isdigit(): |
32 | | - LOGGING_ENABLED = bool(int(os.environ.get("NVIM_GHOST_LOGGING_ENABLED"))) |
33 | | - else: |
34 | | - sys.exit("Invalid value of $NVIM_GHOST_LOGGING_ENABLED") |
35 | 26 |
|
36 | 27 |
|
| 28 | +def envbool(envvar: str, default: str = False) -> bool: |
| 29 | + val = os.environ.get(envvar) |
| 30 | + if val is None: |
| 31 | + return False |
| 32 | + if val.isdigit(): |
| 33 | + val = int(val) |
| 34 | + if val in (0, 1): |
| 35 | + return bool(val) |
| 36 | + raise ValueError( |
| 37 | + f"The environment variable '{envvar}', if set, should be set to either 0 or 1" |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +AUTOEXIT: bool = envbool("NVIM_GHOST_AUTO_EXIT") |
| 42 | +SUPER_QUIET: bool = envbool("NVIM_GHOST_SUPER_QUIET") |
| 43 | +LOGGING_ENABLED: bool = envbool("NVIM_GHOST_LOGGING_ENABLED") |
| 44 | +VERBOSE_LOGGING: bool = envbool("NVIM_GHOST_VERBOSE_LOGGING") |
| 45 | + |
| 46 | +FOCUSED_NVIM_ADDRESS = os.environ.get("NVIM_LISTEN_ADDRESS", None) |
| 47 | +NVIM_ADDRESSES = [FOCUSED_NVIM_ADDRESS] if FOCUSED_NVIM_ADDRESS is not None else [] |
| 48 | + |
| 49 | +SERVER_PORT: str = os.environ.get("GHOSTTEXT_SERVER_PORT", "4001") |
37 | 50 | if not SERVER_PORT.isdigit(): |
38 | 51 | if FOCUSED_NVIM_ADDRESS is not None: |
39 | 52 | with pynvim.attach("socket", path=FOCUSED_NVIM_ADDRESS) as nvim_handle: |
|
45 | 58 | sys.exit("Port must be a number") |
46 | 59 | GHOST_PORT: int = int(SERVER_PORT) |
47 | 60 |
|
48 | | -AUTOEXIT: bool = bool(os.environ.get("NVIM_GHOST_AUTO_EXIT")) |
49 | | -NVIM_ADDRESSES = [FOCUSED_NVIM_ADDRESS] if FOCUSED_NVIM_ADDRESS is not None else [] |
50 | | - |
51 | 61 | # chdir to folder containing binary |
52 | 62 | # otherwise the logs are generated whereever the server was started from (i.e curdir) |
53 | 63 | # which..... isn't good. You'd have stdout.log and stderr.log files everywhere! |
|
0 commit comments