[gnome-builder] libide/terminal: add ide_terminal_page_new_completed()



commit 0ec0b2968caa56cf4d7a07a08df91385997bd7a1
Author: Christian Hergert <chergert redhat com>
Date:   Fri Sep 16 14:18:10 2022 -0700

    libide/terminal: add ide_terminal_page_new_completed()
    
    This is a convenience function to setup a new terminal page that is
    intended for display purposes only such as the contents of a previously
    run terminal (ie: previous application session).
    
    We want to keep the state around to be reused, but otherwise interacting
    with the terminal is not supported.

 src/libide/terminal/ide-terminal-page.c | 42 +++++++++++++++++++++++++++++++++
 src/libide/terminal/ide-terminal-page.h |  5 ++++
 2 files changed, 47 insertions(+)
---
diff --git a/src/libide/terminal/ide-terminal-page.c b/src/libide/terminal/ide-terminal-page.c
index 56f546d73..d51fed607 100644
--- a/src/libide/terminal/ide-terminal-page.c
+++ b/src/libide/terminal/ide-terminal-page.c
@@ -656,3 +656,45 @@ ide_terminal_page_get_terminal (IdeTerminalPage *self)
 
   return self->terminal;
 }
+
+IdeTerminalPage *
+ide_terminal_page_new_completed (const char *title,
+                                 const char *text,
+                                 int         columns,
+                                 int         rows)
+{
+  g_autofree char *copy = g_strdup (text);
+  IdeTerminalPage *self;
+  IdeLineReader reader;
+  char *line;
+  gsize line_len;
+
+  self = g_object_new (IDE_TYPE_TERMINAL_PAGE,
+                       "title", title,
+                       NULL);
+
+  vte_terminal_set_input_enabled (VTE_TERMINAL (self->terminal), FALSE);
+
+  self->close_on_exit = FALSE;
+  self->manage_spawn = FALSE;
+  g_clear_object (&self->launcher);
+  self->respawn_on_exit = FALSE;
+  self->exited = TRUE;
+
+  if (columns > 0 && rows > 0)
+    vte_terminal_set_size (VTE_TERMINAL (self->terminal), columns, rows);
+
+  ide_line_reader_init (&reader, copy, -1);
+  while ((line = ide_line_reader_next (&reader, &line_len)))
+    {
+      gboolean had_newline = line[line_len] != 0;
+
+      line[line_len] = 0;
+      ide_terminal_page_feed (self, line);
+
+      if (had_newline)
+        ide_terminal_page_feed (self, "\r\n");
+    }
+
+  return self;
+}
diff --git a/src/libide/terminal/ide-terminal-page.h b/src/libide/terminal/ide-terminal-page.h
index 371470ce8..954ddfd73 100644
--- a/src/libide/terminal/ide-terminal-page.h
+++ b/src/libide/terminal/ide-terminal-page.h
@@ -38,6 +38,11 @@ G_BEGIN_DECLS
 IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdeTerminalPage, ide_terminal_page, IDE, TERMINAL_PAGE, IdePage)
 
+IDE_AVAILABLE_IN_ALL
+IdeTerminalPage     *ide_terminal_page_new_completed             (const char          *title,
+                                                                  const char          *text,
+                                                                  int                  columns,
+                                                                  int                  rows);
 IDE_AVAILABLE_IN_ALL
 void                 ide_terminal_page_set_launcher              (IdeTerminalPage     *self,
                                                                   IdeTerminalLauncher *launcher);


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