示例#1
0
文件: xxx.c 项目: lexuszhi1990/hen
static void report(const char *msg, ...)
{
    static bool empty = TRUE;
    struct view *view = display[current_view];
    enum line_type type;
    if (!empty || *msg) {
        va_list args;

        va_start(args, msg);

        werase(status_win);
        wmove(status_win, 0, 0);
        if (*msg) {
            vwprintw(status_win, msg, args);
            empty = false;
        } else{
            empty = TRUE;
        }
        wrefresh(status_win);

        va_end(args);
    }
    update_title_win(view);
    
    if (view->lines) {
        wmove(view->win, view->lineno - view->offset, view->width - 1);
        wrefresh(view->win);
    } 
}
示例#2
0
文件: xxx.c 项目: yaomoon/GT2440
static void report(const char *msg, ...)
{
    static bool empty = TRUE;
    struct view *view = display[current_view];
    if (!empty || *msg) {
        va_list args;

        va_start(args, msg);

        werase(status_win);
        wmove(status_win, 0, 0);
        if (*msg) {
            vwprintw(status_win, msg, args);
            empty = false;
        } else{
            empty = TRUE;
        }
        wrefresh(status_win);

        va_end(args);
    }
#ifdef yaomoon
fprintf(moon_log,"927: report\n");
#endif
    update_title_win(view);
    
    if (view->lines) {
        wmove(view->win, view->lineno - view->offset, view->width - 1);
        wrefresh(view->win);
    } 
#ifdef yaomoon
while(1);
#endif
}
示例#3
0
文件: xxx.c 项目: lexuszhi1990/hen
static void redraw_display(bool clear)
{
    struct view *view;
    view = display[0];

    if (clear)
        wclear(view->win);
    redraw_view(view);
    update_title_win(view);
}
示例#4
0
文件: xxx.c 项目: lexuszhi1990/hen
static void move_view(struct view *view, int lines)
{
	/* The rendering expects the new offset. */
	view->offset += lines;

	assert(0 <= view->offset && view->offset < view->lines);
	assert(lines);

    int line = lines > 0 ? view->height - lines : 0;
    int end = line + (lines > 0 ? lines : -lines);

    wscrl(view->win, lines);

    for (; line < end; line++) 
    {
        if (!view->render(view, line))
            break;
    }

	/* Move current line into the view. */
	if (view->lineno < view->offset) 
    {
		view->lineno = view->offset;
		view->render(view, 0);

	} 
    else if (view->lineno >= view->offset + view->height) 
    {
		view->lineno = view->offset + view->height - 1;
		view->render(view, view->lineno - view->offset);
	}

	assert(view->offset <= view->lineno && view->lineno < view->lines);

	redrawwin(view->win);
	wrefresh(view->win);

	update_title_win(view);
}
示例#5
0
文件: xxx.c 项目: lexuszhi1990/hen
static void navigate_view(struct view *view, int request)
{
	int steps;

	switch (request) {

	case REQ_MOVE_UP:
		steps = -1;
		break;

	case REQ_MOVE_DOWN:
		steps = 1;
		break;
	}

	if (steps <= 0 && view->lineno == 0) {
		report("already at first line");
		return;

	} else if (steps >= 0 && view->lineno + 1 == view->lines) {
		report("already at last line");
		return;
	}

	/* Move the current line */
	view->lineno += steps;
	assert(0 <= view->lineno && view->lineno < view->lines);

	/* Repaint the old "current" line if we be scrolling */
    view->render(view, view->lineno - steps - view->offset);

	/* Check whether the view needs to be scrolled */
	if (view->lineno < view->offset ||
	    view->lineno >= view->offset + view->height) 
    {
		if (steps < 0 && -steps > view->offset) 
        {
			steps = -view->offset;
		} 
        else if (steps > 0) 
        {
			if (view->lineno == view->lines - 1 &&
			    view->lines > view->height) 
            {
				steps = view->lines - view->offset - 1;
				if (steps >= view->height)
                {
					steps -= view->height - 1;
                }
			}
		}
        move_view(view, steps); 
		return;
	}
   
	/* Draw the current line */
	view->render(view, view->lineno - view->offset);

	redrawwin(view->win);
	wrefresh(view->win);
	update_title_win(view);
}
示例#6
0
文件: xxx.c 项目: lexuszhi1990/hen
static int update_view(struct view *view)
{
	char buffer[BUFSIZ];
	char *line;
	void **tmp;
	int redraw_from = -1;
	unsigned long lines = view->height;
    char *top = "Binary file";

	if (!view->pipe)
		return TRUE;

	/* Only redraw if lines are visible. */
	if (view->offset + view->height >= view->lines)
		redraw_from = view->lines - view->offset;

	tmp = realloc(view->line, sizeof(*view->line) * (view->lines + lines));
	if (!tmp)
		goto alloc_error;

	view->line = tmp;

	while ((line = fgets(buffer, sizeof(buffer), view->pipe))) 
    {
		int linelen;
		linelen = strlen(line);

		if (linelen)
			line[linelen - 1] = 0;

        if(!strncmp(line, top, strlen(top))) 
            continue;

		if (!view->read(view, line))
			goto alloc_error;

		if (lines-- == 1)
			break;
	}

	if (redraw_from >= 0) {
		/* If this is an incremental update, redraw the previous line
		 * since for commits some members could have changed when
		 * loading the main view. */
		if (redraw_from > 0)
			redraw_from--;

		/* Incrementally draw avoids flickering. */
		redraw_view_from(view, redraw_from);
	}

	update_title_win(view);

	if (ferror(view->pipe)) {
		printw("Failed to read %s", view->cmd);
		goto end;

	} else if (feof(view->pipe)) {
        report("load %d lines", view->lines);
		goto end;
	}

	return TRUE;

alloc_error:
	printw("Allocation failure");

end:
	end_update(view);
	return FALSE;
}