src/print.c
static void
draw_rectange(int offsety, int offsetx,			/* y, x offset on screen */
			int maxy, int maxx,				/* size of visible rectangle */
			int srcy, int srcx,				/* offset to displayed data */
			DataDesc *desc,
			attr_t data_attr,				/* colors for data (alphanums) */
			attr_t line_attr,				/* colors for borders */
			attr_t expi_attr,				/* colors for expanded headers */
			bool clreoln)					/* force clear to eoln */
{
	int			row;
	LineBufferIter lbi;
	attr_t		active_attr;
	int			srcy_bak = srcy;

	init_lbi_ddesc(&lbi, desc, srcy);

	row = 0;

	if (offsety)
		/* \033 is \e */
		printf("\033[%dB", offsety);

	while (row < maxy)
	{
		int			bytes;
		char	   *ptr;
		char	   *rowstr = NULL;

		(void) lbi_get_line_next(&lbi, &rowstr, NULL, NULL);

		active_attr = line_attr;
		printf("%s", ansi_attr(active_attr));

		row += 1;

		if (rowstr != NULL)
		{
			int		i;
			int		effective_row = row + srcy_bak - 1;		/* row was incremented before, should be reduced */
			bool	fix_line_attr_style;
			bool	is_expand_head;
			int		ei_min, ei_max;
			int		left_spaces;
			char   *free_row;

			if (desc->is_expanded_mode)
			{
				fix_line_attr_style = effective_row >= desc->border_bottom_row;
				is_expand_head = is_expanded_header(rowstr, &ei_min, &ei_max);
			}
			else
			{
				fix_line_attr_style = effective_row == desc->border_top_row ||
											effective_row == desc->border_head_row ||
											effective_row >= desc->border_bottom_row;
				is_expand_head = false;
			}

			if (offsetx != 0)
				printf("\033[%dC", offsetx);

			/* skip first srcx chars */
			i = srcx;
			left_spaces = 0;

			while(i > 0)
			{
				if (*rowstr != '\0' && *rowstr != '\n')
				{
					i -= dsplen(rowstr);
					rowstr += charlen(rowstr);
					if (i < 0)
						left_spaces = -i;
				}
				else
					break;
			}

			/* Fix too hungry cutting when some multichar char is removed */
			if (left_spaces > 0)
			{
				char *p;

				free_row = malloc(left_spaces + strlen(rowstr) + 1);
				if (!free_row)
				{
					fprintf(stderr, "out of memory");
					exit(1);
				}

				p = free_row;
				while (left_spaces-- > 0)
				{
					*p++ = ' ';
				}
				strcpy(p, rowstr);
				rowstr = free_row;
			}
			else
				free_row = NULL;

			ptr = rowstr;
			bytes = 0;

			/* find length of maxx characters */
			if (*ptr != '\0' && *ptr != '\n')
			{
				i = 0;
				while (i < maxx)
				{
					int		pos = srcx + i;

					if (is_expand_head)
					{
						attr_t	new_attr;

						new_attr = pos >= ei_min && pos <= ei_max ? expi_attr : line_attr;

						if (new_attr != active_attr)
						{
							if (bytes > 0)
							{
								printf("%.*s", bytes, rowstr);
								rowstr += bytes;
								bytes = 0;
							}

							/* active new style */
							active_attr = new_attr;
							printf("%s", ansi_attr(active_attr));
						}
					}
					else if (!fix_line_attr_style && desc->headline_transl != NULL)
					{
						if (pos < desc->headline_char_size)
						{
							attr_t	new_attr;

							new_attr = desc->headline_transl[pos] == 'd' ? data_attr : line_attr;

							if (new_attr != active_attr)
							{
								if (bytes > 0)
								{
									printf("%.*s", bytes, rowstr);
									rowstr += bytes;
									bytes = 0;
								}

								/* active new style */
								active_attr = new_attr;
								printf("%s", ansi_attr(active_attr));
							}
						}
					}

					if (*ptr != '\0' && *ptr != '\n')
					{
						int len  = charlen(ptr);

						i += dsplen(ptr);
						ptr += len;
						bytes += len;
					}
					else
						break;
				}
			}

			if (bytes > 0)
			{
				printf("%.*s", bytes, rowstr);
				if (clreoln)
					printf("\033[K");
				printf("\n");
			}

			if (free_row != NULL)
			{
				free(free_row);
				free_row = NULL;
			}
		}
		else
			break;
	}
}
/*
 * Print data to primary screen without ncurses
 */
Print data to primary screen without ncurses
Print data to primary screen without ncurses
static void
draw_rectange(int offsety, int offsetx,			
			int maxy, int maxx,				
			int srcy, int srcx,				
			DataDesc *desc,
			attr_t data_attr,				
			attr_t line_attr,				
			attr_t expi_attr,				
			bool clreoln)					
{
	int			row;
	LineBufferIter lbi;
	attr_t		active_attr;
	int			srcy_bak = srcy;
	init_lbi_ddesc(&lbi, desc, srcy);
	row = 0;
	if (offsety)
		printf("\033[%dB", offsety);
	while (row < maxy)
	{
		int			bytes;
		char	   *ptr;
		char	   *rowstr = NULL;
		(void) lbi_get_line_next(&lbi, &rowstr, NULL, NULL);
		active_attr = line_attr;
		printf("%s", ansi_attr(active_attr));
		row += 1;
		if (rowstr != NULL)
		{
			int		i;
			int		effective_row = row + srcy_bak - 1;		
			bool	fix_line_attr_style;
			bool	is_expand_head;
			int		ei_min, ei_max;
			int		left_spaces;
			char   *free_row;
			if (desc->is_expanded_mode)
			{
				fix_line_attr_style = effective_row >= desc->border_bottom_row;
				is_expand_head = is_expanded_header(rowstr, &ei_min, &ei_max);
			}
			else
			{
				fix_line_attr_style = effective_row == desc->border_top_row ||
											effective_row == desc->border_head_row ||
											effective_row >= desc->border_bottom_row;
				is_expand_head = false;
			}
			if (offsetx != 0)
				printf("\033[%dC", offsetx);
			i = srcx;
			left_spaces = 0;
			while(i > 0)
			{
				if (*rowstr != '\0' && *rowstr != '\n')
				{
					i -= dsplen(rowstr);
					rowstr += charlen(rowstr);
					if (i < 0)
						left_spaces = -i;
				}
				else
					break;
			}
			if (left_spaces > 0)
			{
				char *p;
				free_row = malloc(left_spaces + strlen(rowstr) + 1);
				if (!free_row)
				{
					fprintf(stderr, "out of memory");
					exit(1);
				}
				p = free_row;
				while (left_spaces-- > 0)
				{
					*p++ = ' ';
				}
				strcpy(p, rowstr);
				rowstr = free_row;
			}
			else
				free_row = NULL;
			ptr = rowstr;
			bytes = 0;
			if (*ptr != '\0' && *ptr != '\n')
			{
				i = 0;
				while (i < maxx)
				{
					int		pos = srcx + i;
					if (is_expand_head)
					{
						attr_t	new_attr;
						new_attr = pos >= ei_min && pos <= ei_max ? expi_attr : line_attr;
						if (new_attr != active_attr)
						{
							if (bytes > 0)
							{
								printf("%.*s", bytes, rowstr);
								rowstr += bytes;
								bytes = 0;
							}
							active_attr = new_attr;
							printf("%s", ansi_attr(active_attr));
						}
					}
					else if (!fix_line_attr_style && desc->headline_transl != NULL)
					{
						if (pos < desc->headline_char_size)
						{
							attr_t	new_attr;
							new_attr = desc->headline_transl[pos] == 'd' ? data_attr : line_attr;
							if (new_attr != active_attr)
							{
								if (bytes > 0)
								{
									printf("%.*s", bytes, rowstr);
									rowstr += bytes;
									bytes = 0;
								}
								active_attr = new_attr;
								printf("%s", ansi_attr(active_attr));
							}
						}
					}
					if (*ptr != '\0' && *ptr != '\n')
					{
						int len  = charlen(ptr);
						i += dsplen(ptr);
						ptr += len;
						bytes += len;
					}
					else
						break;
				}
			}
			if (bytes > 0)
			{
				printf("%.*s", bytes, rowstr);
				if (clreoln)
					printf("\033[K");
				printf("\n");
			}
			if (free_row != NULL)
			{
				free(free_row);
				free_row = NULL;
			}
		}
		else
			break;
	}
}
static void draw_rectange ( int offsety , int offsetx , int maxy , int maxx , int srcy , int srcx , DataDesc * desc , attr_t data_attr , attr_t line_attr , attr_t expi_attr , bool clreoln ) { int row ; LineBufferIter lbi ; attr_t active_attr ; int srcy_bak = srcy ; init_lbi_ddesc ( & lbi , desc , srcy ) ; row = 0 ; if ( offsety ) printf ( " \033 " , offsety ) ; while ( row < maxy ) { int bytes ; char * ptr ; char * rowstr = NULL ; ( void ) lbi_get_line_next ( & lbi , & rowstr , NULL , NULL ) ; active_attr = line_attr ; printf ( " " , ansi_attr ( active_attr ) ) ; row += 1 ; if ( rowstr != NULL ) { int i ; int effective_row = row + srcy_bak - 1 ; bool fix_line_attr_style ; bool is_expand_head ; int ei_min , ei_max ; int left_spaces ; char * free_row ; if ( desc -> is_expanded_mode ) { fix_line_attr_style = effective_row >= desc -> border_bottom_row ; is_expand_head = is_expanded_header ( rowstr , & ei_min , & ei_max ) ; } else { fix_line_attr_style = effective_row == desc -> border_top_row || effective_row == desc -> border_head_row || effective_row >= desc -> border_bottom_row ; is_expand_head = false ; } if ( offsetx != 0 ) printf ( " \033 " , offsetx ) ; i = srcx ; left_spaces = 0 ; while ( i > 0 ) { if ( * rowstr != ' \0 ' && * rowstr != ' \n ' ) { i -= dsplen ( rowstr ) ; rowstr += charlen ( rowstr ) ; if ( i < 0 ) left_spaces = - i ; } else break ; } if ( left_spaces > 0 ) { char * p ; free_row = malloc ( left_spaces + strlen ( rowstr ) + 1 ) ; if ( ! free_row ) { fprintf ( stderr , " " ) ; exit ( 1 ) ; } p = free_row ; while ( left_spaces -- > 0 ) { * p ++ = ' ' ; } strcpy ( p , rowstr ) ; rowstr = free_row ; } else free_row = NULL ; ptr = rowstr ; bytes = 0 ; if ( * ptr != ' \0 ' && * ptr != ' \n ' ) { i = 0 ; while ( i < maxx ) { int pos = srcx + i ; if ( is_expand_head ) { attr_t new_attr ; new_attr = pos >= ei_min && pos <= ei_max ? expi_attr : line_attr ; if ( new_attr != active_attr ) { if ( bytes > 0 ) { printf ( " " , bytes , rowstr ) ; rowstr += bytes ; bytes = 0 ; } active_attr = new_attr ; printf ( " " , ansi_attr ( active_attr ) ) ; } } else if ( ! fix_line_attr_style && desc -> headline_transl != NULL ) { if ( pos < desc -> headline_char_size ) { attr_t new_attr ; new_attr = desc -> headline_transl [ pos ] == ' ' ? data_attr : line_attr ; if ( new_attr != active_attr ) { if ( bytes > 0 ) { printf ( " " , bytes , rowstr ) ; rowstr += bytes ; bytes = 0 ; } active_attr = new_attr ; printf ( " " , ansi_attr ( active_attr ) ) ; } } } if ( * ptr != ' \0 ' && * ptr != ' \n ' ) { int len = charlen ( ptr ) ; i += dsplen ( ptr ) ; ptr += len ; bytes += len ; } else break ; } } if ( bytes > 0 ) { printf ( " " , bytes , rowstr ) ; if ( clreoln ) printf ( " \033 " ) ; printf ( " \n " ) ; } if ( free_row != NULL ) { free ( free_row ) ; free_row = NULL ; } } else break ; } }
Print data to primary screen without ncurses
Print data to primary screen without ncurses
/* y, x offset on screen */ /* size of visible rectangle */ /* offset to displayed data */ /* colors for data (alphanums) */ /* colors for borders */ /* colors for expanded headers */ /* force clear to eoln */ /* \033 is \e */ /* row was incremented before, should be reduced */ /* skip first srcx chars */ /* Fix too hungry cutting when some multichar char is removed */ /* find length of maxx characters */ /* active new style */ /* active new style */