Пример #1
0
void InputReader::historyUp() {
    if (history.empty()) {
        std::cout << '\a' << std::flush;
        return;
    }
    if (in_tab_complete) {
        output = current_tab_val;
        in_tab_complete = false;
    }
    if (!in_history) {
        original_hist_val = output;
        original_hist_cursor_pos = cursor_pos;
        in_history = true;
        clearPrompt(output.size());
        hist_pos = history.size() - 1;
        current_hist_val = history.back();
        cursor_pos = current_hist_val.size();
        std::cout << current_hist_val << std::flush;
    } else {
        if (hist_pos > 0) {
            hist_pos--;
            clearPrompt(current_hist_val.size());
            current_hist_val = history.at((unsigned)hist_pos);
            cursor_pos = current_hist_val.size();
            std::cout << current_hist_val << std::flush;
        } else {
            std::cout << '\a' << std::flush;
        }
    }
}
Пример #2
0
void InputReader::tabComplete() {
    if (in_history) {
        output = current_hist_val;
        in_history = false;
    }
    if (!in_tab_complete) {
        current_tab_completes = std::vector<std::string>();
        original_tab_val = output;
        bool found_tab = false;
        for (auto& a : tab_completion) {
            if (a.find(original_tab_val) == 0) {
                current_tab_completes.push_back(a);
                found_tab = true;
            }
        }
        if (!found_tab) {
            std::cout << '\a' << std::flush;
            return;
        } else {
            in_tab_complete = true;
            tab_pos = 0;
            current_tab_val = current_tab_completes.at((unsigned)tab_pos);
            clearPrompt(output.size());

            cursor_pos = current_tab_val.size();
            std::cout << current_tab_val << std::flush;
        }
    } else {
        if (tab_pos + 1 >= current_tab_completes.size()) {
            clearPrompt(current_tab_val.size());
            current_tab_val = original_tab_val;
            in_tab_complete = false;
            cursor_pos = output.size();
            std::cout << output << std::flush;
        } else {
            tab_pos++;

            clearPrompt(current_tab_val.size());
            current_tab_val = current_tab_completes.at((unsigned)tab_pos);

            cursor_pos = current_tab_val.size();
            std::cout << current_tab_val << std::flush;
        }
    }
}
Пример #3
0
void InputReader::showFullText(std::string text) {
    clearPrompt(text.size());
    for (unsigned long i = 0; i < text.size(); i++) {
        std::cout << text.at(i) << std::flush;
    }

    for (unsigned long i = (unsigned)cursor_pos; i < text.size(); i++) {
        std::cout << "\b" << std::flush;
    }
}
Пример #4
0
void InputReader::historyDown() {
    if (in_history) {
        clearPrompt(current_hist_val.size());
        if (hist_pos + 1 < history.size()) {
            hist_pos++;
            current_hist_val = history.at((unsigned)hist_pos);
            cursor_pos = current_hist_val.size();
            std::cout << current_hist_val << std::flush;
        } else {
            in_history = false;
            cursor_pos = original_hist_cursor_pos;
            std::cout << original_hist_val << std::flush;
        }
    } else {
        std::cout << '\a' << std::flush;
    }
}
Пример #5
0
int main(int argc, char *argv[]) {
   
	/* handle arguments */
	if(argc != 4) {
		printf("Incorrect arguments, please use:\n./client server port username\n");
		return 1;
	}

	raw_mode(); 

	memset(liveChannel, '\0', CHANNEL_MAX);
	char * address = argv[1];
	char * port = argv[2];
	char * username = argv[3];

	/* Build Socket we pass the function the address and port */
	if(buildSocket(address, port) != true) {
		cooked_mode();
		return 1;
	}

	/* Handle Login */
	if(login(username) != true) {
		cooked_mode();
		return 1;
	}

	int parseStatus = true;
	char * input;
	fd_set readfds;

	promptUser();

	do {
		FD_ZERO(&readfds);
		FD_SET(0, &readfds);
		FD_SET(socketfd, &readfds);
		select(socketfd+1, &readfds, NULL, NULL, NULL);

		if(FD_ISSET(0, &readfds)) {

			input = inputString();


			if(input != NULL) {

				/* Parse Input */

			
				parseStatus = parseInput(input);

				if(parseStatus != -1) { 
					promptUser();
				}
			}

		} else if (FD_ISSET(socketfd, &readfds)) { 

			struct text * text = (struct text *) malloc(sizeof(struct text) + 1024);
			int bytes = 0;

			if((bytes = recvfrom(socketfd, text, 1024, 0,servinfo->ai_addr, &servinfo->ai_addrlen)) > 0) {
			
				clearPrompt();
				switchResp(text);
				free(text);
			
			}

		}	

	} while(parseStatus != -1);
	
	freeaddrinfo(servinfo);

	cooked_mode();
	return 0;
}
Пример #6
0
void main(void) 
{
    // initialise the RTC communication line
    I2C_Init() ;
    // initialise the LCD display
    LCDInit(LS_NONE);
    // initialise the actual RTC
    DS1307_Init() ;

    //clear the display
    LCDClear();
    
    // read back our running time
    DS1307_readRam(&runningMinutes,0,2) ;
    DS1307_readRam(&runningHours,2,2) ;
    
    LCDWriteString("Starting counter");
    LCDGotoXY(0,1) ;
    LCDWriteString("at ");
    LCDWriteInt(runningHours,1);
    LCDWriteString(":");
    LCDWriteInt(runningMinutes,1);
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;

    // compensate for our handling on the first run of the readClock routine
    runningMinutes-- ;

    LCDClear();
    // infinite loop, read the clock, display on the LCD, check for the button, and if needed, process the menus
   while(1)
  {       
      readClock();
      
      showClock() ;           
      
      readInputs() ;
      
      if (bButton)
        doMenu();
      else if (state & 0x30)
      {
          // rotate the encoder to select a menu function, well, that was the aim, but encoder reading
          // seems a tad slow or inaccurate.
          //
          // there is a timeout if the button isn't pressed after selecting the menu option
          
          if (state & DIR_CW)
          {
              menuFunction++ ;
              if (menuFunction == MENU_LAST)
                  menuFunction = MENU_NONE ;
          }
          else if (state & DIR_CCW)
          {
              menuFunction-- ;
              if (menuFunction < MENU_NONE)
                  menuFunction = MENU_LAST-1 ;
          }
          
          if (menuFunction != MENU_NONE)
          {
              next_menu_clear = minute * 60 + seconds + 20 ;
              LCDGotoXY(9,0);
              if (menuFunction == MENU_TIME)
                LCDWriteString("Time ?");
              if (menuFunction == MENU_DATE)
                LCDWriteString("Date ?");
          }
          else
              clearPrompt();
      }
      else if (next_menu_clear && ((minute * 60 + seconds) > next_menu_clear))
      {
          clearPrompt();
      }
  }
}