[PATCH] Added the capability to capture history to capture-pane command.

2011-03-30 Thread Raghavendra D Prabhu

Hi,
I have been wanting the capability to capture the history and store
store it to a file much akin to save-buffer. While checking the sources,
I noticed that it had been noticed in TODO to be added with -h to
capture-pane. So I have implemented it. I have also tested it myself.

%<%<--


Adding -h to capture-pane now captures history of that pane.

Signed-off-by: Raghavendra D Prabhu 
---
 cmd-capture-pane.c |   50 --
 1 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c
index a2c2fdd..1ed0bb3 100644
--- a/cmd-capture-pane.c
+++ b/cmd-capture-pane.c
@@ -31,8 +31,8 @@ int   cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
 
 const struct cmd_entry cmd_capture_pane_entry = {

"capture-pane", "capturep",
-   "b:t:", 0, 0,
-   "[-b buffer-index] [-t target-pane]",
+   "b:t:h", 0, 0,
+   "[-b buffer-index] [-t target-pane] [-h capture-history]",
0,
NULL,
NULL,
@@ -47,8 +47,9 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
char*buf, *line, *cause;
struct screen   *s;
int  buffer;
-   u_inti, limit;
-   size_t   len, linelen;
+   u_inti, j, limit;
+   size_t   len, linelen, cellsize;
+   struct grid* gd;
 
 	if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)

return (-1);
@@ -57,16 +58,37 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
buf = NULL;
len = 0;
 
-	for (i = 0; i < screen_size_y(s); i++) {

-  line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
-  linelen = strlen(line);
-
-  buf = xrealloc(buf, 1, len + linelen + 1);
-  memcpy(buf + len, line, linelen);
-  len += linelen;
-  buf[len++] = '\n';
-
-  xfree(line);
+   if (!args_has(args, 'h')) {
+  for (i = 0; i < screen_size_y(s); i++) {
+   line = grid_view_string_cells(s->grid, 0, i, 
screen_size_x(s));
+   linelen = strlen(line);
+
+   buf = xrealloc(buf, 1, len + linelen + 1);
+   memcpy(buf + len, line, linelen);
+   len += linelen;
+   buf[len++] = '\n';
+
+   xfree(line);
+   }
+   } else  {
+   gd = s->grid;
+   line = NULL;
+   // Looping over the previous history + viewable text
+   for (i = 0; i < gd->hsize + gd->sy; i++) {
+   cellsize = gd->linedata[i].cellsize;
+   line = xrealloc(line,1,cellsize+1);
+   for (j = 0; j < cellsize; j++) {
+   line[j] = 
gd->linedata[i].celldata[j].data;
+   }
+   line[cellsize]='\0';
+
+   buf = xrealloc(buf, 1, len + cellsize + 1);
+   memcpy(buf + len, line, cellsize);
+   len += cellsize;
+   buf[len++] = '\n';
+
+   }
+   xfree(line);
}
 
 	limit = options_get_number(&global_options, "buffer-limit");

--
1.7.4.2

--
Raghavendra Prabhu
GPG ID:D72BE977



pgphDl6R3RErJ.pgp
Description: PGP signature
--
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
___
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users


Re: [PATCH] Added the capability to capture history to capture-pane command.

2011-03-30 Thread Nicholas Marriott
Hi

Thanks, but I'm afraid I already did this a few days ago by giving
capture-pane start and end line arguments (it is in OpenBSD I don't
think it has made it to SF yet).


On Thu, Mar 31, 2011 at 01:15:13AM +0530, Raghavendra D Prabhu wrote:
> Hi,
> I have been wanting the capability to capture the history and store
> store it to a file much akin to save-buffer. While checking the sources,
> I noticed that it had been noticed in TODO to be added with -h to
> capture-pane. So I have implemented it. I have also tested it myself.
> 
> %<%<--
> 
> 
> Adding -h to capture-pane now captures history of that pane.
> 
> Signed-off-by: Raghavendra D Prabhu 
> ---
>  cmd-capture-pane.c |   50 --
>  1 files changed, 36 insertions(+), 14 deletions(-)
> 
> diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c
> index a2c2fdd..1ed0bb3 100644
> --- a/cmd-capture-pane.c
> +++ b/cmd-capture-pane.c
> @@ -31,8 +31,8 @@ int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
>  const struct cmd_entry cmd_capture_pane_entry = {
>   "capture-pane", "capturep",
> - "b:t:", 0, 0,
> - "[-b buffer-index] [-t target-pane]",
> + "b:t:h", 0, 0,
> + "[-b buffer-index] [-t target-pane] [-h capture-history]",
>   0,
>   NULL,
>   NULL,
> @@ -47,8 +47,9 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
>   char*buf, *line, *cause;
>   struct screen   *s;
>   int  buffer;
> - u_inti, limit;
> - size_t   len, linelen;
> + u_inti, j, limit;
> + size_t   len, linelen, cellsize;
> + struct grid* gd;
>   if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
>   return (-1);
> @@ -57,16 +58,37 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>   buf = NULL;
>   len = 0;
> - for (i = 0; i < screen_size_y(s); i++) {
> -line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
> -linelen = strlen(line);
> -
> -buf = xrealloc(buf, 1, len + linelen + 1);
> -memcpy(buf + len, line, linelen);
> -len += linelen;
> -buf[len++] = '\n';
> -
> -xfree(line);
> + if (!args_has(args, 'h')) {
> +for (i = 0; i < screen_size_y(s); i++) {
> + line = grid_view_string_cells(s->grid, 0, i, 
> screen_size_x(s));
> + linelen = strlen(line);
> +
> + buf = xrealloc(buf, 1, len + linelen + 1);
> + memcpy(buf + len, line, linelen);
> + len += linelen;
> + buf[len++] = '\n';
> +
> + xfree(line);
> + }
> + } else  {
> + gd = s->grid;
> + line = NULL;
> + // Looping over the previous history + viewable text
> + for (i = 0; i < gd->hsize + gd->sy; i++) {
> + cellsize = gd->linedata[i].cellsize;
> + line = xrealloc(line,1,cellsize+1);
> + for (j = 0; j < cellsize; j++) {
> + line[j] = 
> gd->linedata[i].celldata[j].data;
> + }
> + line[cellsize]='\0';
> +
> + buf = xrealloc(buf, 1, len + cellsize + 1);
> + memcpy(buf + len, line, cellsize);
> + len += cellsize;
> + buf[len++] = '\n';
> +
> + }
> + xfree(line);
>   }
>   limit = options_get_number(&global_options, "buffer-limit");
> -- 
> 1.7.4.2
> 
> --
> Raghavendra Prabhu
> GPG ID:D72BE977
> 



--
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
___
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users