summaryrefslogtreecommitdiffstats
path: root/input.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-10-09 21:22:16 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-10-09 21:22:16 +0000
commit185f7297e8df1399094b7e3d1314f1af1e94e633 (patch)
tree55326e854032c0a967701d2ad7be6677f8cc9e71 /input.c
parent23e7da1ccb63d2cb9bea945060c6f5158e73d967 (diff)
Better OSC support for title setting, and support APC as well.
Diffstat (limited to 'input.c')
-rw-r--r--input.c100
1 files changed, 42 insertions, 58 deletions
diff --git a/input.c b/input.c
index e5e854c0..8df09c38 100644
--- a/input.c
+++ b/input.c
@@ -1,4 +1,4 @@
-/* $Id: input.c,v 1.62 2008-09-26 07:41:01 nicm Exp $ */
+/* $Id: input.c,v 1.63 2008-10-09 21:22:16 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -48,9 +48,6 @@ void input_state(struct input_ctx *, void *);
void input_state_first(u_char, struct input_ctx *);
void input_state_escape(u_char, struct input_ctx *);
void input_state_intermediate(u_char, struct input_ctx *);
-void input_state_title_first(u_char, struct input_ctx *);
-void input_state_title_second(u_char, struct input_ctx *);
-void input_state_title_next(u_char, struct input_ctx *);
void input_state_sequence_first(u_char, struct input_ctx *);
void input_state_sequence_next(u_char, struct input_ctx *);
void input_state_sequence_intermediate(u_char, struct input_ctx *);
@@ -261,9 +258,13 @@ input_state_first(u_char ch, struct input_ctx *ictx)
ch -= 0x40;
if (ch == '[')
input_state(ictx, input_state_sequence_first);
- else if (ch == ']')
- input_state(ictx, input_state_title_first);
- else
+ else if (ch == ']') {
+ input_start_string(ictx, STRING_SYSTEM);
+ input_state(ictx, input_state_string_next);
+ } else if (ch == '_') {
+ input_start_string(ictx, STRING_APPLICATION);
+ input_state(ictx, input_state_string_next);
+ } else
input_handle_c1_control(ch, ictx);
return;
}
@@ -301,9 +302,13 @@ input_state_escape(u_char ch, struct input_ctx *ictx)
if (INPUT_UPPERCASE(ch)) {
if (ch == '[')
input_state(ictx, input_state_sequence_first);
- else if (ch == ']')
- input_state(ictx, input_state_title_first);
- else {
+ else if (ch == ']') {
+ input_start_string(ictx, STRING_SYSTEM);
+ input_state(ictx, input_state_string_next);
+ } else if (ch == '_') {
+ input_start_string(ictx, STRING_APPLICATION);
+ input_state(ictx, input_state_string_next);
+ } else {
input_state(ictx, input_state_first);
input_handle_c1_control(ch, ictx);
}
@@ -320,53 +325,6 @@ input_state_escape(u_char ch, struct input_ctx *ictx)
}
void
-input_state_title_first(u_char ch, struct input_ctx *ictx)
-{
- if (ch >= '0' && ch <= '9') {
- if (ch == '0')
- input_start_string(ictx, STRING_TITLE);
- else
- input_start_string(ictx, STRING_IGNORE);
- input_state(ictx, input_state_title_second);
- return;
- }
-
- input_state(ictx, input_state_first);
-}
-
-void
-input_state_title_second(u_char ch, struct input_ctx *ictx)
-{
- if (ch == ';') {
- input_state(ictx, input_state_title_next);
- return;
- }
-
- input_state(ictx, input_state_first);
-}
-
-void
-input_state_title_next(u_char ch, struct input_ctx *ictx)
-{
- if (ch == '\007') {
- if (ictx->string_type == STRING_TITLE)
- screen_set_title(ictx->ctx.s, input_get_string(ictx));
- else
- input_abort_string(ictx);
- input_state(ictx, input_state_first);
- return;
- }
-
- if (ch >= 0x20 && ch != 0x7f) {
- if (input_add_string(ictx, ch) != 0)
- input_state(ictx, input_state_first);
- return;
- }
-
- input_state(ictx, input_state_first);
-}
-
-void
input_state_intermediate(u_char ch, struct input_ctx *ictx)
{
if (INPUT_INTERMEDIATE(ch))
@@ -467,6 +425,10 @@ input_state_string_next(u_char ch, struct input_ctx *ictx)
input_state(ictx, input_state_string_escape);
return;
}
+ if (ch == 0x07) {
+ input_state_string_escape(ch, ictx);
+ return;
+ }
if (ch >= 0x20 && ch != 0x7f) {
if (input_add_string(ictx, ch) != 0)
@@ -478,10 +440,32 @@ input_state_string_next(u_char ch, struct input_ctx *ictx)
void
input_state_string_escape(u_char ch, struct input_ctx *ictx)
{
- if (ch == '\\') {
+ char *s;
+
+ if (ch == '\007' || ch == '\\') {
input_state(ictx, input_state_first);
switch (ictx->string_type) {
+ case STRING_SYSTEM:
+ if (ch != '\007')
+ return;
+ s = input_get_string(ictx);
+ if ((s[0] != '0' && s[0] != '2') || s[1] != ';') {
+ xfree(s);
+ return;
+ }
+ screen_set_title(ictx->ctx.s, s + 2);
+ xfree(s);
+ break;
+ case STRING_APPLICATION:
+ if (ch != '\\')
+ return;
+ s = input_get_string(ictx);
+ screen_set_title(ictx->ctx.s, s);
+ xfree(s);
+ break;
case STRING_NAME:
+ if (ch != '\\')
+ return;
xfree(ictx->w->name);
ictx->w->name = input_get_string(ictx);
server_status_window(ictx->w);