From bcf096569172422064b14d43cfcf2aa0b0cb9422 Mon Sep 17 00:00:00 2001 From: Miguel Guthridge Date: Sun, 7 Apr 2024 23:52:11 +1000 Subject: [PATCH] Handle server exit when running server-side repl --- flapi/cli/repl.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/flapi/cli/repl.py b/flapi/cli/repl.py index 0cd55d7..8045200 100644 --- a/flapi/cli/repl.py +++ b/flapi/cli/repl.py @@ -7,6 +7,7 @@ import code import click import sys +import os import time import random from typing import Optional @@ -22,6 +23,7 @@ fl_print, ) from flapi import _consts as consts +from flapi.errors import FlapiServerExit from flapi.cli import consts as cli_consts from .util import handle_verbose try: @@ -78,7 +80,9 @@ def ellipsis(delta: float) -> str: end='\r', ) - print("Connected to FL Studio") + # Yucky thing to ensure that we write all the way to the end of the line + msg = "Connected to FL Studio" + print(msg + ' ' * (os.get_terminal_size().columns - len(msg))) return True @@ -118,6 +122,12 @@ def exec_lines(lines: list[str]) -> bool: else: res = fl_eval(source) print(repr(res)) + except FlapiServerExit: + print( + "Error: the Flapi server exited, likely because FL Studio was " + "closed." + ) + exit(1) except Exception: print_exc()