After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 24457 - allow saving terminal content
allow saving terminal content
Status: RESOLVED FIXED
Product: gnome-terminal
Classification: Core
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: GNOME Terminal Maintainers
GNOME Terminal Maintainers
: 73272 91550 120583 349973 556791 (view as bug list)
Depends on:
Blocks: 94452
 
 
Reported: 2000-09-14 11:40 UTC by Frederic Detienne
Modified: 2014-09-22 15:08 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
add "save scrollback to file" (7.86 KB, patch)
2005-03-02 22:40 UTC, Mario Manno
none Details | Review
add accessor funtcion to vte (1.09 KB, patch)
2005-03-02 22:41 UTC, Mario Manno
none Details | Review
Updated patch with schema, rediff against current gnome cvs (9.16 KB, patch)
2006-01-09 14:08 UTC, Mario Manno
needs-work Details | Review
(Incomplete) Start of a logging patch (351.95 KB, patch)
2007-12-23 03:24 UTC, Harrison Metzger
needs-work Details | Review
save scrollback patch (5.87 KB, patch)
2008-09-12 00:09 UTC, Mario Manno
needs-work Details | Review
save terminals scrollback content (7.64 KB, patch)
2009-05-27 16:46 UTC, Mario Manno
needs-work Details | Review
save terminals scrollback content (7.87 KB, patch)
2009-06-02 15:49 UTC, Mario Manno
none Details | Review

Description Frederic Detienne 2001-01-27 20:18:10 UTC
Package:  gnome-terminal
Severity: normal
Version:  1.2.1
Synopsis: gnome-terminal should allow logging to a file
Class:    change-request

Distribution: Red Hat Linux release 6.0 (Hedwig)
System: Linux 2.4.0-test7 i686 unknown
C library: glibc-2.1.3-15
C compiler: egcs-2.91.66
glib: 1.2.8
GTK+: 1.2.8
ORBit: ORBit 0.5.3
gnome-libs: gnome-libs 1.2.4
libxml: 1.8.9
gnome-print: gnome-print-0.20
gnome-core: gnome-core 1.2.1


Description:
I regularly have to log what I am doing into a file. It is not always
possible/convenient to stop the telnet session and lanch tee.

(because you do not know in advance when you will need logging and you
can not log everything).

This used to be a much appreciated XTerm feature. It is very widely used
withinCisco.

Thanks.




------- Bug moved to this database by debbugs-export@bugzilla.gnome.org 2001-01-27 15:18 -------
This bug was previously known as bug 24457 at http://bugs.gnome.org/
http://bugs.gnome.org/show_bug.cgi?id=24457
Originally filed under the gnome-core product and gnome-terminal component.

Unknown version 1.2.x in product gnome-core. Setting version to the default, "unspecified".
The original reporter (fd@cisco.com) of this bug does not have an account here.
Reassigning to the exporter, debbugs-export@bugzilla.gnome.org.
Reassigning to the default owner of the component, gnome-core-maint@bugzilla.gnome.org.

Comment 1 Havoc Pennington 2002-02-14 02:50:43 UTC
Seems reasonable, but post-2.0 at this point due to release
engineering freeze
Comment 2 Havoc Pennington 2002-03-03 14:44:44 UTC
*** Bug 73272 has been marked as a duplicate of this bug. ***
Comment 3 Havoc Pennington 2002-03-03 14:49:39 UTC
#73272 points out that you want to be able to save to file in addition 
to preplanned logging.
Comment 4 Heath Harrelson 2002-11-08 19:22:29 UTC
*** Bug 91550 has been marked as a duplicate of this bug. ***
Comment 5 Mariano Suárez-Alvarez 2003-08-24 16:45:55 UTC
*** Bug 120583 has been marked as a duplicate of this bug. ***
Comment 6 Mariano Suárez-Alvarez 2003-08-24 16:48:31 UTC
Changing the version, as this is not yet there.
Comment 7 Bryan W Clark 2004-10-05 19:49:21 UTC
re-titling and creating 'gnome-terminal UI improvements dependency tree of doom!'
Comment 8 Mario Manno 2005-03-02 22:40:04 UTC
Created attachment 38173 [details] [review]
add "save scrollback to file"

Maybe this is a start.
Comment 9 Mario Manno 2005-03-02 22:41:17 UTC
Created attachment 38174 [details] [review]
add accessor funtcion to vte

Unfortunately I don't know how to get the current number of lines in the
scrollback without patching vte too.
Comment 10 Mario Manno 2006-01-09 14:08:03 UTC
Created attachment 57028 [details] [review]
Updated patch with schema, rediff against current gnome cvs

I have been using this patch for the last few month. I want to get rid of the need to patch vte for this one, but I have no idea how.
Comment 11 Olav Vitters 2006-08-04 21:14:16 UTC
*** Bug 349973 has been marked as a duplicate of this bug. ***
Comment 12 Mario Manno 2006-08-05 02:52:33 UTC
I created a separate bug for the vte dependency (#348342).
Comment 13 Mariano Suárez-Alvarez 2006-10-17 04:50:58 UTC
This patch takes saves what's in the terminal buffer. Wouldn't it be more useful to actually log the output of the child to a file? (together with the contents of the text buffer at the time the user decides to start logging, maybe?) Otherwise, it is quite hard to save long outputs, like the one produced by jhbuild, say. 

I have no idea what the UI for such a thing might look like.
Comment 14 Mario Manno 2006-10-17 08:39:38 UTC
If I know before that i need to log the output i would use the 'script' or 'tee' command. 

But most often something happened way back in the buffer which I need and this patch saves me from selecting a few thousand lines with the mouse and pasting them into a text file. 
Since there is no way to search the buffers content in g-t this comes in handy as a workaround, too.

Other times I need to store an important sessions output, like a filesystem check for example.

Adding realtime logging would be a different issue, since you know before that you want to log. How about adding a checkbox menuitem 'Log to file' which opens a filedialog to receive the logfile name and afterwards writes input/output to the file until unchecked?
Comment 15 Mario Manno 2006-11-02 19:40:25 UTC
(In reply to comment #14)

> Adding realtime logging would be a different issue, since you know before that
> you want to log. How about adding a checkbox menuitem 'Log to file' which opens
> a filedialog to receive the log file name and afterwards writes input/output to
> the file until unchecked?

Maybe someone with more experience could comment this, but isn't this a vte issue?
It's no problem to add another menu entry to g-t, but as far as i understand the api the real-time logging has to go into the vte widget, right?
Comment 16 Behdad Esfahbod 2006-11-02 20:09:54 UTC
(In reply to comment #15)
> (In reply to comment #14)
> 
> > Adding realtime logging would be a different issue, since you know before that
> > you want to log. How about adding a checkbox menuitem 'Log to file' which opens
> > a filedialog to receive the log file name and afterwards writes input/output to
> > the file until unchecked?
> 
> Maybe someone with more experience could comment this, but isn't this a vte
> issue?
> It's no problem to add another menu entry to g-t, but as far as i understand
> the api the real-time logging has to go into the vte widget, right?

I think vte emits enough signals that this can be entirely done in g-t. text-modified, text-inserted, text-deleted signals for example.
Comment 17 Mario Manno 2006-11-03 21:37:48 UTC
(In reply to comment #16)
> I think vte emits enough signals that this can be entirely done in g-t.
> text-modified, text-inserted, text-deleted signals for example.

Thanks, I hadn't thought about the accessibility api. These signals are used internally for communication with the accessibility peer.
So basically g-t has to register itself as a peer and use the atk api to write to a file?
Comment 18 Mario Manno 2006-11-04 14:47:20 UTC
I looked into atk and wrote a little test terminal. The desired events only get emitted if accessibility is enabled at log in. Maybe there is a way to enable them from gnome-terminal itself, but honestly this looks like a crude hack to me.

I'd say vte has to implement real time logging, unless there are any other ideas?

I don't need real time logging in g-t anyway, i would be happy if vte just implemented something like Bug 348342, which is a dependency for the scrollback save patch i attached.
Comment 19 Harrison Metzger 2007-12-18 03:38:56 UTC
The current patch (2006-01-09 14:08 UTC 9.16 KB) methodology seems to work, but a more sophisticated approach would be better. Have you ever used Trilian? (I used it for AIM back in my windows days - gosh its over now.) Each session would be logged automatically to files which had dates, or you could explicitly save a session.

I think a good idea is there will be a logging directory, some dot directory off the ~ directory. Each time one opens a tab, it would create a file with the name <current date>.log. (If desireible, instead of a flat logging directory, there would be a setting to have it log as <year>/<month>/<current date>.log). Every 64k (or what turns out to be an efficient buffer size) that is written on the terminal screen, the file would open and be appended. There would be an option such as "off the record" where any input or output would not be logged. I use tee sometimes to record the output of my command, but sometimes I like to know what I actually typed, so this logging method would record whats on the terminal screen (which is both input and output). There should be another switch to explicit log any keybord input so you can see where you hit <ctrl> + c, or any other key, or if you typed a password. (Of course, for security, this option probably should be off as its default state.) Finally, it should make a note of when a program like nano or vi is opened since you can't really save the "text" of that program.

I'd be happy to try and write this. But, I'm wondering if people think it is a good idea, or does anyone else want to write it so we don't waist each others' time? Let me know what you think.
Comment 20 Johannes Berg 2007-12-18 13:16:53 UTC
That logging directory would *definitely* have to be optional, otherwise I'd fill up my ~ directory ever so quickly with how much I work on the console and how often I type "dmesg" and stuff like that. And then, I think it'd be fairly useless because it'd have to default to *off* and people would only remember to turn it on when it's too late already...
Comment 21 Harrison Metzger 2007-12-18 17:19:25 UTC
Thats is true. I Imagine that I would fill up my ~ too. You could have three options: Log everything (described in my last post), Log session(s)/tab(s) if requested, absolutely no logging.

Log if requested: each open session/tab would write to a file (same way above off the ~), but if the user did not tell it to log this session, the log would be discarded on a successful exit gnome-terminal. This is good too in case something crashes, then you still have logs of what happened prior to the crash. This way, as long as you did not close the session its not "too late." Your dmesging or catting a log may get up to a few megs per session, but as soon as you exit (assuming you didnt specify to log it) will just be purged.
Comment 22 lsof 2007-12-19 19:35:23 UTC
Sorry to put a spanner in the works, but I myself only need one thing:
 save everything in the scrollback buffer to disk.

The alternative is a long slow laborious copy and paste.
Comment 23 Harrison Metzger 2007-12-23 03:24:34 UTC
Created attachment 101483 [details] [review]
(Incomplete) Start of a logging patch

This incomplete patch is to enabled logging for each terminal session. There are 2 logging modes: Enabled, and On Request. Enabled, will log everything as text comes out. On Request means that you have to click "Start Logging" to begin logging. On either method, you can choose to "Pause Logging" and "Resume Logging" (incase you have sensitive material or for any reason you choose). If you choose the On Request option, there is a sub option to log anyway, but unless you choose to keep the log, it will be discarded on exit. This is here for two reasons: 1) if you start something and later on decide you need it to be logged all you have to do his click "Keep log on exit". 2) If your system crashes, you have a log of the last thing that terminal was doing. 

This patch is incomplete. I'm wondering if anyone can offer suggestions or help with the code. The biggest problem is that It can't handle backspaces when you erase what you've typed, or alter text of already typed stuff. This code is in the terminal-screen.c file in the function terminal_screen_logging_ti_callback, which is a callback for "contents-changed" on a VteTerminal.
Comment 24 g11024342@trbvm.com 2008-09-11 13:10:35 UTC
Any chance this over 8 year old request can get done? This seems like a very basic function. Please consider adding it for future releases!

I have used konsole for a few years just because it can log your session. This can be used as a workaround.
Comment 25 Mario Manno 2008-09-12 00:09:16 UTC
Created attachment 118559 [details] [review]
save scrollback patch

Updated patch against r3036, no longer requires patched vte
Comment 26 Christian Persch 2008-10-18 18:43:08 UTC
*** Bug 556791 has been marked as a duplicate of this bug. ***
Comment 27 Jae Stutzman 2009-02-09 22:38:50 UTC
Any more news on this bug? It is sorely needed, patching it in everywhere is not ideal :)
Comment 28 Christian Persch 2009-05-26 20:00:52 UTC
Reviewing attachment 118559 [details] [review]:

+      { "FileSaveTab", GTK_STOCK_SAVE, N_("Save Tab"), "",
+        NULL,
+        G_CALLBACK (file_save_tab_callback) },

This doesn't very clearly express the purpose of this menu item; maybe "Save Terminal Text" or something...

+  if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)

No. Absolutely not. gtk_dialog_run() is not allowed in g-t. Just connect as response handler and show the dialogue, and do the work on response.

+    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

What about non-local files? Should use uri here, and use GIO to save the file.

       <separator />
+      <menuitem action="FileSaveTab" />
       <menuitem action="FileCloseTab" />

I wouldn't group this item with Close, they're unrelated and this just invites accidents.
Comment 29 Christian Persch 2009-05-26 20:04:23 UTC
About attachment 101483 [details] [review]:

Clearly doesn't apply, has too much code style issues and is too outdated to make it worth reviewing. I just want to note that it implements a different thing than attachment 118559 [details] [review], logging instead of just saving the text that's currently in the vteterminal's buffer. I think for logging, we should add API to vte to do this there, and just put the enabling code in g-t.
Comment 30 Mario Manno 2009-05-27 16:46:34 UTC
Created attachment 135449 [details] [review]
save terminals scrollback content

Thanks for the review. I hope this new patches fixes most issues. Is it ok to move the callback to terminal-utils.c?
Comment 31 Brad Landis 2009-05-27 20:42:29 UTC
+1 for getting this completed, and added to the current version of gnome if possible.
Comment 32 Christian Persch 2009-06-01 19:44:02 UTC
(In reply to comment #30)
> Created an attachment (id=135449) [edit]

+  if (filename_uri == NULL)
+      return;

wrong ident.

+  file = g_file_new_for_uri (filename_uri);
+  stream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL);
+  
+  if (stream != NULL)
+    g_output_stream_write (G_OUTPUT_STREAM (stream), terminal_text, strlen (terminal_text), NULL, NULL);
+  else
+    g_warning ("Could not write: %s\n", filename_uri);

Tell the use about it, I think, using terminal_util_show_error_dialog.

+  g_free(filename_uri);
+  g_free(terminal_text);

You're leaking the GFile, and the GFileOutputStream.

+  terminal_text = vte_terminal_get_text_range (VTE_TERMINAL (terminal),
+      0, 0,
+      row, col,
+      vte_terminal_always_selected,
+      NULL,
+      array);

As a follow-up bug for vte, maybe we should add some vte API that writes the text directly to a GOutputStream instead...

> Is it ok to
> move the callback to terminal-utils.c?

I think it's better to move this callback to where all the other action callbacks are, in terminal-window.c

+  dialog = gtk_file_chooser_dialog_new ( _("Save as..."),
+      NULL,

Don't pass NULL as parent, use the terminal window.

+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS));

Not sure this is the right dir...

+  g_signal_connect (dialog, "response", G_CALLBACK (terminal_util_save_term_text_cb), terminal);

What happens if the terminal closes before the dialogue is dismissed? I think in this case the dialogue should close too, and the dialogue should also be modal to the window.

+  g_signal_connect (dialog, "delete_event", G_CALLBACK (gtk_true), NULL);

Definitely not!
Comment 33 Mario Manno 2009-06-02 15:49:10 UTC
Created attachment 135821 [details] [review]
save terminals scrollback content

The file chooser is now a modal dialog.
Comment 34 Behdad Esfahbod 2009-06-02 20:49:40 UTC
Should we also add a "Save Selection"?
Comment 35 Christian Persch 2009-10-28 17:42:05 UTC
Yes.
Comment 36 Behdad Esfahbod 2010-01-14 01:28:06 UTC
Implemented vte api and the "Save Contents" menu item.
Comment 37 Victor Engmark 2012-08-30 13:55:59 UTC
Any news about which release this will be included in? It's been set as RESOLVED for almost three years.
Comment 38 Behdad Esfahbod 2012-08-30 14:11:19 UTC
Been in Fedora / Red Hat for over two years.
Comment 39 Christian Persch 2012-08-30 14:47:36 UTC
Actually, it's still disabled in stable releases (because of the sync issue).
Comment 40 Behdad Esfahbod 2012-08-30 14:49:05 UTC
Ah.  I think you should enable it.  Not going to fix itself magically, but it's not a huge deal either.
Comment 41 Bruce Korb 2014-02-03 17:32:02 UTC
Okay, so this bug (it is sufficiently deficient that it is a design bug) is *THIRTEEN YEARS OLD*, and was finally fixed *FOUR* years ago, but nobody can use the fix because it was rigged in a way that makes it *DISABLED* for normal users.  Closing the bug was premature.  Please re-open it until such time as there is a release that has this *CRUCIAL* feature enabled by default.  Thank you.
Comment 42 Behdad Esfahbod 2014-02-03 17:43:56 UTC
Shouting on bugzilla doesn't fix bugs.
Comment 43 lsof 2014-02-03 21:25:02 UTC
Looks like nothing else does either. You'll just rewrite it again and discard the bugs anyway.
Comment 44 Christian Persch 2014-02-17 22:04:31 UTC
Stop it.

I think I've made it clear previously that I consider fixing the sync issue a blocker to enabling this; I stand by that.
Comment 45 Bruce Korb 2014-02-18 01:52:06 UTC
The description might be edited to reference whatever the "sync issue" is.  (Is there a bug number for it? Your Comment #39 merely says, "Actually, it's still disabled in stable releases (because of the sync issue)." and is not very informative.)  This bug report shows up high in the Google results.  With the reference, folks could go sign up for that status.

Still, after 13 years, I'd sort of expect issues blocking critical functionality to get worked out.

Thank you for following up!
Comment 46 Behdad Esfahbod 2014-02-18 17:20:26 UTC
Christian.  The sync saving is definitely not worse than the fact that 1. we store history on disk, and 2. line rewrapping is sync also.  For a menu feature, I really don't think being sync should be an issue...  Definitely your decision though.
Comment 47 Stuart Axon 2014-09-22 15:08:50 UTC
Hi,
   Would it be possible to link to the bug for the sync issue, I'm curious to see what it actually entails.

I'm guessing in order to be able to try the feature + see what it's like with the sync issue, I should build an unstable build with jhbuild or similar?

Cheers
S