Open main menu

CDOT Wiki β

Console startup oop344 - 20123

Tester:

#include "console.h"
using namespace cio;

int main(){
  char text[41] = "Hello how are you this morning!";
  bool insertMode = true;
  int curpos = 8;
  int offset = 10;
  console.setPos(10, 20);
  console<<"*****************";
  console.setPos(11, 20);
  console<<"*****************";
  console.setPos(12, 20);
  console<<"*****************";
  console.edit(text, 11, 21, 15, 40, &insertMode, &offset, &curpos, false, false);
  console.setPos(15,20);
  console<<text;
  console.pause();
  return 0;
}

console.edit()

  int  Console::edit(char* str, int row, int col, 
            int fieldLength, int maxStrLength, 
            bool* insertMode, int* strOffset, int* curPosition,  
            bool IsTextEditor, bool ReadOnly){
    bool done = false;
    int key = 0;
    while(!done){
      // displaying the interface
      display(str + *strOffset, row, col, fieldLength);
      setPos(row, col + *curPosition);
      // end displaying the interface
      switch(key = getKey()){
      case LEFT:
        if(*curPosition > 0){
          (*curPosition)--;
        }
        else if(*strOffset > 0){
          (*strOffset)--;
        }
        else{
          // beep
        }
        break;
      case INSERT:
        //if(*insertMode){
        //  *insertMode = false;
        //}
        //else{
        //  *insertMode = true;
        //}
        *insertMode = !(*insertMode);
        break;
      case HOME:
        *strOffset = *curPosition = 0;
        break;
      case ESCAPE:
        done = true;
        break;
      default:
        if(key >=32 && key <= 126){  // I have a printable character to work with
          if(*insertMode){ // edit in insert mode

          }
          else{ // edit in overstrike mode
            if(max string lenght is not reached){
              str[*strOffset + *curPosition] = key;
              if(the cursor is not at the end of the field){
                (*curPosition)++;
              }
              else if(MaxStrlen is not reached){
                (*strOffset)++;
              }
            }
          }
        }
      }
    }
    return 0;
  }