From 0a64877b1e75c787720fcb37b41394ce2101d27b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 21 Jun 2017 22:32:34 +1000 Subject: [PATCH] colors: Add error handling to reload --- wal | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/wal b/wal index 9c51cc4..a7264a1 100755 --- a/wal +++ b/wal @@ -498,17 +498,20 @@ def read_file(input_file): def reload_colors(vte): """Reload colors.""" - with open(CACHE_DIR / "sequences") as file: - sequences = file.read() + sequence_file = pathlib.Path(CACHE_DIR / "sequences") - # If vte mode was used, remove the problem sequence. - if vte: - sequences = re.sub(r"\]708;\#.{6}", "", sequences) + if sequence_file.is_file(): + with open(sequence_file, "r") as file: + sequences = file.read() - # Decode the string. - sequences = bytes(sequences, "utf-8").decode("unicode_escape") + # If vte mode was used, remove the problem sequence. + if vte: + sequences = re.sub(r"\]708;\#.{6}", "", sequences) + + # Decode the string. + sequences = bytes(sequences, "utf-8").decode("unicode_escape") + print(sequences, end="") - print(sequences, end="") quit()