summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--src/main.vala6
-rw-r--r--src/ui/clock.vala61
-rw-r--r--src/ui/curses-ui.vala68
-rw-r--r--src/ui/dialog.vala36
-rw-r--r--src/ui/logo.vala30
-rw-r--r--src/ui/message_box.vala45
-rw-r--r--src/ui/numbers.vala98
-rw-r--r--src/ui/status.vala24
9 files changed, 369 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 0102716..80b6fdb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-SRC=src/main.vala src/device.vala src/scannersession.vala src/db.vala src/audio.vala src/web.vala src/graph-data.vala src/template.vala src/websession.vala src/admin.vala src/price.vapi
-DEPS=--pkg posix --pkg linux --pkg libsoup-2.4 --pkg sqlite3 --pkg gee-1.0 --pkg gio-2.0 --pkg gstreamer-0.10 --pkg libarchive --pkg gpgme
+SRC=src/main.vala src/device.vala src/scannersession.vala src/db.vala src/audio.vala src/web.vala src/graph-data.vala src/template.vala src/websession.vala src/admin.vala src/price.vapi src/ui/*.vala
+DEPS=--pkg posix --pkg linux --pkg libsoup-2.4 --pkg sqlite3 --pkg gee-1.0 --pkg gio-2.0 --pkg gstreamer-0.10 --pkg libarchive --pkg gpgme --pkg curses -X -lcurses
FLAGS=-X -lgpgme -X -w --enable-experimental --thread --vapidir=vapi
barcode-scanner: $(SRC)
diff --git a/src/main.vala b/src/main.vala
index 82fe238..4a14cdf 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -21,6 +21,7 @@ public ScannerSession localsession;
public MainLoop loop;
public PGPKeyArchive pgp;
public KeyFile cfg;
+public CursesUI ui;
const OptionEntry[] option_entries = {
{ "version", 'v', OptionFlags.IN_MAIN, OptionArg.NONE, ref opt_version, "output version information and exit", null },
@@ -80,6 +81,8 @@ public static int main(string[] args) {
dev.blink(10);
});
+ ui = new CursesUI();
+
while(!check_valid_time()) {
write_to_log("Invalid System Time! Retry in 1 minute...");
Posix.sleep(60);
@@ -105,6 +108,7 @@ public static int main(string[] args) {
dev = null;
db = null;
audio = null;
+ ui.exit();
return 0;
}
@@ -117,7 +121,7 @@ public void write_to_log(string format, ...) {
var arguments = va_list();
var message = format.vprintf(arguments);
- stdout.printf(message + "\n");
+ ui.log(message);
}
bool handle_signals() {
diff --git a/src/ui/clock.vala b/src/ui/clock.vala
new file mode 100644
index 0000000..e38ad9c
--- /dev/null
+++ b/src/ui/clock.vala
@@ -0,0 +1,61 @@
+using Curses;
+
+public class ClockWindow {
+ AsciiNumbers ascii;
+ Window win;
+
+ public ClockWindow() {
+ ascii = new AsciiNumbers();
+ win = new Window(6, 18, 1, COLS-2-18);
+ win.bkgdset(COLOR_PAIR(0) | Attribute.BOLD);
+
+ win.clrtobot();
+ win.box(0, 0);
+
+ win.refresh();
+ }
+
+ public void update() {
+ string[] x;
+ var now = new DateTime.now_local();
+
+ x = ascii.get('0' + (char) (now.get_hour() / 10));
+ win.mvaddstr(1,1, x[0]);
+ win.mvaddstr(2,1, x[1]);
+ win.mvaddstr(3,1, x[2]);
+
+ x = ascii.get('0' + (char) (now.get_hour() % 10));
+ win.mvaddstr(1,4, x[0]);
+ win.mvaddstr(2,4, x[1]);
+ win.mvaddstr(3,4, x[2]);
+
+ x = ascii.get(':');
+ win.mvaddstr(1,7, x[0]);
+ win.mvaddstr(2,7, x[1]);
+ win.mvaddstr(3,7, x[2]);
+
+ x = ascii.get('0' + (char) (now.get_minute() / 10));
+ win.mvaddstr(1,10, x[0]);
+ win.mvaddstr(2,10, x[1]);
+ win.mvaddstr(3,10, x[2]);
+
+ x = ascii.get('0' + (char) (now.get_minute() % 10));
+ win.mvaddstr(1,13, x[0]);
+ win.mvaddstr(2,13, x[1]);
+ win.mvaddstr(3,13, x[2]);
+
+
+ win.clrtobot();
+ win.box(0, 0);
+
+ win.mvaddstr(5,4, now.format("%Y-%m-%d"));
+
+ win.refresh();
+ }
+
+ public void redraw() {
+ win.touchwin();
+ win.refresh();
+ }
+
+}
diff --git a/src/ui/curses-ui.vala b/src/ui/curses-ui.vala
new file mode 100644
index 0000000..6676eea
--- /dev/null
+++ b/src/ui/curses-ui.vala
@@ -0,0 +1,68 @@
+public class CursesUI {
+ MessageBox messages;
+ Dialog dialog;
+ Logo banner;
+ ClockWindow clkwin;
+ StatusPanel statuswin;
+
+ public CursesUI() {
+ /* unicode support */
+ Intl.setlocale(LocaleCategory.CTYPE, "");
+
+ /* initialize curses */
+ Curses.initscr();
+
+ /* disable cursor */
+ Curses.curs_set(0);
+
+ /* initialize color mode and define color pairs */
+ Curses.start_color();
+ Curses.init_pair(0, Curses.Color.WHITE, Curses.Color.BLACK);
+ 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();
+ statuswin = new StatusPanel();
+ messages = new MessageBox();
+ clkwin = new ClockWindow();
+
+ clkwin.update();
+
+ Timeout.add_seconds(10, update_time);
+ }
+
+ ~CursesUI() {
+ exit();
+ }
+
+ public void exit() {
+ /* Reset the terminal mode */
+ Curses.endwin();
+ }
+
+ bool update_time() {
+ clkwin.update();
+ return true;
+ }
+
+ public void status(string message) {
+ statuswin.set(message);
+ }
+
+ public void log(string message) {
+ messages.add(message);
+ }
+
+ public void dialog_open(string title, string message) {
+ dialog = new Dialog(message, title);
+ }
+
+ public void dialog_close() {
+ dialog = null;
+ messages.redraw();
+ banner.redraw();
+ clkwin.redraw();
+ statuswin.redraw();
+ }
+}
diff --git a/src/ui/dialog.vala b/src/ui/dialog.vala
new file mode 100644
index 0000000..29782e5
--- /dev/null
+++ b/src/ui/dialog.vala
@@ -0,0 +1,36 @@
+using Curses;
+
+public class Dialog {
+ Window win;
+ Window subwin;
+
+ public Dialog(string message, string title = "KtT Shopsystem Error", int h=16, int w=60)
+ requires (title.length <= w-4)
+ {
+ int y = LINES/2-h/2;
+ int x = COLS/2-w/2;
+
+ int title_x = (w-title.length)/2;
+
+ win = new Window(h, w, y, x);
+
+ /* make the dialog white on red */
+ win.bkgdset(COLOR_PAIR(2) | Attribute.BOLD);
+ win.clrtobot();
+
+ /* message subwindow */
+ subwin = win.derwin(h-4, w-4, 2, 2);
+ subwin.clrtobot();
+ subwin.printw(message);
+ subwin.refresh();
+
+ /* dialog title */
+ win.box(0,0);
+ win.mvaddstr(0, title_x, title);
+ win.mvaddch(0, title_x-2, Acs.RTEE);
+ win.mvaddch(0, title_x-1, ' ');
+ win.mvaddch(0, title_x+title.length, ' ');
+ win.mvaddch(0, title_x+title.length+1, Acs.LTEE);
+ win.refresh();
+ }
+}
diff --git a/src/ui/logo.vala b/src/ui/logo.vala
new file mode 100644
index 0000000..46fbaf7
--- /dev/null
+++ b/src/ui/logo.vala
@@ -0,0 +1,30 @@
+using Curses;
+
+public class Logo {
+ Window win;
+
+ public Logo() {
+ 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");
+
+ win.clrtobot();
+
+ win.box(0, 0);
+
+ win.refresh();
+ }
+
+ public void redraw() {
+ win.touchwin();
+ win.refresh();
+ }
+
+}
diff --git a/src/ui/message_box.vala b/src/ui/message_box.vala
new file mode 100644
index 0000000..4f9c3f6
--- /dev/null
+++ b/src/ui/message_box.vala
@@ -0,0 +1,45 @@
+using Curses;
+
+public class MessageBox {
+ Window win;
+ Window subwin;
+ DateTime last;
+
+ public MessageBox() {
+ win = new Window(LINES-9, COLS - 2, 8, 1);
+ win.bkgdset(COLOR_PAIR(0));
+
+ win.clrtobot();
+ win.box(0, 0);
+ win.refresh();
+
+ subwin = win.derwin(LINES-11, COLS-4, 1, 1);
+ subwin.scrollok(true);
+ subwin.clrtobot();
+ subwin.refresh();
+
+ last = new DateTime.from_unix_utc(0);
+ }
+
+ public void add(string msg) {
+ var now = new DateTime.now_local();
+
+ if(now.get_day_of_year() != last.get_day_of_year() || now.get_year() != last.get_year()) {
+ string curtime = now.format("%Y-%m-%d");
+ subwin.addstr("\nDate Changed: " + curtime);
+ }
+
+ last = now;
+
+ string curtime = now.format("%H:%M:%S");
+ subwin.addstr("\n[" + curtime + "] " + msg);
+ subwin.refresh();
+ }
+
+ public void redraw() {
+ win.touchwin();
+ win.refresh();
+ subwin.touchwin();
+ subwin.refresh();
+ }
+}
diff --git a/src/ui/numbers.vala b/src/ui/numbers.vala
new file mode 100644
index 0000000..8ee00d5
--- /dev/null
+++ b/src/ui/numbers.vala
@@ -0,0 +1,98 @@
+public class AsciiNumbers {
+
+ public string[] zero = {
+ " _ ",
+ "/ \\",
+ "\\_/"
+ };
+
+ public string[] one = {
+ " ",
+ " /|",
+ " |"
+ };
+
+ public string[] two = {
+ "__ ",
+ " _)",
+ "(__"
+ };
+
+ public string[] three = {
+ "__ ",
+ " _)",
+ "__)"
+ };
+
+ public string[] four = {
+ " ",
+ "|_|",
+ " |"
+ };
+
+ public string[] five = {
+ " __",
+ "|_ ",
+ "__)"
+ };
+
+ public string[] six = {
+ " _ ",
+ "/_ ",
+ "\\_)"
+ };
+
+ public string[] seven = {
+ "___",
+ " /",
+ " / "
+ };
+
+ public string[] eight = {
+ " _ ",
+ "(_)",
+ "(_)"
+ };
+
+ public string[] nine = {
+ " _ ",
+ "(_\\",
+ " _/"
+ };
+
+ public string[] colon = {
+ " ",
+ " o ",
+ " o "
+ };
+
+ public string[] get(char c) {
+ switch(c) {
+ case '0':
+ return zero;
+ case '1':
+ return one;
+ case '2':
+ return two;
+ case '3':
+ return three;
+ case '4':
+ return four;
+ case '5':
+ return five;
+ case '6':
+ return six;
+ case '7':
+ return seven;
+ case '8':
+ return eight;
+ case '9':
+ return nine;
+ case ':':
+ return colon;
+ default:
+ return {};
+ }
+ }
+
+}
diff --git a/src/ui/status.vala b/src/ui/status.vala
new file mode 100644
index 0000000..db33820
--- /dev/null
+++ b/src/ui/status.vala
@@ -0,0 +1,24 @@
+using Curses;
+
+public class StatusPanel {
+ Window win;
+
+ public StatusPanel() {
+ win = new Window(1, COLS - 2, LINES-1, 1);
+ win.bkgdset(COLOR_PAIR(2) | Attribute.BOLD);
+
+ win.clrtobot();
+ win.refresh();
+ }
+
+ public void set(string msg) {
+ win.mvaddstr(0,1, msg);
+ win.clrtobot();
+ win.refresh();
+ }
+
+ public void redraw() {
+ win.touchwin();
+ win.refresh();
+ }
+}