コード例 #1
0
static void console_output(int fd, const char *text, gint length)
{
	static const char fd_colors[NFD] = { '6', '7', '1', '7', '5' };
	static char setaf[5] = { '\033', '[', '3', '?', 'm' };
	static int last_fd = -1;
	gint i;

	if (last_fd == 3 && fd != 0)
		vte_terminal_feed(debug_console, "\r\n", 2);

	if (fd != last_fd)
	{
		setaf[3] = fd_colors[fd];
		vte_terminal_feed(debug_console, setaf, sizeof(setaf));
		last_fd = fd;
	}

	if (length == -1)
		length = strlen(text);

	for (i = 0; i < length; i++)
	{
		if (text[i] == '\n')
		{
			vte_terminal_feed(debug_console, text, i);
			vte_terminal_feed(debug_console, "\r", 2);
			length -= i;
			text += i;
			i = 0;
		}
	}

	vte_terminal_feed(debug_console, text, length);
}
コード例 #2
0
void uart_write_data(unsigned int address,unsigned int val)
{
	unsigned char c = val & 0xff;
//	printf("UART TX: %02x\n",c);
	if (clientsockfd>0) {
		//write(clientsockfd, &c, 1);
		send(clientsockfd, &c, 1, 0);
	} else {
		uart_log(c);
		if (c=='\n')
			vte_terminal_feed(VTE_TERMINAL(vte),"\r",1);
		vte_terminal_feed(VTE_TERMINAL(vte),(char*)&c,1);

	}
}
コード例 #3
0
ファイル: controller.c プロジェクト: thiagoarrais/console
static void
console_controller_reprint_suffix(ConsoleController *ctrl)
{
	gchar *suffix, *suffix_cmd, *backspace;

	glong bksplen, avlen, suflen = 0;
	InputNode *cursor = ctrl->input_cursor->next;

	if (cursor) {
		avlen = ctrl->input_length + 1;
		suffix = (gchar*) g_slice_alloc(avlen * sizeof(gchar));
		while(cursor) {
			suffix[suflen++] = cursor->charData;
			cursor = cursor->next;
		}
		suffix[suflen] = '\0';

		bksplen = slice_sprintnum(&backspace, "\033[O\033[%dD\033[N", suflen);
		if (suflen + bksplen > avlen) {
			suffix_cmd = (gchar*) g_slice_alloc((suflen + bksplen) * sizeof(gchar));
			g_stpcpy(suffix_cmd, suffix);
		} else {
			suffix_cmd = suffix;
		}
		g_stpcpy(suffix_cmd + suflen, backspace);
	}

	if (suflen) {
		vte_terminal_feed(ctrl->terminal, suffix_cmd, suflen + bksplen);
		if (suffix_cmd != suffix) g_slice_free1((suflen + bksplen) * sizeof(gchar), suffix_cmd);
		g_slice_free1(avlen * sizeof(gchar), suffix);
		g_slice_free1(bksplen * sizeof(gchar), backspace);
	}
}
コード例 #4
0
ファイル: hotssh-tab.c プロジェクト: GNOME/hotssh
static void
on_istream_read_complete (GObject           *src,
			  GAsyncResult      *res,
			  gpointer           user_data)
{
  HotSshTab *self = user_data;
  HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
  gs_unref_bytes GBytes *result = NULL;
  GError *local_error = NULL;
  const guint8 *buf;
  gsize len;

  result = g_input_stream_read_bytes_finish ((GInputStream*)src, res, &local_error);
  if (!result)
    goto out;

  buf = g_bytes_get_data (result, &len);
  g_debug ("read %u bytes", (guint)len);
  
  vte_terminal_feed ((VteTerminal*)priv->terminal, (char*)buf, len);

  g_input_stream_read_bytes_async ((GInputStream*)src, 8192, G_PRIORITY_DEFAULT,
				   priv->cancellable, on_istream_read_complete, self);

 out:
  if (local_error)
    page_transition_take_error (self, local_error);
}
コード例 #5
0
ファイル: uimon.c プロジェクト: r-type/vice-libretro
void write_to_terminal(struct console_private_s *t,
                       const char *data,
                       glong length)
{
    if(t->term) {
        vte_terminal_feed(VTE_TERMINAL(t->term), data, length);
    }
}
コード例 #6
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void
console_controller_flush_pending_input(ConsoleController *ctrl)
{
	glong i, num_down_steps, cursor_position, num_columns;
	gchar *input_line, *cmd_step_down;
	InputNode *current_node;
	VteCommandHistoryNode *cmd;

	if (0 != ctrl->user_input_mode) return;

	input_line = (gchar*) g_slice_alloc((ctrl->input_length + 1) * sizeof(gchar));

	current_node = ctrl->input_head->next;
	i = cursor_position = 0;
	while(current_node) {
		if (current_node == ctrl->input_cursor) cursor_position = i;
		input_line[i++] = current_node->charData;
		current_node = current_node->next;
	}
	input_line[i] = '\0';

	num_columns = ctrl->terminal->column_count;
	num_down_steps =   (ctrl->prompt_length + ctrl->input_length) / num_columns
                         - (ctrl->prompt_length + cursor_position) / num_columns;
	if (num_down_steps > 0) {
		cmd_step_down = g_strnfill(num_down_steps, '\n');
		vte_terminal_feed(ctrl->terminal, "\033[O", 3);
		vte_terminal_feed(ctrl->terminal, cmd_step_down, num_down_steps);
		vte_terminal_feed(ctrl->terminal, "\033[N", 3);
		g_free(cmd_step_down);
	}

	cmd = g_slice_new0(VteCommandHistoryNode);
	if (ctrl->last_cmd) {
		ctrl->last_cmd->next = cmd;
		cmd->previous = ctrl->last_cmd;
	} else {
		cmd->previous = cmd;
	}
	cmd->data = input_line;
	ctrl->last_cmd = cmd;

	console_controller_emit_line_received(ctrl->terminal, input_line, ctrl->input_length);
	console_controller_reset_pending_input(ctrl);
}
コード例 #7
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void
console_controller_user_input(ConsoleController *ctrl, gchar *text)
{
	const int length = strlen(text);

	vte_terminal_feed(ctrl->terminal, text, length);
	console_controller_reprint_suffix(ctrl);
	console_controller_store_input(ctrl, text, length);
}
コード例 #8
0
void
ide_terminal_page_feed (IdeTerminalPage *self,
                        const gchar     *message)
{
  g_return_if_fail (IDE_IS_TERMINAL_PAGE (self));

  if (self->terminal_top != NULL)
    vte_terminal_feed (VTE_TERMINAL (self->terminal_top), message, -1);
}
コード例 #9
0
ファイル: controller.c プロジェクト: thiagoarrais/console
static void
console_controller_sprint_and_feed(ConsoleController *self, const gchar *format, const glong number)
{
	gchar *cmdstr;
	glong cmdlen;

	cmdlen = slice_sprintnum(&cmdstr, format, number);
	vte_terminal_feed(self->terminal, cmdstr, cmdlen);
	g_slice_free1(cmdlen * sizeof(gchar), cmdstr);
}
コード例 #10
0
ファイル: vte_wrap.c プロジェクト: Enide/Eclipse-Terminal
/*
 * Class:     com_randomwalking_swt_terminal_internal_Vte
 * Method:    _vte_terminal_feed
 * Signature: (ILjava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_com_randomwalking_swt_terminal_internal_Vte__1vte_1terminal_1feed
  (JNIEnv * env, jclass obj, jint terminal, jstring data) {
	if (data == NULL) {
		return;
	}
	const char * mdata = (*env)->GetStringUTFChars(env, data, NULL);

	vte_terminal_feed(VTE_TERMINAL(terminal), mdata, strlen(mdata));
	(*env)->ReleaseStringUTFChars(env, data, mdata);
}
コード例 #11
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void
console_controller_cursor_home(ConsoleController *ctrl)
{
	gchar *cmdstr;
	glong cmdlen;

	cmdlen = slice_sprintnum(&cmdstr, "\033[%dD", ctrl->input_cursor_position);
	vte_terminal_feed(ctrl->terminal, cmdstr, cmdlen);

	g_slice_free1(cmdlen * sizeof(gchar), cmdstr);
}
コード例 #12
0
ファイル: mud-subwindow.c プロジェクト: GNOME/gnome-mud
void
mud_subwindow_feed(MudSubwindow *self,
                   const gchar *data,
                   guint length)
{
    g_return_if_fail(MUD_IS_SUBWINDOW(self));

    vte_terminal_feed(VTE_TERMINAL(self->priv->terminal),
                      data,
                      length);
}
コード例 #13
0
ファイル: mssh-terminal.c プロジェクト: intelligenia/mssh
static void mssh_terminal_child_exited(VteTerminal *vte, gpointer data)
{
    char msg[] = "\r\n[Child Exited]\r\n";

    MSSHTerminal *terminal = MSSH_TERMINAL(data);

    terminal->ended = 1;

    vte_terminal_feed(vte, msg, strlen(msg));

    g_signal_emit_by_name(terminal, "session-closed");
}
コード例 #14
0
ファイル: main.c プロジェクト: ramarnat/astaro-strongswan
static void start_guest()
{
	page_t *page;

	page = get_page(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
	if (page && page->guest->get_state(page->guest) == GUEST_STOPPED)
	{
		vte_terminal_feed(VTE_TERMINAL(page->vte),
						  "--- starting guest ---\n\r", -1);
		page->guest->start(page->guest, invoke, VTE_TERMINAL(page->vte), idle);
	}
}
コード例 #15
0
ファイル: rbvte-terminal.c プロジェクト: benolee/ruby-gnome2
static VALUE
term_feed(VALUE self, VALUE data)
{
    glong length;

    length = RSTRING_LEN(data);

    if (length > 0) {
        vte_terminal_feed(RVAL2TERM(self), RSTRING_PTR(data), length);
    }

    return Qnil;
}
コード例 #16
0
ファイル: rbvteterminal.c プロジェクト: Vasfed/ruby-gnome2
static VALUE
rg_feed(VALUE self, VALUE data)
{
    glong length;

    length = RSTRING_LEN(data);

    if (length > 0) {
        vte_terminal_feed(_SELF(self), RSTRING_PTR(data), length);
    }

    return self;
}
コード例 #17
0
ファイル: uimon.c プロジェクト: bobsummerwill/VICE
void write_to_terminal(struct console_private_s *t,
                       const char *data,
                       glong length)
{
    if(t->term) {
        vte_terminal_feed(VTE_TERMINAL(t->term), data, length);
        /* this is a horrible hack to work around the fact VTE is not ment to be
           used like it is used here (no child process at all). flushing stdout
           here will make the initial prompt show up immediatly and not delay it
           until a key is pressed */
        fflush(stdout);
    }
}
コード例 #18
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void
console_controller_cursor_end(ConsoleController *ctrl)
{
	gchar *cmdstr;
	glong cmdlen, num_backsteps = ctrl->input_length - ctrl->input_cursor_position;

	if (0 == num_backsteps) return;

	cmdlen = slice_sprintnum(&cmdstr, "\033[%dC", num_backsteps);
	vte_terminal_feed(ctrl->terminal, cmdstr, cmdlen);

	g_slice_free1(cmdlen * sizeof(gchar), cmdstr);
}
コード例 #19
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void
console_controller_set_command_prompt(ConsoleController *ctrl, const gchar *text)
{
	glong old_prompt_length = ctrl->prompt_length;

	ctrl->prompt = g_strdup(text);
	ctrl->prompt_length = strlen(text);

	if (0 == ctrl->user_input_mode) {
		InputNode *current_node;
		gchar *user_input;
		glong i, inputlen;
		glong num_chars = ctrl->input_cursor_position + old_prompt_length;

		console_controller_sprint_and_feed(ctrl, "\033[O\033[%dD", num_chars);
		console_controller_sprint_and_feed(ctrl, "\033[%dP", num_chars);

		console_controller_print_command_prompt(ctrl);

		inputlen = ctrl->input_length + 1;
		user_input = (gchar*) g_slice_alloc(inputlen * sizeof(gchar));
		i = 0;
		current_node = ctrl->input_head;
		while(current_node) {
			user_input[i++] = current_node->charData;
			current_node = current_node->next;
		}
		user_input[i] = '\0';

		vte_terminal_feed(ctrl->terminal, user_input, inputlen);
		g_slice_free1(inputlen * sizeof(gchar), user_input);

		if (ctrl->input_length > ctrl->input_cursor_position)
			console_controller_sprint_and_feed(ctrl, "\033[%dD", ctrl->input_length - ctrl->input_cursor_position);

		vte_terminal_feed(ctrl->terminal, "\033[N", 3);
	}
}
コード例 #20
0
static void
debugger_log (IdeDebuggerEditorAddin *self,
              IdeDebuggerStream       stream,
              GBytes                 *content,
              IdeDebugger            *debugger)
{
  g_assert (IDE_IS_DEBUGGER_EDITOR_ADDIN (self));
  g_assert (IDE_IS_DEBUGGER_STREAM (stream));
  g_assert (content != NULL);
  g_assert (IDE_IS_DEBUGGER (debugger));

  if (stream == IDE_DEBUGGER_CONSOLE)
    {
      IdeLineReader reader;
      const gchar *str;
      gchar *line;
      gsize len;
      gsize line_len;

      str = g_bytes_get_data (content, &len);

      /*
       * Ingnore \n so we can add \r\n. Otherwise we get problematic
       * output in the terminal.
       */
      ide_line_reader_init (&reader, (gchar *)str, len);
      while (NULL != (line = ide_line_reader_next (&reader, &line_len)))
        {
          vte_terminal_feed (VTE_TERMINAL (self->log_view), line, line_len);

          if ((line + line_len) < (str + len))
            {
              if (line[line_len] == '\r' || line[line_len] == '\n')
                vte_terminal_feed (VTE_TERMINAL (self->log_view), "\r\n", 2);
            }
        }
    }
}
コード例 #21
0
ファイル: vteapp.c プロジェクト: MihirKulkarni/vte_indic
static gboolean
read_and_feed(GIOChannel *source, GIOCondition condition, gpointer data)
{
	char buf[2048];
	gsize size;
	GIOStatus status;
	g_assert(VTE_IS_TERMINAL(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);
		return TRUE;
	}
	return FALSE;
}
コード例 #22
0
ファイル: serial.c プロジェクト: reyesr/lcrt
/**
 * @brief the callback to read data from serial port and put the data to terminal.
 * @param user_data we use it to point to struct lcrt_terminal.
 * @param fd file descriptor of serial port.
 * @condition
 */
static void lcrt_serial_read(gpointer user_data, gint fd, GdkInputCondition condition)
{
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    int len = 0;
    unsigned char buffer[1024] = {0};    
    debug_where();
    len = read(fd, buffer, 1024);
    if (len <= 0) {
        /** serial device may be pull out  */
        if (errno == EAGAIN) {
            lcrt_serial_disconnect(lterminal);
            return;
        }
        return ;
    }
    vte_terminal_feed(VTE_TERMINAL(lterminal->terminal), (const char *)buffer, len);
}
コード例 #23
0
ファイル: main.c プロジェクト: ramarnat/astaro-strongswan
/**
 * handle guest termination, SIGCHILD
 */
static void child_exited(VteReaper *vtereaper, gint pid, gint status)
{
	enumerator_t *enumerator;
	page_t *page;

	enumerator = pages->create_enumerator(pages);
	while (enumerator->enumerate(enumerator, (void**)&page))
	{
		if (page->guest->get_pid(page->guest) == pid)
		{
			page->guest->sigchild(page->guest);
			vte_terminal_feed(VTE_TERMINAL(page->vte),
							  "\n\r--- guest terminated ---\n\r", -1);
			break;
		}
	}
	enumerator->destroy(enumerator);
}
コード例 #24
0
ファイル: main.c プロジェクト: ramarnat/astaro-strongswan
static void start_all_guests()
{
	enumerator_t *enumerator;
	page_t *page;

	enumerator = pages->create_enumerator(pages);
	while (enumerator->enumerate(enumerator, (void**)&page))
	{
		if (page->guest->get_state(page->guest) == GUEST_STOPPED)
		{
			vte_terminal_feed(VTE_TERMINAL(page->vte),
						  "--- starting all guests ---\n\r", -1);
			page->guest->start(page->guest, invoke,
							   VTE_TERMINAL(page->vte), idle);
		}
	}
	enumerator->destroy(enumerator);
}
コード例 #25
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void console_controller_delete_current_char(ConsoleController *ctrl)
{
	InputNode *deleted_node = ctrl->input_cursor->next;

	if (0 != ctrl->user_input_mode) return;

	if (deleted_node) {
		--ctrl->input_length;
		if (deleted_node->previous)
      			deleted_node->previous->next = deleted_node->next;
		if (deleted_node->next)
			deleted_node->next->previous = deleted_node->previous;

		vte_terminal_feed(ctrl->terminal, "\033[0J", 4);
		console_controller_reprint_suffix(ctrl);

		g_slice_free(InputNode, deleted_node);
	}
}
コード例 #26
0
ファイル: tilda_terminal.c プロジェクト: Kalabasa/tilda
static void child_exited_cb (GtkWidget *widget, gpointer data)
{
    DEBUG_FUNCTION ("child_exited_cb");
    DEBUG_ASSERT (widget != NULL);
    DEBUG_ASSERT (data != NULL);

    tilda_term *tt = TILDA_TERM(data);
    gint index = gtk_notebook_page_num (GTK_NOTEBOOK(tt->tw->notebook), tt->hbox);

    /* Make sure we got a valid index */
    if (index == -1)
    {
        DEBUG_ERROR ("Bad notebook tab\n");
        return;
    }

    /* These can stay here. They don't need to go into a header because
     * they are only used at this point in the code. */
    enum command_exit { DROP_TO_DEFAULT_SHELL, RESTART_COMMAND, EXIT_TERMINAL };

    /* Check the user's preference for what to do when the child terminal
     * is closed. Take the appropriate action */
    switch (config_getint ("command_exit"))
    {
        case EXIT_TERMINAL:
            tilda_window_close_tab (tt->tw, index, FALSE);
            break;
        case RESTART_COMMAND:
            vte_terminal_feed (VTE_TERMINAL(tt->vte_term), "\r\n\r\n", 4);
            start_shell (tt, FALSE, NULL);
            break;
        case DROP_TO_DEFAULT_SHELL:
            start_shell (tt, TRUE, NULL);
        default:
            break;
    }
}
コード例 #27
0
ファイル: controller.c プロジェクト: thiagoarrais/console
void
console_controller_print_command_prompt(ConsoleController *ctrl)
{
	if (0 == ctrl->user_input_mode)
		vte_terminal_feed(ctrl->terminal, ctrl->prompt, ctrl->prompt_length);
}
コード例 #28
0
ファイル: termit_core_api.c プロジェクト: wiget/termit
void termit_tab_feed(struct TermitTab* pTab, const gchar* data)
{
    vte_terminal_feed(VTE_TERMINAL(pTab->vte), data, strlen(data));
}
コード例 #29
0
ファイル: vteapp.c プロジェクト: MihirKulkarni/vte_indic
int
main(int argc, char **argv)
{
	GdkScreen *screen;
	GdkColormap *colormap;
	GtkWidget *window, *widget,*hbox = NULL, *scrollbar, *scrolled_window = NULL;
	VteTerminal *terminal;
	char *env_add[] = {
#ifdef VTE_DEBUG
		(char *) "FOO=BAR", (char *) "BOO=BIZ",
#endif
		NULL};
	const char *background = NULL;
	gboolean transparent = FALSE, audible = TRUE, blink = TRUE,
		 debug = FALSE, dingus = FALSE, dbuffer = TRUE,
		 console = FALSE, scroll = FALSE, keep = FALSE,
		 icon_title = FALSE, shell = TRUE, highlight_set = FALSE,
		 cursor_set = FALSE, reverse = FALSE, use_geometry_hints = TRUE,
		 antialias = TRUE, use_scrolled_window = FALSE,
                 show_object_notifications = FALSE;
        char *geometry = NULL;
	gint lines = 100;
	const char *message = "Launching interactive shell...\r\n";
	const char *font = NULL;
	const char *termcap = NULL;
	const char *command = NULL;
	const char *working_directory = NULL;
	const char *output_file = NULL;
        char *pty_flags_string = NULL;
        char *cursor_shape_string = NULL;
        char *scrollbar_policy_string = NULL;
	GdkColor fore, back, tint, highlight, cursor;
	const GOptionEntry options[]={
		{
			"antialias", 'A', G_OPTION_FLAG_REVERSE,
			G_OPTION_ARG_NONE, &antialias,
			"Disable the use of anti-aliasing", NULL
		},
		{
			"background", 'B', 0,
			G_OPTION_ARG_FILENAME, &background,
			"Specify a background image", NULL
		},
		{
			"console", 'C', 0,
			G_OPTION_ARG_NONE, &console,
			"Watch /dev/console", NULL
		},
		{
			"dingus", 'D', 0,
			G_OPTION_ARG_NONE, &dingus,
			"Highlight URLs inside the terminal", NULL
		},
		{
			"shell", 'S', G_OPTION_FLAG_REVERSE,
			G_OPTION_ARG_NONE, &shell,
			"Disable spawning a shell inside the terminal", NULL
		},
		{
			"transparent", 'T', 0,
			G_OPTION_ARG_NONE, &transparent,
			"Enable the use of a transparent background", NULL
		},
		{
			"double-buffer", '2', G_OPTION_FLAG_REVERSE,
			G_OPTION_ARG_NONE, &dbuffer,
			"Disable double-buffering", NULL
		},
		{
			"audible", 'a', G_OPTION_FLAG_REVERSE,
			G_OPTION_ARG_NONE, &audible,
			"Use visible, instead of audible, terminal bell",
			NULL
		},
		{
			"blink", 'b', G_OPTION_FLAG_REVERSE,
			G_OPTION_ARG_NONE, &blink,
			"Disable the blinking cursor", NULL
		},
		{
			"command", 'c', 0,
			G_OPTION_ARG_STRING, &command,
			"Execute a command in the terminal", NULL
		},
		{
			"debug", 'd', 0,
			G_OPTION_ARG_NONE, &debug,
			"Enable various debugging checks", NULL
		},
		{
			"font", 'f', 0,
			G_OPTION_ARG_STRING, &font,
			"Specify a font to use", NULL
		},
		{
			"geometry", 'g', 0,
			G_OPTION_ARG_STRING, &geometry,
			"Set the size (in characters) and position", "GEOMETRY"
		},
		{
			"highlight", 'h', 0,
			G_OPTION_ARG_NONE, &highlight_set,
			"Enable the cursor highlighting", NULL
		},
		{
			"icon-title", 'i', 0,
			G_OPTION_ARG_NONE, &icon_title,
			"Enable the setting of the icon title", NULL
		},
		{
			"keep", 'k', 0,
			G_OPTION_ARG_NONE, &keep,
			"Live on after the window closes", NULL
		},
		{
			"scrollback-lines", 'n', 0,
			G_OPTION_ARG_INT, &lines,
			"Specify the number of scrollback-lines", NULL
		},
		{
			"color-cursor", 'r', 0,
			G_OPTION_ARG_NONE, &cursor_set,
			"Enable a colored cursor", NULL
		},
		{
			"cursor-shape", 0, 0,
			G_OPTION_ARG_STRING, &cursor_shape_string,
			"Set cursor shape (block|underline|ibeam)", NULL
		},
		{
			"scroll-background", 's', 0,
			G_OPTION_ARG_NONE, &scroll,
			"Enable a scrolling background", NULL
		},
		{
			"termcap", 't', 0,
			G_OPTION_ARG_STRING, &termcap,
			"Specify the terminal emulation to use", NULL
		},
		{
			"working-directory", 'w', 0,
			G_OPTION_ARG_FILENAME, &working_directory,
			"Specify the initial working directory of the terminal",
			NULL
		},
		{
			"reverse", 0, 0,
			G_OPTION_ARG_NONE, &reverse,
			"Reverse foreground/background colors", NULL
		},
		{
			"no-geometry-hints", 'G', G_OPTION_FLAG_REVERSE,
			G_OPTION_ARG_NONE, &use_geometry_hints,
			"Allow the terminal to be resized to any dimension, not constrained to fit to an integer multiple of characters",
			NULL
		},
		{
			"scrolled-window", 'W', 0,
			G_OPTION_ARG_NONE, &use_scrolled_window,
			"Use a GtkScrolledWindow as terminal container",
			NULL
		},
		{
			"scrollbar-policy", 'P', 0,
			G_OPTION_ARG_STRING, &scrollbar_policy_string,
			"Set the policy for the vertical scroolbar in the scrolled window (always|auto|never; default:always)",
			NULL
		},
		{
			"object-notifications", 'N', 0,
			G_OPTION_ARG_NONE, &show_object_notifications,
			"Print VteTerminal object notifications",
			NULL
		},
		{
			"output-file", 0, 0,
			G_OPTION_ARG_STRING, &output_file,
			"Save terminal contents to file at exit", NULL
		},
		{
			"pty-flags", 0, 0,
			G_OPTION_ARG_STRING, &pty_flags_string,
			"PTY flags set from default|no-utmp|no-wtmp|no-lastlog|no-helper|no-fallback", NULL
		},
		{ NULL }
	};
	GOptionContext *context;
	GError *error = NULL;
        VteTerminalCursorShape cursor_shape = VTE_CURSOR_SHAPE_BLOCK;
        GtkPolicyType scrollbar_policy = GTK_POLICY_ALWAYS;
        VtePtyFlags pty_flags = VTE_PTY_DEFAULT;

	/* Have to do this early. */
	if (getenv("VTE_PROFILE_MEMORY")) {
		if (atol(getenv("VTE_PROFILE_MEMORY")) != 0) {
			g_mem_set_vtable(glib_mem_profiler_table);
		}
	}

	context = g_option_context_new (" - test VTE terminal emulation");
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, &error);
	g_option_context_free (context);
	if (error != NULL) {
		g_printerr ("Failed to parse command line arguments: %s\n",
				error->message);
		g_error_free (error);
		return 1;
	}

        if (cursor_shape_string) {
                cursor_shape = parse_enum(VTE_TYPE_TERMINAL_CURSOR_SHAPE, cursor_shape_string);
                g_free(cursor_shape_string);
        }
        if (scrollbar_policy_string) {
                scrollbar_policy = parse_enum(GTK_TYPE_POLICY_TYPE, scrollbar_policy_string);
                g_free(scrollbar_policy_string);
        }
        if (pty_flags_string) {
                pty_flags |= parse_flags(VTE_TYPE_PTY_FLAGS, pty_flags_string);
                g_free(pty_flags_string);
        }

	if (!reverse) {
		back.red = back.green = back.blue = 0xffff;
		fore.red = fore.green = fore.blue = 0x0000;
	} else {
		back.red = back.green = back.blue = 0x0000;
		fore.red = fore.green = fore.blue = 0xffff;
	}

	highlight.red = highlight.green = highlight.blue = 0xc000;
	cursor.red = 0xffff;
	cursor.green = cursor.blue = 0x8000;
	tint.red = tint.green = tint.blue = 0;
	tint = back;

	gdk_window_set_debug_updates(debug);

	/* Create a window to hold the scrolling shell, and hook its
	 * delete event to the quit function.. */
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_container_set_resize_mode(GTK_CONTAINER(window),
				      GTK_RESIZE_IMMEDIATE);

	/* Set ARGB colormap */
	screen = gtk_widget_get_screen (window);
	colormap = gdk_screen_get_rgba_colormap (screen);
	if (colormap)
	    gtk_widget_set_colormap(window, colormap);

        if (use_scrolled_window) {
                scrolled_window = gtk_scrolled_window_new (NULL, NULL);
                gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
                                               GTK_POLICY_NEVER, scrollbar_policy);
                gtk_container_add(GTK_CONTAINER(window), scrolled_window);
        } else {
                /* Create a box to hold everything. */
                hbox = gtk_hbox_new(0, FALSE);
                gtk_container_add(GTK_CONTAINER(window), hbox);
        }

	/* Create the terminal widget and add it to the scrolling shell. */
	widget = vte_terminal_new();
	terminal = VTE_TERMINAL (widget);
	if (!dbuffer) {
		gtk_widget_set_double_buffered(widget, dbuffer);
	}
        g_signal_connect(terminal, "child-exited", G_CALLBACK(child_exit_cb), NULL);
        if (show_object_notifications)
                g_signal_connect(terminal, "notify", G_CALLBACK(terminal_notify_cb), NULL);
        if (use_scrolled_window) {
                gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(terminal));
        } else {
                gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
        }

	/* Connect to the "char_size_changed" signal to set geometry hints
	 * whenever the font used by the terminal is changed. */
	if (use_geometry_hints) {
		char_size_changed(widget, 0, 0, window);
		g_signal_connect(widget, "char-size-changed",
				 G_CALLBACK(char_size_changed), window);
		g_signal_connect(widget, "realize",
				 G_CALLBACK(char_size_realized), window);
	}

	/* Connect to the "window_title_changed" signal to set the main
	 * window's title. */
	g_signal_connect(widget, "window-title-changed",
			 G_CALLBACK(window_title_changed), window);
	if (icon_title) {
		g_signal_connect(widget, "icon-title-changed",
				 G_CALLBACK(icon_title_changed), window);
	}

	/* Connect to the "status-line-changed" signal. */
	g_signal_connect(widget, "status-line-changed",
			 G_CALLBACK(status_line_changed), widget);

	/* Connect to the "button-press" event. */
	g_signal_connect(widget, "button-press-event",
			 G_CALLBACK(button_pressed), widget);

	/* Connect to application request signals. */
	g_signal_connect(widget, "iconify-window",
			 G_CALLBACK(iconify_window), window);
	g_signal_connect(widget, "deiconify-window",
			 G_CALLBACK(deiconify_window), window);
	g_signal_connect(widget, "raise-window",
			 G_CALLBACK(raise_window), window);
	g_signal_connect(widget, "lower-window",
			 G_CALLBACK(lower_window), window);
	g_signal_connect(widget, "maximize-window",
			 G_CALLBACK(maximize_window), window);
	g_signal_connect(widget, "restore-window",
			 G_CALLBACK(restore_window), window);
	g_signal_connect(widget, "refresh-window",
			 G_CALLBACK(refresh_window), window);
	g_signal_connect(widget, "resize-window",
			 G_CALLBACK(resize_window), window);
	g_signal_connect(widget, "move-window",
			 G_CALLBACK(move_window), window);

	/* Connect to font tweakage. */
	g_signal_connect(widget, "increase-font-size",
			 G_CALLBACK(increase_font_size), window);
	g_signal_connect(widget, "decrease-font-size",
			 G_CALLBACK(decrease_font_size), window);

        if (!use_scrolled_window) {
                /* Create the scrollbar for the widget. */
                scrollbar = gtk_vscrollbar_new(terminal->adjustment);
                gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0);
        }

	/* Set some defaults. */
	vte_terminal_set_audible_bell(terminal, audible);
	vte_terminal_set_visible_bell(terminal, !audible);
	vte_terminal_set_cursor_blink_mode(terminal, blink ? VTE_CURSOR_BLINK_SYSTEM : VTE_CURSOR_BLINK_OFF);
	vte_terminal_set_scroll_background(terminal, scroll);
	vte_terminal_set_scroll_on_output(terminal, FALSE);
	vte_terminal_set_scroll_on_keystroke(terminal, TRUE);
	vte_terminal_set_scrollback_lines(terminal, lines);
	vte_terminal_set_mouse_autohide(terminal, TRUE);
	if (background != NULL) {
		vte_terminal_set_background_image_file(terminal,
						       background);
	}
	if (transparent) {
		vte_terminal_set_background_transparent(terminal,
							TRUE);
	}
	vte_terminal_set_background_tint_color(terminal, &tint);
	vte_terminal_set_colors(terminal, &fore, &back, NULL, 0);
	vte_terminal_set_opacity(terminal, 0xdddd);
	if (highlight_set) {
		vte_terminal_set_color_highlight(terminal,
						 &highlight);
	}
	if (cursor_set) {
		vte_terminal_set_color_cursor(terminal, &cursor);
	}
	if (termcap != NULL) {
		vte_terminal_set_emulation(terminal, termcap);
	}
        vte_terminal_set_cursor_shape(terminal, cursor_shape);

	/* Set the default font. */
	vte_terminal_set_font_from_string_full(terminal, font,
					       antialias ? VTE_ANTI_ALIAS_USE_DEFAULT : VTE_ANTI_ALIAS_FORCE_DISABLE);

	/* Match "abcdefg". */
	if (dingus) {
		int id;
		GRegex *regex;
		regex = g_regex_new (DINGUS1, 0, 0, NULL);
		id = vte_terminal_match_add_gregex(terminal, regex, 0);
		g_regex_unref (regex);
		vte_terminal_match_set_cursor_type(terminal,
						   id, GDK_GUMBY);
		regex = g_regex_new (DINGUS2, 0, 0, NULL);
		id = vte_terminal_match_add_gregex(terminal, regex, 0);
		g_regex_unref (regex);
		vte_terminal_match_set_cursor_type(terminal,
						   id, GDK_HAND1);
	}

	if (console) {
		/* Open a "console" connection. */
		int consolefd = -1, yes = 1, watch;
		GIOChannel *channel;
		consolefd = open("/dev/console", O_RDONLY | O_NOCTTY);
		if (consolefd != -1) {
			/* Assume failure. */
			console = FALSE;
#ifdef TIOCCONS
			if (ioctl(consolefd, TIOCCONS, &yes) != -1) {
				/* Set up a listener. */
				channel = g_io_channel_unix_new(consolefd);
				watch = g_io_add_watch(channel,
						       G_IO_IN,
						       read_and_feed,
						       widget);
				g_signal_connect(widget,
						 "eof",
						 G_CALLBACK(disconnect_watch),
						 GINT_TO_POINTER(watch));
				g_signal_connect(widget,
						 "child-exited",
						 G_CALLBACK(disconnect_watch),
						 GINT_TO_POINTER(watch));
				g_signal_connect(widget,
						 "realize",
						 G_CALLBACK(take_xconsole_ownership),
						 NULL);
#ifdef VTE_DEBUG
				vte_terminal_feed(terminal,
						  "Console log for ...\r\n",
						  -1);
#endif
				/* Record success. */
				console = TRUE;
			}
#endif
		} else {
			/* Bail back to normal mode. */
			g_warning(_("Could not open console.\n"));
			close(consolefd);
			console = FALSE;
		}
	}

	if (!console) {
		if (shell) {
                        GError *err = NULL;
                        char **command_argv = NULL;
                        int command_argc;
                        GPid pid = -1;

			_VTE_DEBUG_IF(VTE_DEBUG_MISC)
				vte_terminal_feed(terminal, message, -1);

                        if (command == NULL)
                                command = "/bin/sh"; // FIXMEchpe

                        if (command != NULL) {
                                if (!g_shell_parse_argv(command, &command_argc, &command_argv, &err) ||
                                    !vte_terminal_fork_command_full(terminal,
                                                                    pty_flags,
                                                                    NULL,
                                                                    command_argv,
                                                                    env_add,
                                                                    G_SPAWN_SEARCH_PATH,
                                                                    NULL, NULL,
                                                                    &pid,
                                                                    &err)) {
                                        g_warning("Failed to fork: %s\n", err->message);
                                        g_error_free(err);
                                } else {
                                        g_print("Fork succeeded, PID %d\n", pid);
                                }
                        }
                        g_strfreev(command_argv);
	#ifdef VTE_DEBUG
			if (command == NULL) {
				vte_terminal_feed_child(terminal,
							"pwd\n", -1);
			}
	#endif
		} else {
			long i;
			i = vte_terminal_forkpty(terminal,
						 env_add, working_directory,
						 TRUE, TRUE, TRUE);
			switch (i) {
			case -1:
				/* abnormal */
				g_warning("Error in vte_terminal_forkpty(): %s",
					  strerror(errno));
				break;
			case 0:
				/* child */
				for (i = 0; ; i++) {
					switch (i % 3) {
					case 0:
					case 1:
						g_print("%ld\n", i);
						break;
					case 2:
						g_printerr("%ld\n", i);
						break;
					}
					sleep(1);
				}
				_exit(0);
				break;
			default:
				g_print("Child PID is %ld (mine is %ld).\n",
					(long) i, (long) getpid());
				/* normal */
				break;
			}
		}
	}

	g_object_set_data (G_OBJECT (widget), "output_file", (gpointer) output_file);

	/* Go for it! */
	g_signal_connect(widget, "child-exited", G_CALLBACK(child_exited), window);
	g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), widget);

	add_weak_pointer(G_OBJECT(widget), &widget);
	add_weak_pointer(G_OBJECT(window), &window);

        gtk_widget_realize(widget);
        if (geometry) {
                if (!gtk_window_parse_geometry (GTK_WINDOW(window), geometry)) {
                        g_warning (_("Could not parse the geometry spec passed to --geometry"));
                }
        }

	gtk_widget_show_all(window);

	gtk_main();

	g_assert(widget == NULL);
	g_assert(window == NULL);

	if (keep) {
		while (TRUE) {
			sleep(60);
		}
	}

	return 0;
}
コード例 #30
0
static void console_output_nl(int fd, const char *text, gint length)
{
	dc_output(fd, text, length);
	vte_terminal_feed(debug_console, "\r\n", 2);
}