| 1 |
/***************************************************************************
|
| 2 |
screen.c - description
|
| 3 |
-------------------
|
| 4 |
begin : Mon Oct 18 2004
|
| 5 |
copyright : (C) 2004 by Leaflet
|
| 6 |
email : leaflet@leafok.com
|
| 7 |
***************************************************************************/
|
| 8 |
|
| 9 |
/***************************************************************************
|
| 10 |
* *
|
| 11 |
* This program is free software; you can redistribute it and/or modify *
|
| 12 |
* it under the terms of the GNU General Public License as published by *
|
| 13 |
* the Free Software Foundation; either version 2 of the License, or *
|
| 14 |
* (at your option) any later version. *
|
| 15 |
* *
|
| 16 |
***************************************************************************/
|
| 17 |
|
| 18 |
#include "io.h"
|
| 19 |
|
| 20 |
void
|
| 21 |
moveto (int row, int col)
|
| 22 |
{
|
| 23 |
if (row >= 0)
|
| 24 |
{
|
| 25 |
prints ("\033[%d;%dH", row, col);
|
| 26 |
}
|
| 27 |
else
|
| 28 |
{
|
| 29 |
prints ("\r");
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
void
|
| 34 |
clrtoeol ()
|
| 35 |
{
|
| 36 |
prints ("\033[K");
|
| 37 |
}
|
| 38 |
|
| 39 |
int
|
| 40 |
str_input (char *buffer, int buffer_length, int echo_mode)
|
| 41 |
{
|
| 42 |
char buf[256], ch;
|
| 43 |
int c, offset = 0, len, loop = 1, i, hz = 0;
|
| 44 |
|
| 45 |
memset (buffer, '\0', buffer_length);
|
| 46 |
|
| 47 |
while (c = igetch ())
|
| 48 |
{
|
| 49 |
if (c == CR || c == LF)
|
| 50 |
break;
|
| 51 |
if (c == BACKSPACE)
|
| 52 |
{
|
| 53 |
if (offset > 0)
|
| 54 |
{
|
| 55 |
buffer[--offset] = '\0';
|
| 56 |
prints ("\b \b");
|
| 57 |
// clrtoeol ();
|
| 58 |
iflush ();
|
| 59 |
}
|
| 60 |
continue;
|
| 61 |
}
|
| 62 |
if (c > 255 || iscntrl (c))
|
| 63 |
{
|
| 64 |
continue;
|
| 65 |
}
|
| 66 |
if (c > 127 && c <= 255)
|
| 67 |
{
|
| 68 |
hz = (!hz);
|
| 69 |
}
|
| 70 |
if (offset >= buffer_length)
|
| 71 |
{
|
| 72 |
outc ('\a');
|
| 73 |
continue;
|
| 74 |
}
|
| 75 |
buffer[offset++] = (char) c;
|
| 76 |
buffer[offset] = '\0';
|
| 77 |
switch (echo_mode)
|
| 78 |
{
|
| 79 |
case 0:
|
| 80 |
outc ((char) c);
|
| 81 |
break;
|
| 82 |
case 1:
|
| 83 |
outc ('*');
|
| 84 |
break;
|
| 85 |
}
|
| 86 |
if (!hz)
|
| 87 |
{
|
| 88 |
iflush ();
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
prints ("\r\n");
|
| 93 |
iflush ();
|
| 94 |
|
| 95 |
return offset;
|
| 96 |
}
|
| 97 |
|
| 98 |
int
|
| 99 |
display_file(const char* filename)
|
| 100 |
{
|
| 101 |
char buffer[256];
|
| 102 |
FILE *fin;
|
| 103 |
|
| 104 |
if ((fin = fopen(filename, "r")) != NULL)
|
| 105 |
{
|
| 106 |
while (fgets(buffer, 255, fin))
|
| 107 |
{
|
| 108 |
prints (buffer);
|
| 109 |
iflush ();
|
| 110 |
}
|
| 111 |
fclose (fin);
|
| 112 |
|
| 113 |
return 0;
|
| 114 |
}
|
| 115 |
|
| 116 |
return -1;
|
| 117 |
}
|
| 118 |
|
| 119 |
int
|
| 120 |
show_top()
|
| 121 |
{
|
| 122 |
return 0;
|
| 123 |
}
|
| 124 |
|
| 125 |
int
|
| 126 |
show_bottom()
|
| 127 |
{
|
| 128 |
return 0;
|
| 129 |
}
|