Local echo on / off via ansi code

This commit is contained in:
Andrew Pamment 2021-12-05 11:42:57 +10:00
parent d99326541e
commit c2fec4cfb9
7 changed files with 59 additions and 11 deletions

View File

@ -671,6 +671,25 @@ void putdata(char *str, int len) {
}
state = 0;
break;
case 'h':
if (params[0] == 12) {
if (consoletty != 0) {
((struct tty_dev_data *)consoletty->fs_data)->echo = 0;
}
}
state = 0;
break;
case 'i':
if (params[0] == 12) {
if (consoletty != 0) {
((struct tty_dev_data *)consoletty->fs_data)->echo = 1;
}
}
state = 0;
break;
default:
state = 0;
break;
}
}
}

View File

@ -28,6 +28,8 @@ unsigned char attrib;
int term_x;
int term_y;
int echo = 1;
unsigned int char_width, char_height;
char *cursor_save_buffer;
@ -433,6 +435,21 @@ void process_char(char c) {
update_cursor(1);
state = 0;
break;
case 'h':
if (params[0] == 12) {
echo = 0;
}
state = 0;
break;
case 'i':
if (params[0] == 12) {
echo = 1;
}
state = 0;
break;
default:
state = 0;
break;
}
}
}
@ -444,6 +461,9 @@ void exit_callback(int wh) {
void input_char(char c) {
write(ParentWrite, &c, 1);
if (echo) {
process_char(c);
}
}
char *sargv[] = {"shell.exe", NULL};

View File

@ -197,7 +197,7 @@ int main(int argc, char **argv) {
}
socket = socket_open(SOCK_TYPE_TCP);
printf("Connecting to %s:%d\n", argv[1], port);
printf("\x1b[12hConnecting to %s:%d\n", argv[1], port);
if (socket_connect(socket, server, port) == 0) {
raw("USER %s 0 0 :%s\r\n", nick, nick);
raw("NICK %s\r\n", nick);
@ -388,5 +388,6 @@ int main(int argc, char **argv) {
printf("Unable to connect!\n");
return -1;
}
printf("\x1b[12i");
return 0;
}

View File

@ -44,7 +44,7 @@ int main(int argc, char **argv) {
}
socket = socket_open(SOCK_TYPE_TCP);
printf("Connecting to %s:%d\n", argv[1], port);
printf("\x1b[12hConnecting to %s:%d\n", argv[1], port);
if (socket_connect(socket, server, port) == 0) {
while ((sl = socket_read_noblock(socket, sbuf, 512)) != 0) {
@ -68,6 +68,6 @@ int main(int argc, char **argv) {
}
socket_close(socket);
}
printf("\x1b[12i");
return 0;
}

View File

@ -135,7 +135,7 @@ int main(int argc, char **argv) {
}
}
printf("\e[1;31mQUINN\e[0m User Shell\n");
printf("\e[12h\e[1;31mQUINN\e[0m User Shell\n");
while (!doexit) {
memset(cmd, 0, 256);
@ -404,4 +404,5 @@ int main(int argc, char **argv) {
memset(cmd, 0, 256);
}
printf("\e[12i");
}

View File

@ -7,12 +7,6 @@
char tty_buf[TTY_BUF_SIZE];
struct tty_dev_data {
int tty_buf_at;
char tty_buf[TTY_BUF_SIZE];
void (*tty_write)(char *data, int len);
};
void tty_input(struct vfs_device_t *device, char c) {
if (device != (void *)0) {
struct tty_dev_data *data = (struct tty_dev_data *)device->fs_data;
@ -20,6 +14,9 @@ void tty_input(struct vfs_device_t *device, char c) {
return;
}
data->tty_buf[data->tty_buf_at++] = c;
if (data->echo == 1) {
data->tty_write(&c, 1); // ECHO ON!
}
}
}
@ -58,8 +55,9 @@ int tty_init(struct vfs_device_t *device) {
data->tty_buf_at = 0;
data->tty_write = putdata;
data->echo = 1;
device->fs_data = (void *)data;
return 1;
}
}

View File

@ -4,6 +4,15 @@
#include "vfs.h"
#define TTY_BUF_SIZE 256
struct tty_dev_data {
int tty_buf_at;
char tty_buf[TTY_BUF_SIZE];
void (*tty_write)(char *data, int len);
unsigned char echo;
};
extern void tty_input(struct vfs_device_t *device, char c);
extern int tty_write_data(struct vfs_device_t *device, char *buffer, int len, int offset);
extern int tty_read_data(struct vfs_device_t *device, char *buffer, int len, int offset);