From 16e73b8157e1bd1929d0e78d1347be14ab894a8d Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Fri, 29 Dec 2017 18:56:32 +0100 Subject: curses-ui: Load logo from file This loads the ASCII art logo shown in the curses UI from a file instead of having it hard-coded in the binary. --- README | 5 +++++ logo.txt | 6 ++++++ src/curses-ui/curses-ui.vala | 16 ++++++++-------- src/curses-ui/logo.vala | 27 ++++++++++++++++++++------- src/curses-ui/main.vala | 4 +++- 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 logo.txt diff --git a/README b/README index 29c498c..fdd141a 100644 --- a/README +++ b/README @@ -79,3 +79,8 @@ but you need to modify a few things. `sqlite3 shop.db "INSERT INTO users (id, email, firstname, lastname) VALUES (1, 'test@tester', 'Firstname', 'Lastname');"` * Setup user password `mdbus2 -s io.mainframe.shopsystem.Database /io/mainframe/shopsystem/database io.mainframe.shopsystem.Database.SetUserPassword 1 "password"` + +== Customize Your Shop == + +Edit the Logo in the logo.txt File. +A helpful tool you will found here [http://patorjk.com/software/taag/](http://patorjk.com/software/taag/) diff --git a/logo.txt b/logo.txt new file mode 100644 index 0000000..ee57aa1 --- /dev/null +++ b/logo.txt @@ -0,0 +1,6 @@ + _ ___ _____ ____ _ + | |/ / ||_ _| / ___|| |__ ___ _ __ + | ' /| __|| | \___ \| '_ \ / _ \| '_ \ + | . \| |_ | | ___) | | | | (_) | |_) ) + |_|\_\\__||_| |____/|_| |_|\___/| .__/ + |_| diff --git a/src/curses-ui/curses-ui.vala b/src/curses-ui/curses-ui.vala index ab34787..f7f6239 100644 --- a/src/curses-ui/curses-ui.vala +++ b/src/curses-ui/curses-ui.vala @@ -21,7 +21,7 @@ public class CursesUI { //StatusPanel statuswin; MessageBoxOverlay mbOverlay; - public CursesUI() { + public CursesUI(string binarylocation) { /* unicode support */ Intl.setlocale(LocaleCategory.CTYPE, ""); @@ -37,8 +37,8 @@ public class CursesUI { Curses.init_pair(1, Curses.Color.GREEN, Curses.Color.BLACK); Curses.init_pair(2, Curses.Color.WHITE, Curses.Color.RED); - /* initialize widgets */ - banner = new Logo(); + /* initialize widgets */ + banner = new Logo(binarylocation); //statuswin = new StatusPanel(); messages = new MessageBox(); clkwin = new ClockWindow(); @@ -68,18 +68,18 @@ public class CursesUI { //} public void log(MessageType type, string message) { - switch (type) { + switch (type) { case MessageType.WARNING: messages.add(message, MessageBox.WARN_COLOR); break; - case MessageType.ERROR: + case MessageType.ERROR: messages.add(message, MessageBox.ERROR_COLOR); break; default: messages.add(message, MessageBox.INFO_COLOR); break; } - + } public void log_overlay(string title, string message, int closeAfter) { @@ -87,7 +87,7 @@ public class CursesUI { Timeout.add_seconds(closeAfter, closeMbOverlay); } - public void dialog_open(string title, string message, int closeAfter=0) { + public void dialog_open(string title, string message, int closeAfter=0) { dialog = new Dialog(message, title, closeAfter); if (closeAfter > 0) { Timeout.add_seconds(closeAfter, close); @@ -102,7 +102,7 @@ public class CursesUI { return false; } - bool close() { + bool close() { dialog_close(); // just call me once return false; diff --git a/src/curses-ui/logo.vala b/src/curses-ui/logo.vala index dbc716d..c795981 100644 --- a/src/curses-ui/logo.vala +++ b/src/curses-ui/logo.vala @@ -18,17 +18,30 @@ using Curses; public class Logo { Window win; - public Logo() { + public Logo(string binarylocation) { win = new Window(8, COLS - 2, 0, 1); win.bkgdset(COLOR_PAIR(1) | Attribute.BOLD); win.addstr("\n"); - win.addstr(" _ ___ _____ ____ _ \n"); - win.addstr(" | |/ / ||_ _| / ___|| |__ ___ _ __ \n"); - win.addstr(" | ' /| __|| | \\___ \\| '_ \\ / _ \\| '_ \\ \n"); - win.addstr(" | . \\| |_ | | ___) | | | | (_) | |_) )\n"); - win.addstr(" |_|\\_\\\\__||_| |____/|_| |_|\\___/| .__/ \n"); - win.addstr(" |_| \n"); + + var file = File.new_for_path (binarylocation + "/../../logo.txt"); + + if (!file.query_exists ()) { + stderr.printf ("File '%s' doesn't exist.\n", file.get_path ()); + } + + try { + // Open file for reading and wrap returned FileInputStream into a + // DataInputStream, so we can read line by line + var dis = new DataInputStream (file.read ()); + string line; + // Read lines until end of file (null) is reached + while ((line = dis.read_line (null)) != null) { + win.addstr(line+"\n"); + } + } catch (Error e) { + error ("%s", e.message); + } win.clrtobot(); diff --git a/src/curses-ui/main.vala b/src/curses-ui/main.vala index da822a9..7020586 100644 --- a/src/curses-ui/main.vala +++ b/src/curses-ui/main.vala @@ -53,7 +53,9 @@ public static int main(string[] args) { error("IOError: %s\n", e.message); } - ui = new CursesUI(); + string binarylocation = File.new_for_path(args[0]).get_parent().get_path(); + + ui = new CursesUI(binarylocation); Log.set_default_handler(log_handler); -- cgit v1.2.3