aboutsummaryrefslogtreecommitdiffstats
path: root/ncurses_windows.c
diff options
context:
space:
mode:
authorEliteTK <tomasz.kramkowski@gmail.com>2015-06-19 19:12:12 +0100
committerEliteTK <tomasz.kramkowski@gmail.com>2015-06-19 19:12:12 +0100
commitda87fcf25e0c94e57f00df84679cd6fadc56ed46 (patch)
tree3c53eea9db01039990455af870a2ca65e7e5a123 /ncurses_windows.c
parent75d2e00662416224f4b745e0004f48f1fc1d9665 (diff)
parent7bf25fb8f0e4643a67894417a95d39e5901b1824 (diff)
downloadc-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.tar.gz
c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.tar.xz
c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.zip
Merge branch 'master' of https://github.com/EliteTK/c-stuff
Diffstat (limited to 'ncurses_windows.c')
-rw-r--r--ncurses_windows.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/ncurses_windows.c b/ncurses_windows.c
new file mode 100644
index 0000000..4a733ba
--- /dev/null
+++ b/ncurses_windows.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2015 Tomasz Kramkowski <tk@the-tk.com>
+ *
+ * This program is free software. It is licensed under version 3 of the
+ * GNU General Public License.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see [http://www.gnu.org/licenses/].
+ */
+// -*- compile-command: "make LDLIBS=-lncurses ncurses_windows" -*-
+#include <stdio.h>
+#include <stdlib.h>
+#include <ncurses.h>
+#include <unistd.h>
+
+#define WIDTH 20
+#define HEIGHT 10
+
+int main(void)
+{
+ WINDOW *box;
+ int c;
+
+ initscr();
+ cbreak();
+ noecho();
+ nonl();
+ intrflush(stdscr, FALSE);
+ keypad(stdscr, TRUE);
+ start_color();
+
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ init_pair(2, COLOR_WHITE, COLOR_RED);
+
+ box = derwin(stdscr, 10, 10, 10, 10);
+
+ bkgd(COLOR_PAIR(1));
+ wbkgd(box, COLOR_PAIR(2));
+
+ while ((c = getch()) != EOF) {
+ if (c == KEY_RESIZE) {
+ int x, y, width, height;
+
+ erase();
+
+ getmaxyx(stdscr, y, x);
+
+ width = x < WIDTH ? x : WIDTH;
+ height = y < HEIGHT ? y : HEIGHT;
+
+ wresize(box, height, width);
+
+ mvderwin(box, (y - height) / 2, (x - width) / 2);
+
+ bkgd(COLOR_PAIR(1));
+
+ wbkgd(box, COLOR_PAIR(2));
+
+ box(box, 0, 0);
+
+ refresh();
+ }
+ }
+
+ return EXIT_SUCCESS;
+}