diff options
author | Johannes Rudolph <johannes.rudolph@gmx.com> | 2017-12-29 18:56:32 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2018-06-28 01:52:53 +0200 |
commit | 16e73b8157e1bd1929d0e78d1347be14ab894a8d (patch) | |
tree | bd82253eae2b1977d6521253c473ce92c9947177 /src/curses-ui/logo.vala | |
parent | 7effa097b0cb2878ef012aea71b6b013498538a7 (diff) | |
download | serial-barcode-scanner-16e73b8157e1bd1929d0e78d1347be14ab894a8d.tar.bz2 |
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.
Diffstat (limited to 'src/curses-ui/logo.vala')
-rw-r--r-- | src/curses-ui/logo.vala | 27 |
1 files changed, 20 insertions, 7 deletions
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(); |