示例#1
0
static void draw(Console *t, bmp4* b) {
	int x,y;
	unsigned *p = b->data;
	for(y=0;y<b->height;y++) for(x=0;x<b->width;x++) {
		console_setcolor(t, 0, *((rgb_t*) p));
		console_goto(t, x, y);
		console_addchar(t, ' ', 0);
		p++;
	}
	console_refresh(t);
}
示例#2
0
文件: tty.c 项目: bmarcot/kemerald
int32_t	tty_refresh(void)
{
uint32_t	i = 0;

  /* find an active tty */
  while ((i < TTY_N) && (tty[i].active == false))
    i++;

  /* if no tty are currently active, return with an error */
  if (i >= TTY_N)
    return ERR_UNKNOWN;

  /* refresh the console with the current tty output */
  tty[i].lastline = console_refresh(tty[i].desc, tty[i].lastline);

  return ERR_NONE;
}
示例#3
0
文件: ncconsole.c 项目: rofl0r/concol
void console_putchar(Console* self, int ch, int doupdate) {
	console_addchar(self, ch, 0);
	if(self->automove) console_advance_cursor(self, 1);
	if(doupdate) console_refresh(self);
}
示例#4
0
void console_tick (void)
{
    if (!HEADLESS && !enable_console) {
        return;
    }

#ifndef _WIN32
    char seq[2];
    char seq2[2];
    char c;

    console_refresh();

    /*
     * Read nonblocking to get chars.
     */
    int fd = STDIN_FILENO;
    int flags = fcntl(fd, F_GETFL, 0);
    size_t nread;
    fcntl(fd, F_SETFL, flags | O_NONBLOCK);
    nread = read(fd,&c,1);
    fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
    if (nread <= 0) {
        return;
    }

    char beforecursor[MAXSTR];
    char updatedtext[MAXSTR];
    char aftercursor[MAXSTR];
    char entered[MAXSTR];
    char newchar[2];
    int origlen;
    int cnt;

    newchar[0] = '\0';
    newchar[0] = c;

    origlen = (uint32_t)strlen(wid_text);

    strlcpy(beforecursor, wid_text, cursor_x + 1);
    strlcpy(aftercursor, wid_text + cursor_x, sizeof(aftercursor));

    switch (c) {
        case '':
            if (!history_walk) {
                history_walk = HISTORY_MAX - 1;
            } else {
                history_walk--;
            }

            console_set_text(history[history_walk]);
            cursor_x = (uint32_t)strlen(console_get_text());
            break;

        case '':
            history_walk++;
            if (history_walk >= HISTORY_MAX) {
                history_walk = 0;
            }

            console_set_text(history[history_walk]);
            cursor_x = (uint32_t)strlen(console_get_text());
            break;

        case '':
            cursor_x = 0;
            break;

        case '':
            cursor_x = origlen;
            break;

        case '':
        case '':
            if (cursor_x > 0) {
                strlcpy(updatedtext, beforecursor, cursor_x);
                strlcat(updatedtext, aftercursor, sizeof(updatedtext));

                cursor_x--;

                console_set_text(updatedtext);
            }
            break;

        case '\t':
            updatedtext[0] = '\0';
            command_handle(console_get_text(), updatedtext,
                            false /* show ambiguous */,
                            true /* show complete */,
                            false /* execute command */,
                            0 /* context */);

            if (updatedtext[0]) {
                console_set_text(updatedtext);
                cursor_x = (uint32_t)strlen(updatedtext);;
            }
            return;

        case '\n':
        case '\r':
            if (origlen) {
                strlcpy(entered, console_get_text(), sizeof(entered));

                if (!command_handle(entered, updatedtext,
                                true /* show ambiguous */,
                                false /* show complete */,
                                true /* execute command */,
                                0 /* context */)) {
                    return;
                }

                if (updatedtext[0]) {
                    console_set_text(updatedtext);
                    cursor_x = (uint32_t)strlen(updatedtext);;
                }

                strlcpy(history[history_at], updatedtext,
                        sizeof(history[history_at]));

                history_at++;
                if (history_at >= HISTORY_MAX) {
                    history_at = 0;
                }
                history_walk = history_at;

                console_set_text("");
                cursor_x = 0;
            } else {
                CON(" ");
            }
            return;

        case 27:    /* escape sequence */

            if (read(fd,seq,2) == -1) break;

            if (seq[0] == 91 && seq[1] == 68) {
                if (cursor_x > 0) {
                    cursor_x--;
                }
            } else if (seq[0] == 91 && seq[1] == 67) {
                if (cursor_x < origlen) {
                    cursor_x++;
                }
            } else if (seq[0] == 91 && (seq[1] == 65 || seq[1] == 66)) {
                /* Up and Down arrows */
                if (seq[1] == 65) {
                    cnt = 0;
                    while (cnt < HISTORY_MAX) {
                        cnt++;
                        if (!history_walk) {
                            history_walk = HISTORY_MAX - 1;
                        } else {
                            history_walk--;
                        }

                        console_set_text(history[history_walk]);
                        if (!history[history_walk][0]) {
                            continue;
                        }

                        cursor_x = (uint32_t)strlen(console_get_text());
                        break;
                    }
                    break;
                } else {
                    cnt = 0;
                    while (cnt < HISTORY_MAX) {
                        cnt++;

                        history_walk++;
                        if (history_walk >= HISTORY_MAX) {
                            history_walk = 0;
                        }

                        console_set_text(history[history_walk]);
                        if (!history[history_walk][0]) {
                            continue;
                        }

                        cursor_x = (uint32_t)strlen(console_get_text());
                        break;
                    }
                    break;
                }

            } else if (seq[0] == 91 && seq[1] > 48 && seq[1] < 55) {
                /* extended escape, read additional two bytes. */
                if (read(fd,seq2,2) == -1) break;

                if (seq[1] == 51 && seq2[0] == 126) {
                    /* Delete key. */
                    if (cursor_x > 0) {
                        strlcpy(updatedtext, beforecursor, cursor_x);
                        strlcat(updatedtext, aftercursor, sizeof(updatedtext));

                        cursor_x--;

                        console_set_text(updatedtext);
                    }
                    break;
                }
            }
            break;

        case '?':
            updatedtext[0] = '\0';
            command_handle(console_get_text(), updatedtext,
                            true /* show ambiguous */,
                            false /* show complete */,
                            false /* execute command */,
                            0 /* context */);

            if (updatedtext[0]) {
                console_set_text(updatedtext);
                cursor_x = (uint32_t)strlen(updatedtext);;
            }
            return;

        default: {
            if (origlen >= (typeof(origlen)) sizeof(updatedtext) - 1) {
                break;
            }

            newchar[1] = '\0';
            newchar[0] = c;
            if (!newchar[0]) {
                break;
            }

            strlcpy(updatedtext, beforecursor, cursor_x + 1);
            strlcat(updatedtext, newchar, sizeof(updatedtext));
            strlcat(updatedtext, aftercursor, sizeof(updatedtext));

            cursor_x++;

            console_set_text(updatedtext);
        }
    }
#endif
}
示例#5
0
int main(int argc, char** argv) {
	char* filename;
	int scaleFullScreen = 0;
	Console co;
	Console* t = &co;
	int cx; int cy;
	int w, h;
	int iterX, iterY;

	struct Pix* pngfile;
	struct Pix* ping;
	struct Pix* palette;
	struct Pix* pix32;
	int i, ix, iy;
	int c;
	
	for (i = 1; i<argc; i++) {
		if (strlen(argv[i]) > 1 && !memcmp(argv[i], "-f", 2)) 
			scaleFullScreen=1;
		else filename = argv[i];
	}

	if (access(filename, R_OK)) {
		puts("file not found!");
		puts("c0npix by rofl0r");
		puts("================");
		printf("arguments: %s [-f] somefile.[jpg|png|bmp|tiff]\n", argv[0]);
		puts("where -f means scale to fullscreen");
		puts("export TERM=xterm-256color before usage is recommended.");
		exit(1);
	}

	console_init(t);
	point reso = {800, 600};
	console_init_graphics(&co, reso, FONT);

	console_getbounds(t, &cx, &cy);

	pngfile = pixRead(filename);

	pixGetDimensions(pngfile, &w, &h, NULL);

	ping = pixScale(pngfile, 2.0, 1.0 );
	
	pixDestroy(&pngfile);
	
	palette = pixOctreeColorQuant(ping, 240, 1);
	
	if (palette == NULL) { puts("palette is nul"); goto finish_him; }

	pix32 = pixConvertTo32(palette);

	iterX = pix32->w;
	iterY = pix32->h;

	int* bufptr = (int*) pix32->data;
	if (bufptr == NULL) {
		puts("bufptr is null");
		goto finish_him;
	}
	
	int startx = 0;
	int starty = 0;
	
	paint:
	for(iy = starty; iy < starty + cy; iy++) {
		bufptr = (int*) pix32->data + (iy * pix32->w) + startx;
		for(ix = startx; ix < startx + cx; ix++) {
			console_setcolor(t, 0, *((rgb_t*) bufptr));
			console_goto(t, ix - startx, iy - starty);
			console_addchar(t, ' ', 0);
			bufptr++;
		}
	}
	console_draw(t);
	//console_printfxy(t, 0, 0, "%d", (int) c);
	
	while ((c = console_getkey(t)) != 'q') {

		console_setcolor(t, 0, RGB(0,0,0));
		
		switch(c) {
			case CK_CURSOR_UP: 
				if(starty > 0) starty--;
				break;
			case CK_CURSOR_DOWN:
				if(starty < (int) pix32->h - cy)
					starty++;
				break;
			case CK_CURSOR_LEFT:
				if(startx > 0)
					startx--;
				break;
			case CK_CURSOR_RIGHT:
				if(startx < (int) pix32->w - cx)
					startx++;
				break;
			default:
				goto loopend; // ignore mouse movement and similar stuff
				break;
		}
		goto paint;
		loopend: ;
	}
	
	pixDestroy(&palette);
	pixDestroy(&pix32);

	console_refresh(t);
	
	finish_him:
	//console_getkey(t);
	
	console_cleanup(t);

	return 0;
}