[vte/vte-next: 137/223] Move methods to VteBuffer



commit a0cf3fe40a2c29aa34ce29410213e1d57110e6ab
Author: Christian Persch <chpe gnome org>
Date:   Thu Jun 9 23:21:34 2011 +0200

    Move methods to VteBuffer

 doc/reference/vte-sections.txt |    6 +-
 src/vte.c                      |  115 +++++++++++++++++++++++-----------------
 src/vte.h                      |    6 --
 src/vteapp.c                   |    6 +-
 src/vtebuffer.h                |   12 ++++
 src/vteseq.c                   |    5 ++
 6 files changed, 90 insertions(+), 60 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 71a4e37..73049da 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -11,9 +11,6 @@ VteSelectionFunc
 vte_terminal_new
 vte_terminal_get_buffer
 vte_terminal_im_append_menuitems
-vte_terminal_feed
-vte_terminal_feed_child
-vte_terminal_feed_child_binary
 vte_terminal_select_all
 vte_terminal_select_none
 vte_terminal_copy_clipboard
@@ -114,6 +111,9 @@ VteTerminalClassPrivate
 <TITLE>VteBuffer</TITLE>
 VteBuffer
 vte_buffer_new
+vte_buffer_feed
+vte_buffer_feed_child
+vte_buffer_feed_child_binary
 
 <SUBSECTION Standard>
 VTE_TYPE_BUFFER
diff --git a/src/vte.c b/src/vte.c
index d0b6973..cc6ecf2 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -3495,7 +3495,8 @@ _vte_terminal_enable_input_source (VteTerminal *terminal)
 	}
 }
 static void
-_vte_terminal_feed_chunks (VteTerminal *terminal, struct _vte_incoming_chunk *chunks)
+_vte_buffer_feed_chunks (VteBuffer *buffer,
+                         struct _vte_incoming_chunk *chunks)
 {
 	struct _vte_incoming_chunk *last;
 
@@ -3504,8 +3505,8 @@ _vte_terminal_feed_chunks (VteTerminal *terminal, struct _vte_incoming_chunk *ch
 			_vte_incoming_chunks_count(chunks));
 
 	for (last = chunks; last->next != NULL; last = last->next) ;
-	last->next = terminal->pvt->incoming;
-	terminal->pvt->incoming = chunks;
+	last->next = buffer->pvt->incoming;
+	buffer->pvt->incoming = chunks;
 }
 /* Read and handle data from the child. */
 static gboolean
@@ -3583,7 +3584,7 @@ out:
 		}
 
 		if (chunks != NULL) {
-			_vte_terminal_feed_chunks (terminal, chunks);
+			_vte_buffer_feed_chunks (terminal->term_pvt->buffer, chunks);
 		}
 		if (!vte_terminal_is_processing (terminal)) {
 			GDK_THREADS_ENTER ();
@@ -3635,32 +3636,38 @@ out:
 }
 
 /**
- * vte_terminal_feed:
- * @terminal: a #VteTerminal
- * @data: a string in the terminal's current encoding
- * @length: the length of the string
+ * vte_buffer_feed:
+ * @buffer: a #VteBuffer
+ * @data: (allow-none): a string in the buffer's current encoding
+ * @length: the length of the string, or <literal>-1</literal>
  *
  * Interprets @data as if it were data received from a child process.  This
- * can either be used to drive the terminal without a child process, or just
+ * can either be used to drive the buffer without a child process, or just
  * to mess with your users.
  */
 void
-vte_terminal_feed(VteTerminal *terminal, const char *data, glong length)
+vte_buffer_feed(VteBuffer *buffer,
+                const char *data,
+                gssize length)
 {
-	/* If length == -1, use the length of the data string. */
-	if (length == ((gssize)-1)) {
+        g_return_if_fail(VTE_IS_BUFFER(buffer));
+
+        if (data == NULL || length == 0)
+                return;
+
+	if (length < 0) {
 		length = strlen(data);
 	}
 
 	/* If we have data, modify the incoming buffer. */
 	if (length > 0) {
 		struct _vte_incoming_chunk *chunk;
-		if (terminal->pvt->incoming &&
-				(gsize)length < sizeof (terminal->pvt->incoming->data) - terminal->pvt->incoming->len) {
-			chunk = terminal->pvt->incoming;
+		if (buffer->pvt->incoming &&
+				(gsize)length < sizeof (buffer->pvt->incoming->data) - buffer->pvt->incoming->len) {
+			chunk = buffer->pvt->incoming;
 		} else {
 			chunk = get_chunk ();
-			_vte_terminal_feed_chunks (terminal, chunk);
+			_vte_buffer_feed_chunks (buffer, chunk);
 		}
 		do { /* break the incoming data into chunks */
 			gsize rem = sizeof (chunk->data) - chunk->len;
@@ -3674,9 +3681,9 @@ vte_terminal_feed(VteTerminal *terminal, const char *data, glong length)
 			data += len;
 
 			chunk = get_chunk ();
-			_vte_terminal_feed_chunks (terminal, chunk);
+			_vte_buffer_feed_chunks (buffer, chunk);
 		} while (1);
-		vte_terminal_start_processing (terminal);
+		vte_terminal_start_processing (buffer->pvt->terminal);
 	}
 }
 
@@ -3838,55 +3845,63 @@ vte_terminal_send(VteTerminal *terminal, const char *encoding,
 }
 
 /**
- * vte_terminal_feed_child:
- * @terminal: a #VteTerminal
- * @text: data to send to the child
+ * vte_buffer_feed_child:
+ * @buffer: a #VteBuffer
+ * @text: (allow-none): data to send to the child
  * @length: length of @text in bytes, or -1 if @text is NUL-terminated
  *
  * Sends a block of UTF-8 text to the child as if it were entered by the user
  * at the keyboard.
  */
 void
-vte_terminal_feed_child(VteTerminal *terminal, const char *text, glong length)
+vte_buffer_feed_child(VteBuffer *buffer,
+                      const char *text,
+                      gssize length)
 {
-	g_return_if_fail(VTE_IS_TERMINAL(terminal));
-	if (length == ((gssize)-1)) {
+        g_return_if_fail(VTE_IS_BUFFER(buffer));
+
+        if (text == NULL || length == 0)
+                return;
+
+	if (length < 0) {
 		length = strlen(text);
 	}
 	if (length > 0) {
-		vte_terminal_send(terminal, "UTF-8", text, length,
+		vte_terminal_send(buffer->pvt->terminal, "UTF-8", text, length,
 				  FALSE, FALSE);
 	}
 }
 
 /**
- * vte_terminal_feed_child_binary:
- * @terminal: a #VteTerminal
- * @data: data to send to the child
+ * vte_buffer_feed_child_binary:
+ * @buffer: a #VteBuffer
+ * @data: (allow-none) (array zero-terminated=0 lenght= length) (element-type uint8): data to send to the child
  * @length: length of @data
  *
  * Sends a block of binary data to the child.
- *
- * Since: 0.12.1
  */
 void
-vte_terminal_feed_child_binary(VteTerminal *terminal, const char *data, glong length)
+vte_buffer_feed_child_binary(VteBuffer *buffer,
+                             const char *data,
+                             gsize length)
 {
-	g_assert(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(VTE_IS_BUFFER(buffer));
+
+        if (data == NULL || length == 0)
+                return;
 
 	/* Tell observers that we're sending this to the child. */
 	if (length > 0) {
-		vte_buffer_emit_commit(terminal->term_pvt->buffer,
-					 data, length);
+		vte_buffer_emit_commit(buffer, data, length);
 
 		/* If there's a place for it to go, add the data to the
 		 * outgoing buffer. */
-		if (terminal->pvt->pty != NULL) {
-			_vte_byte_array_append(terminal->pvt->outgoing,
+		if (buffer->pvt->pty != NULL) {
+			_vte_byte_array_append(buffer->pvt->outgoing,
 					   data, length);
 			/* If we need to start waiting for the child pty to
 			 * become available for writing, set that up here. */
-			_vte_terminal_connect_pty_write(terminal);
+			_vte_terminal_connect_pty_write(buffer->pvt->terminal);
 		}
 	}
 }
@@ -4827,7 +4842,7 @@ vte_terminal_key_press(GtkWidget *widget, GdkEventKey *event)
 			    !suppress_meta_esc &&
 			    (normal_length > 0) &&
 			    (modifiers & VTE_META_MASK)) {
-				vte_terminal_feed_child(terminal,
+				vte_buffer_feed_child(terminal->term_pvt->buffer,
 							_VTE_CAP_ESC,
 							1);
 			}
@@ -5054,10 +5069,13 @@ vte_cell_is_selected(VteTerminal *terminal, glong col, glong row, gpointer data)
 static void
 vte_terminal_paste_cb(GtkClipboard *clipboard, const gchar *text, gpointer data)
 {
-	VteTerminal *terminal;
+	VteTerminal *terminal = data;
+        VteBuffer *buffer;
 	gchar *paste, *p;
 	long length;
-	terminal = data;
+
+        buffer = terminal->term_pvt->buffer;
+
 	if (text != NULL) {
 		_vte_debug_print(VTE_DEBUG_SELECTION,
 				"Pasting %"G_GSIZE_FORMAT" UTF-8 bytes.\n",
@@ -5080,10 +5098,10 @@ vte_terminal_paste_cb(GtkClipboard *clipboard, const gchar *text, gpointer data)
 			}
 		}
 		if (terminal->pvt->screen->bracketed_paste_mode)
-			vte_terminal_feed_child(terminal, "\e[200~", -1);
-		vte_terminal_feed_child(terminal, paste, length);
+			vte_buffer_feed_child(buffer, "\e[200~", -1);
+		vte_buffer_feed_child(buffer, paste, length);
 		if (terminal->pvt->screen->bracketed_paste_mode)
-			vte_terminal_feed_child(terminal, "\e[201~", -1);
+			vte_buffer_feed_child(buffer, "\e[201~", -1);
 		g_free(paste);
 	}
 }
@@ -5238,7 +5256,7 @@ vte_terminal_send_mouse_button_internal(VteTerminal *terminal,
 
 	/* Send event direct to the child, this is binary not text data */
 	len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
-	vte_terminal_feed_child_binary(terminal, buf, len);
+	vte_buffer_feed_child_binary(terminal->term_pvt->buffer, buf, len);
 }
 
 /* Send a mouse button click/release notification. */
@@ -5311,7 +5329,7 @@ vte_terminal_maybe_send_mouse_drag(VteTerminal *terminal, GdkEventMotion *event)
 
 	/* Send event direct to the child, this is binary not text data */
 	len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
-	vte_terminal_feed_child_binary(terminal, buf, len);
+	vte_buffer_feed_child_binary(terminal->term_pvt->buffer, buf, len);
 }
 
 /* Clear all match hilites. */
@@ -7515,6 +7533,7 @@ vte_terminal_get_emulation(VteTerminal *terminal)
 void
 _vte_terminal_inline_error_message(VteTerminal *terminal, const char *format, ...)
 {
+        VteBuffer *buffer = terminal->term_pvt->buffer;
 	va_list ap;
 	char *str;
 
@@ -7522,9 +7541,9 @@ _vte_terminal_inline_error_message(VteTerminal *terminal, const char *format, ..
 	str = g_strdup_vprintf (format, ap);
 	va_end (ap);
 
-	vte_terminal_feed (terminal, "*** VTE ***: ", 13);
-	vte_terminal_feed (terminal, str, -1);
-	vte_terminal_feed (terminal, "\r\n", 2);
+	vte_buffer_feed (buffer, "*** VTE ***: ", 13);
+	vte_buffer_feed (buffer, str, -1);
+	vte_buffer_feed (buffer, "\r\n", 2);
 	g_free (str);
 }
 
diff --git a/src/vte.h b/src/vte.h
index 7a4e4eb..b0a166d 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -230,12 +230,6 @@ gboolean vte_terminal_spawn_sync(VteTerminal *terminal,
                                  GCancellable *cancellable,
                                  GError **error);
 
-/* Send data to the terminal to display, or to the terminal's forked command
- * to handle in some way.  If it's 'cat', they should be the same. */
-void vte_terminal_feed(VteTerminal *terminal, const char *data, glong length);
-void vte_terminal_feed_child(VteTerminal *terminal, const char *text, glong length);
-void vte_terminal_feed_child_binary(VteTerminal *terminal, const char *data, glong length);
-
 /* Copy currently-selected text to the clipboard, or from the clipboard to
  * the terminal. */
 void vte_terminal_copy_clipboard(VteTerminal *terminal);
diff --git a/src/vteapp.c b/src/vteapp.c
index 4bbf50b..8e32e89 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -407,7 +407,7 @@ read_and_feed(GIOChannel *source, GIOCondition condition, gpointer data)
 	status = g_io_channel_read_chars(source, buf, sizeof(buf),
 					 &size, NULL);
 	if ((status == G_IO_STATUS_NORMAL) && (size > 0)) {
-		vte_terminal_feed(VTE_TERMINAL(data), buf, size);
+		vte_buffer_feed(vte_terminal_get_buffer(VTE_TERMINAL(data)), buf, size);
 		return TRUE;
 	}
 	return FALSE;
@@ -1067,7 +1067,7 @@ main(int argc, char **argv)
 						 G_CALLBACK(take_xconsole_ownership),
 						 NULL);
 #ifdef VTE_DEBUG
-				vte_terminal_feed(terminal,
+				vte_buffer_feed(vte_terminal_get_buffer(terminal),
 						  "Console log for ...\r\n",
 						  -1);
 #endif
@@ -1091,7 +1091,7 @@ main(int argc, char **argv)
 			GPid pid = -1;
 
 			_VTE_DEBUG_IF(VTE_DEBUG_MISC)
-				vte_terminal_feed(terminal, message, -1);
+				vte_buffer_feed(vte_terminal_get_buffer(terminal), message, -1);
 
                         if (command == NULL || *command == '\0')
                                 command = vte_get_user_shell ();
diff --git a/src/vtebuffer.h b/src/vtebuffer.h
index d4554ef..e7ea33c 100644
--- a/src/vtebuffer.h
+++ b/src/vtebuffer.h
@@ -62,6 +62,18 @@ GType vte_buffer_get_type (void);
 
 VteBuffer *vte_buffer_new (void);
 
+void vte_buffer_feed                    (VteBuffer *buffer,
+                                         const char *data,
+                                         gssize length);
+
+void vte_buffer_feed_child              (VteBuffer *buffer,
+                                         const char *text,
+                                         gssize length);
+
+void vte_buffer_feed_child_binary       (VteBuffer *buffer,
+                                         const char *data,
+                                         gsize length);
+
 G_END_DECLS
 
 #endif /* VTE_BUFFER_H */
diff --git a/src/vteseq.c b/src/vteseq.c
index 99d25d4..596cede 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -32,6 +32,11 @@
 
 #define BEL "\007"
 
+/* FIXMEchpe hackery remove later */
+static inline void vte_terminal_feed_child(VteTerminal *terminal, const char *data, gssize len)
+{
+        vte_buffer_feed_child(terminal->term_pvt->buffer, data, len);
+}
 
 
 /* FUNCTIONS WE USE */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]