From 133cf044c4afc64ce51b400e034fbd305cf4b766 Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Thu, 1 Dec 2022 12:19:32 -0800 Subject: [PATCH] console.print --- bin/cat.py | 4 ++-- bin/grep.py | 4 ++-- bin/ls.py | 6 +++--- bin/ps.py | 2 +- bin/pwd.py | 2 +- bin/sh.py | 6 ++---- lib/console.py | 3 +++ 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bin/cat.py b/bin/cat.py index 9144662..fc7b272 100644 --- a/bin/cat.py +++ b/bin/cat.py @@ -11,9 +11,9 @@ def get_app_class(template): except OSError as e: try: os.listdir(file) - console.write_str(self.console, f"cat: {file}: Is a directory\n") + console.print(self.console, f"cat: {file}: Is a directory") except OSError: - console.write_str(self.console, f"cat: {file}: No such file or directory\n") + console.print(self.console, f"cat: {file}: No such file or directory") self.exit() diff --git a/bin/grep.py b/bin/grep.py index f541134..be0006b 100644 --- a/bin/grep.py +++ b/bin/grep.py @@ -16,9 +16,9 @@ def get_app_class(template): except OSError as e: try: os.listdir(file) - console.write_str(self.console, f"grep: {file}: Is a directory\n") + console.print(self.console, f"grep: {file}: Is a directory") except OSError: - console.write_str(self.console, f"grep: {file}: No such file or directory\n") + console.print(self.console, f"grep: {file}: No such file or directory") self.exit() diff --git a/bin/ls.py b/bin/ls.py index 30e4545..02ba5b9 100644 --- a/bin/ls.py +++ b/bin/ls.py @@ -11,13 +11,13 @@ def get_app_class(template): try: for file in os.listdir(path): - console.write_str(self.console, file + "\n") + console.print(self.console, file) except OSError as e: try: os.stat(path) - console.write_str(self.console, path + "\n") + console.print(self.console, path) except OSError: - console.write_str(self.console, f"ls: cannot access '{path}': No such file or directory\n") + console.print(self.console, f"ls: cannot access '{path}': No such file or directory") self.exit() diff --git a/bin/ps.py b/bin/ps.py index 3fa7dca..84aa5e7 100644 --- a/bin/ps.py +++ b/bin/ps.py @@ -7,7 +7,7 @@ def get_app_class(template): for pid, app in apps.items(): args = app.argv[1:] name = app.name - console.write_str(self.console, f'{pid} {name} {args}\n') + console.print(self.console, f'{pid} {name} {args}') self.exit() return App diff --git a/bin/pwd.py b/bin/pwd.py index 7e19437..7211fa8 100644 --- a/bin/pwd.py +++ b/bin/pwd.py @@ -4,7 +4,7 @@ import console def get_app_class(template): class App(template): def F_main(self): - console.write_str(self.console, os.getcwd() + "\n") + console.print(self.console, os.getcwd()) self.exit() return App diff --git a/bin/sh.py b/bin/sh.py index baf23b4..925e250 100644 --- a/bin/sh.py +++ b/bin/sh.py @@ -8,7 +8,7 @@ def get_app_class(template): self.jump('prompt') def F_prompt(self): - self.console.write(b'FibonacciOS sh # ') + console.print(self.console, 'FibonacciOS sh # ', end="") self.store['buf'] = [] self.jump('input') @@ -29,9 +29,7 @@ def get_app_class(template): self.wait(pid) self.transfer_console(pid) except fibonaccios.exceptions.AppNotFound as e: - print('error: app not found') + console.print(self.console, 'error: app not found') self.jump('prompt') - def F_loop(self): - pass return App diff --git a/lib/console.py b/lib/console.py index c523898..fe41961 100644 --- a/lib/console.py +++ b/lib/console.py @@ -19,3 +19,6 @@ def read(console, buffer): def write_str(console, string, encoding="utf-8"): console.write(string.encode(encoding)) + +def print(console, *values, sep=" ", end="\n"): + write_str(console, sep.join(str(value) for value in values) + end)