aboutsummaryrefslogtreecommitdiff
path: root/demo-glib.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-09-23 01:38:08 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-09-23 03:05:01 +0200
commitb630bf7a5f5ec85317db04f770ffc90664ac28f0 (patch)
tree52a0f40045809e71bc6fcac40d52e570f2fb2b59 /demo-glib.c
parent7909067ac05e885211dafa255da0526543bb87bf (diff)
downloadtermo-b630bf7a5f5ec85317db04f770ffc90664ac28f0.tar.gz
termo-b630bf7a5f5ec85317db04f770ffc90664ac28f0.tar.xz
termo-b630bf7a5f5ec85317db04f770ffc90664ac28f0.zip
WIP: Is mine now (^3^)
Seriously though, I've got some issues with how this thing is designed, as well as with its formatting, and when you add the fact that the original author wants to merge this thing into his bigger library that also handles terminal output, which I'll kindly leave to ncurses, it kind of makes sense for me to do this. Manpages have been removed as they are going to become obsolete and they're rather difficult to maintain. If anything, there will be Doxygen-generated documentation. The plan is to throw away any direct UTF-8 support and support all uni- and multibyte character encodings. However some unrelated refactoring is about to come first.
Diffstat (limited to 'demo-glib.c')
-rw-r--r--demo-glib.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/demo-glib.c b/demo-glib.c
index 7dc8d87..00f5aa2 100644
--- a/demo-glib.c
+++ b/demo-glib.c
@@ -3,63 +3,63 @@
#include "termkey.h"
-static TermKey *tk;
+static termkey_t *tk;
static int timeout_id;
-static void on_key(TermKey *tk, TermKeyKey *key)
+static void
+on_key (termkey_t *tk, termkey_key_t *key)
{
- char buffer[50];
- termkey_strfkey(tk, buffer, sizeof buffer, key, TERMKEY_FORMAT_VIM);
- printf("%s\n", buffer);
+ char buffer[50];
+ termkey_strfkey (tk, buffer, sizeof buffer, key, TERMKEY_FORMAT_VIM);
+ printf ("%s\n", buffer);
}
-static gboolean key_timer(gpointer data)
+static gboolean
+key_timer (gpointer data)
{
- TermKeyKey key;
-
- if(termkey_getkey_force(tk, &key) == TERMKEY_RES_KEY)
- on_key(tk, &key);
-
- return FALSE;
+ termkey_key_t key;
+ if (termkey_getkey_force (tk, &key) == TERMKEY_RES_KEY)
+ on_key (tk, &key);
+ return FALSE;
}
-static gboolean stdin_io(GIOChannel *source, GIOCondition condition, gpointer data)
+static gboolean
+stdin_io (GIOChannel *source, GIOCondition condition, gpointer data)
{
- if(condition && G_IO_IN) {
- if(timeout_id)
- g_source_remove(timeout_id);
+ if (condition && G_IO_IN)
+ {
+ if (timeout_id)
+ g_source_remove (timeout_id);
- termkey_advisereadable(tk);
+ termkey_advisereadable (tk);
- TermKeyResult ret;
- TermKeyKey key;
- while((ret = termkey_getkey(tk, &key)) == TERMKEY_RES_KEY) {
- on_key(tk, &key);
- }
+ termkey_result_t ret;
+ termkey_key_t key;
+ while ((ret = termkey_getkey (tk, &key)) == TERMKEY_RES_KEY)
+ on_key (tk, &key);
- if(ret == TERMKEY_RES_AGAIN)
- timeout_id = g_timeout_add(termkey_get_waittime(tk), key_timer, NULL);
- }
+ if (ret == TERMKEY_RES_AGAIN)
+ timeout_id = g_timeout_add
+ (termkey_get_waittime (tk), key_timer, NULL);
+ }
- return TRUE;
+ return TRUE;
}
-int main(int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
- TERMKEY_CHECK_VERSION;
-
- tk = termkey_new(0, 0);
-
- if(!tk) {
- fprintf(stderr, "Cannot allocate termkey instance\n");
- exit(1);
- }
-
- GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-
- g_io_add_watch(g_io_channel_unix_new(0), G_IO_IN, stdin_io, NULL);
-
- g_main_loop_run(loop);
-
- termkey_destroy(tk);
+ TERMKEY_CHECK_VERSION;
+
+ tk = termkey_new (0, 0);
+ if (!tk)
+ {
+ fprintf (stderr, "Cannot allocate termkey instance\n");
+ exit (1);
+ }
+
+ GMainLoop *loop = g_main_loop_new (NULL, FALSE);
+ g_io_add_watch (g_io_channel_unix_new (0), G_IO_IN, stdin_io, NULL);
+ g_main_loop_run (loop);
+ termkey_destroy (tk);
}