Beispiel #1
0
void
process_move (gint c)
{
  if (timeout) {
    g_timeout_add (SPEED_DROP,
	           (GSourceFunc) next_move, GINT_TO_POINTER (c));
    return;

  }

  if (!p.do_animate) {
    move_cursor (c);
    column_moveto = c;
    process_move2 (c);
  } else {
    column_moveto = c;
    anim = ANIM_MOVE;
    timeout = g_timeout_add (SPEED_MOVE,
                             (GSourceFunc) on_animate, GINT_TO_POINTER (c));
  }
}
Beispiel #2
0
void reset_terminal(void){
	clear_terminal();
	
	set_display_attribute(BAR_COLOUR);
	draw_horizontal_line(1,1,WIDTH);
	set_display_attribute(BAR_COLOUR);
	draw_vertical_line(40,1,HEIGHT);
	
	move_cursor(TITLE_X,TITLE_Y);
	printf_P(PSTR("FROGGER"));
	
	draw_lives();
	draw_score();
	draw_level();
	draw_time(16);
	display_scores();
	draw_status(0);
	draw_frog();
	
	set_display_attribute(8);
}
Beispiel #3
0
void console_putc_color(char c, real_color_t back, real_color_t fore)
{
	uint8_t back_color = (uint8_t)back;
	uint8_t fore_color = (uint8_t)fore;

	uint8_t attribute_byte = (back_color << 4) | (fore_color & 0x0F);
	uint16_t attribute = attribute_byte << 8;
	
	if ((c == 0x08) && cursor_x)
	{
		cursor_x--;
	}
	else if (c == 0x09)
	{
		cursor_x = (cursor_x+8) & ~(8-1);		
	}
	else if (c == '\r')
	{
		cursor_x = 0;
	}
	else if (c == '\n')
	{
		cursor_x=0;
		cursor_y++;
	}
	else if(c >= ' ') //the acsii code bigger than SPACE is valid char.
	{
		video_memory[cursor_y*80 + cursor_x] = (c | attribute);
		cursor_x++;
	}
	
	if (cursor_x >= 80)
	{
		cursor_x = 0;
		cursor_y++;
	}
	scroll();
	move_cursor();

}
Beispiel #4
0
void mon_putchar(char c)
{
	/* The background colour is black (0), the foreground is green (2). */
	uint8_t bc = 0, fc = 2;

	/* The attribute byte is made up of two nibbles - the lower being the
	   foreground colour, and the upper the background colour. */
	uint8_t attr_byte = (bc << 4) | (fc & 0x0F);
	/* The attribute byte is the top 8 bits of the word we have to send to
	   the VGA board. */
	uint16_t attr = attr_byte << 8;
	uint16_t *location;

	if (c == 0x08 && cursor_x > 0) {
		/* Handle a backspace, by moving the cursor back one space */
		cursor_x--;
	} else if (c == 0x09) {
		/* Handle a tab by increasing the cursor's X, but only to a point where
		   it is divisible by 8. */
		cursor_x = (cursor_x + 8) & ~(8 - 1);
	} else if (c == '\r') {
		/* Handle carriage return */
		cursor_x = 0;
	} else if (c == '\n') {
		/* Handle newline return */
		cursor_x = 0;
		cursor_y++;
	} else if (c >= ' ') {
		/* Handle any other printable char */
		location = video_memory + (cursor_x++ + MON_WIDTH * cursor_y);
		*location = c | attr;
	}

	if (cursor_x >= MON_WIDTH) {
		cursor_x = 0;
		cursor_y++;
	}
	scroll();
	move_cursor();
}
Beispiel #5
0
void init()
{
	move_cursor(X_MIN,Y_MIN);
	int x,y;
	printf("\033[37;40m");
	for(y = Y_MIN; y < Y_MAX; y+=2)
	{
		for(x = X_MIN ; x < X_MAX; x++)
		{
			printf(" ");
			if(x == 40)
				print_tennis_net();
		}
		printf("\r\n");
	}
	for(x = X_MIN ; x < X_MAX; x++)
	{
		printf(" ");
		if(x == 40)
			print_tennis_net();
	}
}
Beispiel #6
0
void vga_clearscreen ()
{
  unsigned short *vptr = (unsigned short *)VMEM_BASE;
  unsigned char vchar = ' ';
  unsigned char backcolor = 0;
  unsigned char forecolor = 15;
  unsigned char vattr = (u8)(backcolor << 4) | (forecolor);

  unsigned short vval = (u16)((u16)(vattr << 8) | (vchar));

  int cnt;
  cnt  = max_x * max_y;
  int offset = 0;

  vval = (u16)((vattr << 8) | (vchar));
  for (offset = 0; offset < cnt; offset++)
    *(volatile unsigned short*)(vptr + offset) = vval;
  
  cursor_x = 0;
  cursor_y = 0;
  move_cursor (cursor_x, cursor_y);
}
Beispiel #7
0
void terminal_putchar(char c)
{	
  if(c == '\n')
    new_line();
	else if(c == '\b')
	{
		if(terminal_column == 0)
		{
			if(terminal_row!=0)
				--terminal_row;
			terminal_column = VGA_WIDTH-1;
		}
		else
			--terminal_column;
	}
  else{
    terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
	  if( ++terminal_column == VGA_WIDTH )
		  new_line();
  }
	move_cursor();
}
Beispiel #8
0
static void
on_game_hint (GtkMenuItem * m, gpointer data)
{
  gchar *s;
  gint c;

  if (timeout)
    return;
  if (gameover)
    return;

  gtk_action_set_sensitive (hint_action, FALSE);
  gtk_action_set_sensitive (undo_action, FALSE);

  set_status_message (_("Thinking..."));

  vstr[0] = vlevel[LEVEL_STRONG];
  c = playgame (vstr, vboard) - 1;

  column_moveto = c;
  if (p.do_animate) {
    while (timeout)
      gtk_main_iteration ();
    anim = ANIM_HINT;
    timeout = g_timeout_add (SPEED_MOVE, (GSourceFunc) on_animate, NULL);
  } else {
    move_cursor (column_moveto);
  }

  blink_tile (0, c, gboard[0][c], 6);

  s = g_strdup_printf (_("Hint: Column %d"), c + 1);
  set_status_message (s);
  g_free (s);

  gtk_action_set_sensitive (hint_action, TRUE);
  gtk_action_set_sensitive (undo_action, (moves > 0));
}
void GTerm::set_mode() // h
{
    switch (param[0] + 1000 * q_mode)
    {
        case 1007:
            clear_mode_flag(NOEOLWRAP);
            break;

        case 1001:
            set_mode_flag(CURSORAPPMODE);
            break;

        case 1006:
            set_mode_flag(CURSORRELATIVE);
            break;

        case 4:
            set_mode_flag(INSERT);
            break;

        case 1003:
            RequestSizeChange(132, height);
            break;

        case 20:
            set_mode_flag(NEWLINE);
            break;

        case 12:
            clear_mode_flag(LOCALECHO);
            break;

        case 1025:
            clear_mode_flag(CURSORINVISIBLE);
            move_cursor(cursor_x, cursor_y);
            break;
    }
}
Beispiel #10
0
void monitor_put(char c)
{
	u8int attribute = 0x0f;

	switch(c){
	case 0x08://backspace
		if(cursor_x > 0){
			//delete char use *((cursor_x + cursor_y * 80) * 2) = 0x2f;
			cursor_x -= 1;
		}
		break;
	case 0x09://tab
		cursor_x = (cursor_x + 8) & ~(8 - 1);
		break;
	case '\r'://0x0d cr
		cursor_x = 0;
		break;
	case '\n'://0x0a line feed
		cursor_x = 0;
		cursor_y ++;
		break;
	default:
		//if(c >= '0' && c <= '9' ||
		//	   	c >= 'a' && c <= 'z' || 
		//		c >= 'A' && c <= 'Z')//0~9 a~z A~Z 只处理ascii
		{u16int* loc = video_memory + (cursor_y * 80 + cursor_x); //video_memory is u16int, don't *2 here
		*loc = c | attribute << 8;
		cursor_x++;
		}
		break;
	}
	if(cursor_x >= 80){
		cursor_x = 0;
		cursor_y++;
	}
	scroll();
	move_cursor();
}
Beispiel #11
0
void splash_screen(void) {

	/* Clear the terminal screen */
	clear_terminal();
	init_score();
	update_score();

	/* 
	** Display some suitable message to the user that includes your name(s)
	** and student number(s).
	** You may need to use terminalio functions to position the cursor 
	** appropriately - see terminalio.h for details.
	*/
	display_sound_status();

	move_cursor(0,TITLEY);
	printf_P(PSTR("Snake\n\nBy: Justin Mancinelli\n\nID: 42094353"));
	//move_cursor(NAMEX,NAMEY);
	//printf_P(PSTR(""));
	//move_cursor(IDX,IDY);
	//printf_P(PSTR(""));

}
Beispiel #12
0
Datei: input.c Projekt: dmt4/ne
static unsigned int print_prompt(const char * const prompt) {
	static const char *prior_prompt;
	assert(prompt != NULL || prior_prompt);

	if (prompt) prior_prompt = prompt;

	move_cursor(ne_lines - 1, 0);

	clear_to_eol();

	standout_on();

	output_string(prior_prompt, false);
	output_string(":", false);

	standout_off();

	output_string(" ", false);

	reset_status_bar();

	return strlen(prior_prompt) + 2;
}
Beispiel #13
0
// 清屏操作
void console_clear(void)
{
        uint8_t attribute_byte = (0 << 4) | (15 & 0x0F);
        uint16_t blank = 0x20 | (attribute_byte << 8);

        // 初始化 console 数据
        for (uint32_t i = 0; i < CON_WIDTH * CON_HIGH; ++i) {
              video_memory[i] = blank;
        }
        cursor_x = 0;
        cursor_y = 0;
        move_cursor();

        // 初始化 buffer 数据
        for (uint32_t i = 0; i < BUFF_WIDTH * BUFF_HIGH; ++i) {
              video_buffer[i] = blank;
        }
        
        buffer_x = 0;
        buffer_y = 0;
        
        current_line = 0;
}
Beispiel #14
0
/*
 * write_to_screen
 * 
 * Prints a series of characters to the screen, by writing directly to
 * video memory. The position of the cursor is updated accordingly. The
 * screen is scrolled if the text goes beyond the end of the last line.
 */
void write_to_screen(const char *data, unsigned int count)	// @TODO: Move to video.c
{
	unsigned int i;
	for (i = 0; i < count; i++) {
		char c = data[i];

		if ('\n' == c) {
			/* newline */
			xpos = 0;
			ypos++;
		} else if ('\t' == c) {
			/* tab  */
			int add = 8 - (xpos % 8);
			xpos += add;
		} else if (c == BACKSPACE && xpos) {
			/* Handle a backspace, by moving the cursor back one space
			 * untill the cursor is against the edge */

			xpos--;	/* Back the cursor up then display if */
			screen[ypos * SCREEN_WIDTH + xpos].c = (int)NULL;

		} else {
			/* normal character */
			screen[ypos * SCREEN_WIDTH + xpos].c = c;
			xpos++;
		}
		if (xpos >= SCREEN_WIDTH) {
			xpos = 0;
			ypos++;
		}
		if (ypos >= SCREEN_HEIGHT) {
			scroll();
		}
	}

	move_cursor(xpos, ypos);
}
Beispiel #15
0
void put(char c)
{
    uint16_t attribute = attbyte << 8;

    switch (c) {
    case '\b': // backspace
        if (cursor_x)
            cursor_x--;
        break;

    case '\t': // tab
        cursor_x = (cursor_x+8) & ~7; // align at a 8-byte boundary
        break;

    case '\n': // LF
        cursor_y++;
        // falls through to reset cursor_x
    case '\r': // CR
        cursor_x = 0;
        break;

    default:
        if (c >= ' ') {
            *(video_mem + (cursor_y*80+cursor_x)) = c | attribute;
            cursor_x++;
        }
        break;
    }

    if (cursor_x >= 80) { // start a new line
        cursor_x = 0;
        cursor_y++;
    }

    scroll();
    move_cursor(cursor_y, cursor_x);
}
Beispiel #16
0
void DISPLAYSHIT(void) {
	int x1;
	int x2;
	move_cursor(10,20);
	x1 = sqrt(tickA*INCRIMENT*tickA*INCRIMENT+HEIGHT2);
	x2 = sqrt(tickB*INCRIMENT*tickB*INCRIMENT+HEIGHT2);
	printf_P(PSTR("\nx1: %d\tx2: %d\tWidth: %d\t"),x1,x2,(x1+x2));
	printf_P(PSTR("\nA: %d\t"),tickA);
	for(int i = 0; i < tickA; i++){
		i += 9;
		printf_P(PSTR("*"));
	}
		for(int i = 0; i < 50; i++){
			printf_P(PSTR("."));
		}
	printf_P(PSTR("\nB: %d\t"),tickB);
	for(int i = 0; i < tickB; i++){
		printf_P(PSTR("@"));
		i += 9;
	}
		for(int i = 0; i < 50; i++){
			printf_P(PSTR("."));
		}
}
void GTerm::reset()
{
    int i;

    pending_scroll = 0;
    bg_color = 0;
    fg_color = 7;
    scroll_top = 0;
    scroll_bot = height - 1;

    for (i = 0; i<MAXHEIGHT; i++)
        linenumbers[i] = i;

    memset(tab_stops, 0, sizeof(tab_stops));
    current_state = GTerm::normal_state;

    clear_mode_flag(NOEOLWRAP | CURSORAPPMODE | CURSORRELATIVE | NEWLINE | INSERT | UNDERLINE | BLINK | KEYAPPMODE
                              | CURSORINVISIBLE);

    clear_area(0, 0, width - 1, height - 1);
    move_cursor(0, 0);

	tm.Reset();
}
Beispiel #18
0
Datei: input.c Projekt: dmt4/ne
char request_char(const buffer * const b, const char * const prompt, const char default_value) {
	set_attr(0);
	print_prompt(prompt);

	if (default_value) output_char(default_value, 0, false);
	move_cursor(b->cur_y, b->cur_x);

	while(true) {
		int c;
		input_class ic;
		do c = get_key_code(); while(c > 0xFF || (ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID);

		switch(ic) {
			case ALPHA:
				return (char)localised_up_case[(unsigned char)c];

			case RETURN:
				return (char)localised_up_case[(unsigned char)default_value];

			default:
				break;
		}
	}
}
Beispiel #19
0
/*
**	Display a tray of `rows' rows.
*/
void	display_tray(int rows, int height, int width)
{
  int	pipes;
  int	i;

  pipes = 1;
  while (pipes < rows * 2)
    {
      i = 0;
      move_cursor(width, height);
      if (pipes == 1)
        {
          my_putstr("\033[31m|\033[0m");
          launch_termcap(SAVE_CURSOR);
        }
      else
        while (i++ < pipes)
          my_putchar('|');
      width = width - 1;
      height = height + 1;
      pipes = pipes + 2;
    }
  launch_termcap(RESTORE_CURSOR);
}
Beispiel #20
0
static void printchar(const char c, uint8_t color, bool bold)
{
	if(c <= 7) return;
	if(c=='\b')
	{
		if(col>0) move_cursor(0, -1);
		return;
	}
	if(c=='\n')
	{
		col=0;
		row++;
	}
	else if(c=='\r')
	{
		col=0;
	}
	else
	{
		if(bold) color=0x09;
		*(video+(row*160)+col)=c;
		*(video+(row*160)+col+1)=color;
		col+=2;
		if(col>=160)
		{
			col=0;
			row++;
		}
	}
	if(row>scroll_buffer_end)
	{ // Scroll the buffer
		row=scroll_buffer_end;
		scroll(1);
		cls_from_cursor_to_eol();
	}
}
Beispiel #21
0
void scroll(char c)
{
    if(index >= 80*25*2) {
		index = 0;
		while(index < 80*24*2) {
			vidptr[index] = vidptr[index + 160];
			vidptr[index + 1] = vidptr[index + 161];
			index += 2;
		}
		
		index = 80*24*2;
		
		while(index < 80*25*2) {
			putch(' ');
		}
		
		index = 80*24*2;
		
		if(pt_s == 0)
			putch(c);
		
		move_cursor((index/2)%80, (index/2)/80);
	}
}
Beispiel #22
0
/* the main game loop */
static bool flipit_loop(void) 
{
    int i;
    int button;
    int lastbutton = BUTTON_NONE;

    flipit_init();
    while(true) {
        button = rb->button_get(true);
        switch (button) {
#ifdef FLIPIT_RC_QUIT
            case FLIPIT_RC_QUIT:
#endif
            case FLIPIT_QUIT:
                /* get out of here */
                return PLUGIN_OK;

            case FLIPIT_SHUFFLE:
                /* mix up the pieces */
                flipit_init();
                break;

            case FLIPIT_SOLVE:
#ifdef FLIPIT_SOLVE_PRE
                if (lastbutton != FLIPIT_SOLVE_PRE)
                    break;
#endif
                /* solve the puzzle */
                if (!flipit_finished()) {
                    for (i=0; i<20; i++)
                        if (!toggle[i]) {
                            clear_cursor();
                            cursor_pos = i;
                            flipit_toggle();
                            draw_cursor();
                            rb->lcd_update();
                            rb->sleep(HZ*2/3);
                        }
                }
                break;

            case FLIPIT_STEP_BY_STEP:
#ifdef FLIPIT_STEP_PRE
                if (lastbutton != FLIPIT_STEP_PRE)
                    break;
#endif
                if (!flipit_finished()) {
                    for (i=0; i<20; i++)
                        if (!toggle[i]) {
                            clear_cursor();
                            cursor_pos = i;
                            flipit_toggle();
                            draw_cursor();
                            rb->lcd_update();
                            break;
                        }
                }
                break;

            case FLIPIT_TOGGLE:
#ifdef FLIPIT_TOGGLE_PRE
                if (lastbutton != FLIPIT_TOGGLE_PRE)
                    break;
#endif
                /* toggle the pieces */
                if (!flipit_finished()) {
                    flipit_toggle();
                    draw_cursor();
                    rb->lcd_update();
                }
                break;

            case FLIPIT_LEFT:
                move_cursor(-1, 0);
                break;

            case FLIPIT_RIGHT:
                move_cursor(1, 0);
                break;
            /*move cursor though the entire field*/
#ifdef FLIPIT_SCROLLWHEEL
            case FLIPIT_PREV:
            case FLIPIT_PREV|BUTTON_REPEAT:    
                if ((cursor_pos)%5 == 0) {
                    move_cursor(-1, -1);
                }
                else {
                    move_cursor(-1, 0);
                }
                break;

            case FLIPIT_NEXT:
            case FLIPIT_NEXT|BUTTON_REPEAT:
                if ((cursor_pos+1)%5 == 0) {
                    move_cursor(1, 1);
                }
                else {
                    move_cursor(1, 0);
                }
                break;
#endif
            case FLIPIT_UP:
#ifdef FLIPIT_UP_PRE
                if (lastbutton != FLIPIT_UP_PRE)
                    break;
#endif
                move_cursor(0, -1);
                break;

            case FLIPIT_DOWN:
                move_cursor(0, 1);
                break;

            default:
                if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
                    return PLUGIN_USB_CONNECTED;
                break;
        }
        if (button != BUTTON_NONE)
            lastbutton = button;
    }
}
Beispiel #23
0
const char *get_lesson(void)	/* Ask user for desired lesson */
{
    static StrType response;
    int ch, n, i, item;
    struct Lesson *p;
    char *lp;

    if (LastLesson) {
	ch = LastLesson;
	n = (LastNum == FINISHED)? 1: (LastNum + 1);
    }else {
	ch = typeLessons[0].nam;
	n = 1;
    }

    move_cursor(0, 0);
#ifdef JPN
    add_str("  以下からコースを選択して下さい:");
    item = 0;
    for (p = typeLessons; p->item; p++) {
	move_cursor(++item, 0);
	add_fmt("        %s (%c1 - %c%d) ", p->item, p->nam, p->nam, p->num);
	if (p->fin >= p->num)
	    add_str(" !!!終了!!!");
	else if (p->fin > 0)
	    add_fmt(" [%c%dまで終了]", p->nam, p->fin);
    }
    move_cursor(++item, 0);
    add_fmt(" 練習したいレッスンの名前(例 %c%d)を入力して下さい", ch, n);
	if (HasHelp) {
		move_cursor(item+1, 0);
		add_str(" (終了=改行、ヘルプ=?) ------> ");
	}else
		add_str(" (終了=改行): ");
#else
    add_str("  Several lessons are available:");
    item = 1;
    for (p = typeLessons; p->item; p++) {
	move_cursor(item++, 8);
	add_fmt("%s (%c1 - %c%d) ", p->item, p->nam, p->nam, p->num);
	if (p->fin >= p->num)
	    add_str(" !!!Finish!!!");
	else if (p->fin > 0)
	    add_fmt(" [%c%d was done]", p->nam, p->fin);
    }
    move_cursor(++item, 0);
    add_fmt(" Type the desired lesson name(e.g. %c%d).", ch, n);
    move_cursor(item+1, 0);
    add_str(" (Quit=RETURN) ------------> ");
#endif

    cbreak_mode(0);

    (void)fgets(response, STR_SIZE, stdin);  /* avoid gets() */

    cbreak_mode(1);
    for (i = 0; i < STR_SIZE && response[i] != '\n' && response[i] != '\r'; i++)
	;
    response[i] = 0;
    for (lp = response; *lp == ' ' || *lp == '\t'; lp++)
	;
    if (*lp == 0)
	cleanup(0);	/* EXIT */
    if (HasHelp && *lp == '?')
	return "?1";	/* HELP FILE */

    return lp;
}
Beispiel #24
0
Datei: request.c Projekt: dmt4/ne
int request_strings(req_list *rlp0, int n) {

	assert(rlp0->cur_entries > 0);

	int ne_lines0 = 0, ne_columns0 = 0;
	bool reordered = false;
	max_names_per_line = max_names_per_col = x = y = page = fuzz_len = 0;
	if ( ! request_strings_init(rlp0) ) return ERROR;

	const int dx = rl.max_entry_len + 1 + (rl.suffix ? 1 : 0);

	while(true) {
		if (ne_lines0 != ne_lines || ne_columns0 != ne_columns) {
			if (ne_lines0 && ne_columns0 ) n = PXY2N(page,x,y);
			if (!(max_names_per_line = ne_columns / dx)) max_names_per_line = 1;
			max_names_per_col = ne_lines - 1;
			names_per_page = max_names_per_line * max_names_per_col;
			ne_lines0 = ne_lines;
			ne_columns0 = ne_columns;
			page = N2P(n);
			x = N2X(n);
			y = N2Y(n);
			print_strings();
			print_message(NULL);
		}

		n = PXY2N(page,x,y);

		assert(fuzz_len >= 0);

		fuzz_len = min(fuzz_len, strlen(rl.entries[n]));

		move_cursor(y, x * dx + fuzz_len);

		int c;
		input_class ic;
		do c = get_key_code(); while((ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID);

		switch(ic) {
			case ALPHA:
				if (n >= rl.cur_entries) n = rl.cur_entries - 1;

				c = localised_up_case[(unsigned char)c];

				fuzz_forward( c );

				break;

			case TAB:
				if (! rlp0->ignore_tab) {
					n = request_strings_cleanup(reordered);
					if (n >= rlp0->cur_entries) return ERROR;
					else return -n - 2;
				}
				break;

			case RETURN:
				n = request_strings_cleanup(reordered);
				if (n >= rlp0->cur_entries) return ERROR;
				else return n;

			case COMMAND:
				if (c < 0) c = -c - 1;
				const int a = parse_command_line(key_binding[c], NULL, NULL, false);
				if (a >= 0) {
					switch(a) {
					case BACKSPACE_A:
						fuzz_back();
						break;

					case MOVERIGHT_A:
						request_move_right();
						break;

					case MOVELEFT_A:
						request_move_left();
						break;

					case MOVESOL_A:
						request_move_to_sol();
						break;

					case MOVEEOL_A:
						request_move_to_eol();
						break;

					case TOGGLESEOL_A:
						if (x != 0) x = 0;
						else request_move_to_eol();
						break;

					case LINEUP_A:
						request_move_up();
						break;

					case LINEDOWN_A:
						request_move_down();
						break;

					case MOVEINCUP_A:
						request_move_inc_up();
						break;

					case MOVEINCDOWN_A:
						request_move_inc_down();
						break;

					case PAGEUP_A:
					case PREVPAGE_A:
						request_prev_page();
						break;

					case PAGEDOWN_A:
					case NEXTPAGE_A:
						request_next_page();
						break;

					case MOVESOF_A:
						request_move_to_sof();
						break;

					case MOVEEOF_A:
						request_move_to_eof();
						break;

					case TOGGLESEOF_A:
						request_toggle_seof();
						break;

					case NEXTWORD_A:
						request_move_next();
						break;

					case PREVWORD_A:
						request_move_previous();
						break;

					case NEXTDOC_A:
						reordered |= request_reorder(1);
						break;

					case PREVDOC_A:
						reordered |= request_reorder(-1);
						break;

					case INSERT_A:
					case DELETECHAR_A:
						prune = !prune;
						break;

					case CLOSEDOC_A:
					case ESCAPE_A:
					case QUIT_A:
					case SELECTDOC_A:
						request_strings_cleanup(reordered);
						return -1;
					}
				}
				break;

			default:
				break;
		}
	}
}
Beispiel #25
0
static int getch_nowait(void)
{
	int rd;
	struct pollfd pfd[2];

	pfd[0].fd = STDIN_FILENO;
	pfd[0].events = POLLIN;
	pfd[1].fd = kbd_fd;
	pfd[1].events = POLLIN;
 again:
	tcsetattr(kbd_fd, TCSANOW, &term_less);
	/* NB: select/poll returns whenever read will not block. Therefore:
	 * if eof is reached, select/poll will return immediately
	 * because read will immediately return 0 bytes.
	 * Even if select/poll says that input is available, read CAN block
	 * (switch fd into O_NONBLOCK'ed mode to avoid it)
	 */
	rd = 1;
	/* Are we interested in stdin? */
//TODO: reuse code for determining this
	if (!(option_mask32 & FLAG_S)
	   ? !(max_fline > cur_fline + max_displayed_line)
	   : !(max_fline >= cur_fline
	       && max_lineno > LINENO(flines[cur_fline]) + max_displayed_line)
	) {
		if (eof_error > 0) /* did NOT reach eof yet */
			rd = 0; /* yes, we are interested in stdin */
	}
	/* Position cursor if line input is done */
	if (less_gets_pos >= 0)
		move_cursor(max_displayed_line + 2, less_gets_pos + 1);
	fflush_all();

	if (kbd_input[0] == 0) { /* if nothing is buffered */
#if ENABLE_FEATURE_LESS_WINCH
		while (1) {
			int r;
			/* NB: SIGWINCH interrupts poll() */
			r = poll(pfd + rd, 2 - rd, -1);
			if (/*r < 0 && errno == EINTR &&*/ winch_counter)
				return '\\'; /* anything which has no defined function */
			if (r) break;
		}
#else
		safe_poll(pfd + rd, 2 - rd, -1);
#endif
	}

	/* We have kbd_fd in O_NONBLOCK mode, read inside read_key()
	 * would not block even if there is no input available */
	rd = read_key(kbd_fd, kbd_input, /*timeout off:*/ -2);
	if (rd == -1) {
		if (errno == EAGAIN) {
			/* No keyboard input available. Since poll() did return,
			 * we should have input on stdin */
			read_lines();
			buffer_fill_and_print();
			goto again;
		}
		/* EOF/error (ssh session got killed etc) */
		less_exit(0);
	}
	set_tty_cooked();
	return rd;
}
Beispiel #26
0
/**
 *  @brief Insert character into the input buffer and move the cursor.
 *
*     This function accepts keypad input and saves to
*     a character array. This is copied to display_buffer
*     during display_input_buffer routine.
 *
 *  @param [in] in_char Character to display.
 *  @return Void.
 */
void insert_char(char in_char){
  char temp_buffer[BUFFER_SIZE] = {0};
  int input_ptr;
  
  input_ptr = (cursor_pos + cursor_offset);
  if(input_ptr == input_len){
    switch(logged_in){
      case FALSE: // Inputting PIN Number
        if(input_len < PIN_MAX){
          input_len++;
          input_buffer[input_ptr] = in_char;
          move_cursor(RIGHT);
        }
        break;

      case TRUE: // Inputting Track Number
        if(input_len < TRACK_MAX){
          input_len++;
          input_buffer[input_ptr] = in_char;
          move_cursor(RIGHT);
        }
        break;
      default:
        break;
    }
  }
  else if(input_ptr < input_len){ // Cursor isn't at the end of the line
    switch(logged_in){
      case FALSE:
        if(input_len < PIN_MAX){
          bzero(temp_buffer,BUFFER_SIZE); // Fill buffer with NULL '\0'
          strncpy(temp_buffer,input_buffer,input_ptr);
          temp_buffer[input_ptr] = in_char;
          strcat(temp_buffer,&input_buffer[input_ptr]);
          strcpy(input_buffer,temp_buffer);
          input_len++;
          move_cursor(RIGHT);
        }
        break;
      case TRUE: // Inputting Track Number
        if(input_len < TRACK_MAX){
          bzero(temp_buffer,BUFFER_SIZE); // Fill buffer with NULL '\0'
          strncpy(temp_buffer,input_buffer,input_ptr);
          temp_buffer[input_ptr] = in_char;
          strcat(temp_buffer,&input_buffer[input_ptr]);
          strcpy(input_buffer,temp_buffer);
          input_len++;
          if((cursor_pos < DIGITS_MAX) && input_len < TRACK_MAX){
            move_cursor(RIGHT);
          }
          else{
            if(cursor_pos < TRACK_MAX-1){
              cursor_offset++;
            }
          }
        }
        break;
      default:
        break;
    }
  }
  display_input_buffer();
}
Beispiel #27
0
void monitor_print_dec(unsigned int n) {
    terminal_state_print_dec(monitor, n);
    move_cursor();
}
Beispiel #28
0
void monitor_print_int(int n) {
    terminal_state_print_int(monitor, n);
    move_cursor();
}
Beispiel #29
0
void monitor_print_str(char* str) {
    terminal_state_print_str(monitor, str);
    move_cursor();
}
Beispiel #30
0
void monitor_put(char c) {
    terminal_state_putchar(monitor, c);
    move_cursor();
}