Exemple #1
0
int amx_fflush(void)
{
    CONSOLE *con;
    if ((con=ActiveConsole())!=NULL && IsWindow(con->hwnd))
        UpdateWindow(con->hwnd);
    return 1;
}
Exemple #2
0
TCHAR *amx_gets(TCHAR *string,int size)
{
  int c=-1,num=0;

  if (ActiveConsole()!=NULL) {
    while (num+1<size && !(c==__T('\r') || c==__T('\n'))) {
      c=amx_getch();
      if (c<0)
        break;
      if (c==__T('\r'))
        c=__T('\n');    /* translate carriage return to newline */
      if (c==__T('\b')) {
        if (num>0)
          string[--num]=__T(' ');
      } else {
        string[num++]=(TCHAR)c;
      } /* if */
      amx_putchar(c);   /* echo the character read */
    } /* while */
    if (num<size)
      string[num]=__T('\0');
    return string;
  } /* if */

  return 0;
}
Exemple #3
0
int amx_termctl(int cmd,int value)
{
  switch (cmd) {
  case 0:
    return 1;           /* simple "is terminal support available" check */

  case 1: {
    CONSOLE *con;
    if ((con=ActiveConsole())!=NULL) {
      con->autowrap=(BOOL)value;
      return 1;
    } /* if */
    return 0;
  } /* case */

  case 2: {
    HWND hconsole=GetConsoleByIndex(value);
    while (hconsole==NULL) {
      CreateConsole(NULL,HWND_DESKTOP,DEFCOLUMNS,DEFWINLINES,DEFBUFFERLINES,DEFFONTHEIGHT,0);
      hconsole=GetConsoleByIndex(value);
    } /* while */
    return SetActiveConsole(hconsole);
  } /* case */

  case 3: {
    CONSOLE *con;
    if ((con=ActiveConsole())!=NULL) {
      con->boldfont=(BOOL)value;
      SetConsoleFont(con,con->cheight);
      return 1;
    } /* if */
    return 0;
  } /* case */

  case 4: {
    MSG msg;
    while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    } /* while */
    return (GetConsoleByIndex(value)!=NULL);
  } /* case */

  default:
    return 0;
  } /* switch */
}
Exemple #4
0
int amx_kbhit(void)
{
  CONSOLE *con;

  if ((con=ActiveConsole())!=NULL)
    return con->keyq_start!=con->keyq_end;
  return 0;
}
Exemple #5
0
void amx_wherexy(int *x,int *y)
{
  CONSOLE *con;
  if ((con=ActiveConsole())!=NULL) {
    if (x!=NULL)
      *x=con->csrx+1;
    if (y!=NULL)
      *y=con->csry+1;
  } /* if */
}
Exemple #6
0
void amx_gotoxy(int x,int y)
{
  CONSOLE *con;
  if ((con=ActiveConsole())!=NULL) {
    if (x>0 && x<=con->columns)
      con->csrx=x-1;
    if (y>0 && y<=con->lines)
      con->csry=y-1;
    RefreshScreen(con,0,0);
  } /* if */
}
Exemple #7
0
int amx_getch(void)
{
    CONSOLE *con;
    int c=-1;

    if ((con=ActiveConsole())!=NULL) {
        while (con->keyq_start==con->keyq_end)
            ProcessMessages();
        c=con->keyqueue[con->keyq_start];
        con->keyq_start=(con->keyq_start+1)%KEYQUEUE_SIZE;
    } /* if */
    return c;
}
Exemple #8
0
int amx_putchar(int c)
{
    CONSOLE *con;
    if ((con=ActiveConsole())!=NULL) {
        if (con->csry<con->lines && con->csrx<con->columns) {
            int pos=(con->csry*con->columns+con->csrx)*2;
            assert(con->buffer!=NULL);
            if (c==__T('\r')) {
                con->csrx=0;
            } else if (c==__T('\n')) {
                con->csrx=0;
                con->csry++;
                if (con->csry>=con->lines)
                    ScrollScreen(con,0,1);
            } else if (c==__T('\b')) {
                if (con->csrx>0) {
                    con->csrx--;
                    pos-=2;
                    con->buffer[pos]=__T(' ');
                    con->buffer[pos+1]=con->attrib;
                } /* if */
            } else if (c==__T('\t')) {
                while (con->csrx % 8!=0 && con->csrx<con->columns) {
                    con->buffer[pos]=' ';
                    con->buffer[pos+1]=con->attrib;
                    con->csrx+=1;
                    if (con->csrx>=con->columns && con->autowrap) {
                        con->csrx=0;
                        con->csry++;
                        if (con->csry>=con->lines)
                            ScrollScreen(con,0,1);
                    } /* if */
                } /* while */
            } else {
                con->buffer[pos]=(TCHAR)c;
                con->buffer[pos+1]=con->attrib;
                con->csrx+=1;
                if (con->csrx>=con->columns && con->autowrap) {
                    con->csrx=0;
                    con->csry++;
                    if (con->csry>=con->lines)
                        ScrollScreen(con,0,1);
                } /* if */
            } /* if */
            RefreshScreen(con,con->csry,con->csry+1);
        } /* if */
    } /* if */
    return 1;
}
Exemple #9
0
void amx_clreol(void)
{
  CONSOLE *con;
  if ((con=ActiveConsole())!=NULL) {
    int i;
    int size=(con->columns-con->csrx)*2;
    int pos=(con->csry*con->columns+con->csrx)*2;
    assert(con->buffer!=NULL);
    for (i=0; i<size; i+=2) {
      con->buffer[pos+i]=__T(' ');
      con->buffer[pos+i+1]=con->attrib;
    } /* for */
    RefreshScreen(con,con->csry,con->csry+1);
  } /* if */
}
Exemple #10
0
void amx_clrscr(void)
{
  CONSOLE *con;
  if ((con=ActiveConsole())!=NULL) {
    int i;
    int size=con->lines*con->columns*2;
    assert(con->buffer!=NULL);
    for (i=0; i<size; i+=2) {
      con->buffer[i]=__T(' ');
      con->buffer[i+1]=con->attrib;
    } /* for */
    con->csrx=con->csry=0;
    RefreshScreen(con,0,con->lines);
  } /* if */
}
Exemple #11
0
int amx_putstr(const TCHAR *string)
{
    CONSOLE *con;
    if ((con=ActiveConsole())!=NULL) {
        int pos, i;
        int top=con->csry;

        pos=(con->csry*con->columns+con->csrx)*2;
        assert(con->buffer!=NULL);
        for (i=0; string[i]!=__T('\0'); i++) {
            if (con->csry<con->lines && con->csrx<con->columns) {
                if (string[i]==__T('\r')) {
                    con->csrx=0;
                    pos=(con->csry*con->columns+con->csrx)*2;
                } else if (string[i]==__T('\n')) {
                    con->csrx=0;
                    con->csry++;
                    if (con->csry>=con->lines)
                        ScrollScreen(con,0,1);
                    pos=(con->csry*con->columns+con->csrx)*2;
                } else if (string[i]==__T('\b')) {
                    if (con->csrx>0) {
                        con->csrx--;
                        pos-=2;
                        con->buffer[pos]=__T(' ');
                        con->buffer[pos+1]=con->attrib;
                    } /* if */
                } else {
                    con->buffer[pos]=string[i];
                    con->buffer[pos+1]=con->attrib;
                    pos+=2;
                    con->csrx+=1;
                    if (con->csrx>=con->columns && con->autowrap) {
                        con->csrx=0;
                        con->csry++;
                        if (con->csry>=con->lines)
                            ScrollScreen(con,0,1);
                        pos=(con->csry*con->columns+con->csrx)*2;
                    } /* if */
                } /* if */
            } /* if */
        } /* for */
        RefreshScreen(con,top,con->csry+1);
    } /* if */
    return 0;
}
Exemple #12
0
int amx_getch(void)
{
  CONSOLE *con;
  int c=-1;

  if ((con=ActiveConsole())!=NULL) {
    MSG msg;
    while (con->keyq_start==con->keyq_end) {
      while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      } /* while */
    } /* while */
    c=con->keyqueue[con->keyq_start];
    con->keyq_start=(con->keyq_start+1)%KEYQUEUE_SIZE;
  } /* if */
  return c;
}
Exemple #13
0
unsigned int amx_setattr(int foregr,int backgr,int highlight)
{
  int prev=0;
  CONSOLE *con;
  if ((con=ActiveConsole())!=NULL) {
    int f,b,h;

    f=con->attrib & 0x07;
    b=(con->attrib >> 4) & 0x0f;
    h=(con->attrib & 0x08) ? 1 : 0;
    prev=(b << 8) | f | (h << 15);
    if (foregr>=0 && foregr<8)
      f=foregr;
    if (backgr>=0 && backgr<8)
      b=backgr;
    if (highlight>=0)
      h=highlight!=0;
    con->attrib=(TCHAR)((b << 4) | f | (h << 3));
  } /* if */