Redo output logging in local.c. Optimise line drawing.

pull/1/head
Nicholas Marriott 2007-11-25 10:56:22 +00:00
parent 15511cb41a
commit 87b418b13e
2 changed files with 42 additions and 6 deletions

23
local.c
View File

@ -1,4 +1,4 @@
/* $Id: local.c,v 1.20 2007-11-24 23:29:49 nicm Exp $ */
/* $Id: local.c,v 1.21 2007-11-25 10:56:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <curses.h>
#include <fcntl.h>
@ -204,6 +205,7 @@ struct local_key local_keys[] = {
/* tty file descriptor and local terminal buffers. */
int local_fd;
int local_log;
struct buffer *local_in;
struct buffer *local_out;
struct termios local_tio;
@ -214,7 +216,8 @@ u_char local_colr;
int
local_init(struct buffer **in, struct buffer **out)
{
char *tty, *name;
char *tty, *path;
const char *name;
int mode, error;
struct termios tio;
struct local_key *lk;
@ -330,6 +333,14 @@ local_init(struct buffer **in, struct buffer **out)
local_attr = 0;
local_colr = 0x88;
if (debug_level > 2) {
xasprintf(
&path, "%s-output-%ld.log", __progname,(long) getpid());
local_log = open(
path, O_RDWR|O_APPEND|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
xfree(path);
}
return (local_fd);
}
@ -360,6 +371,9 @@ local_done(void)
if (tcsetattr(local_fd, TCSANOW, &local_tio) != 0)
fatal("tcsetattr failed");
close(local_fd);
if (local_log != -1)
close(local_log);
if (change_scroll_region != NULL) {
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
@ -388,6 +402,8 @@ local_putc(int c)
if (c < 0 || c > (int) UCHAR_MAX)
fatalx("invalid character");
if (local_log != -1)
write(local_log, &ch, 1);
if (acs_chars != NULL && local_attr & ATTR_DRAWING) {
ch = local_translate_acs(ch);
if (ch == '\0')
@ -640,7 +656,8 @@ local_attributes(u_char attr, u_char colr)
/* If any bits are being cleared, reset everything. */
if (local_attr & ~attr) {
if (exit_alt_charset_mode != NULL)
if ((local_attr & ATTR_DRAWING) &&
exit_alt_charset_mode != NULL)
local_putp(exit_alt_charset_mode);
local_putp(exit_attribute_mode);
local_colr = 0x88;

View File

@ -1,4 +1,4 @@
/* $Id: screen.c,v 1.44 2007-11-24 19:29:56 nicm Exp $ */
/* $Id: screen.c,v 1.45 2007-11-25 10:56:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -382,7 +382,15 @@ screen_draw_move(struct screen_draw_ctx *ctx, u_int px, u_int py)
if (px == ctx->cx && py == ctx->cy)
return;
input_store_two(ctx->b, CODE_CURSORMOVE, py + 1, px + 1);
if (px == 0 && py == ctx->cy)
input_store8(ctx->b, '\r');
else if (px == ctx->cx && py == ctx->cy + 1)
input_store8(ctx->b, '\n');
else if (px == 0 && py == ctx->cy + 1) {
input_store8(ctx->b, '\r');
input_store8(ctx->b, '\n');
} else
input_store_two(ctx->b, CODE_CURSORMOVE, py + 1, px + 1);
ctx->cx = px;
ctx->cy = py;
@ -444,7 +452,18 @@ screen_draw_column(struct screen_draw_ctx *ctx, u_int px)
void
screen_draw_line(struct screen_draw_ctx *ctx, u_int py)
{
screen_draw_cells(ctx, 0, py, screen_size_x(ctx->s));
u_int cx, cy;
cy = screen_y(ctx->s, py) - ctx->oy;
cx = ctx->s->grid_size[cy];
if (screen_size_x(ctx->s) < 3 || cx >= screen_size_x(ctx->s) - 3)
screen_draw_cells(ctx, 0, py, screen_size_x(ctx->s));
else {
screen_draw_cells(ctx, 0, py, cx);
screen_draw_move(ctx, cx, cy);
input_store_zero(ctx->b, CODE_CLEARENDOFLINE);
}
}
/* Draw set of lines. */