[ansi] Support for more escape sequences.

This commit is contained in:
Kevin Lange 2011-04-15 21:48:20 -05:00
parent d9a6c37e17
commit d2ff4c474e
7 changed files with 128 additions and 10 deletions

View File

@ -15,7 +15,7 @@ MODULES = $(patsubst %.c,%.o,$(wildcard kernel/core/*.c))
FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/core/fs/*.c))
VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/core/video/*.c))
BINARIES = initrd/bin/hello initrd/bin/echo initrd/bin/yes
UTILITIES = util/bin/readelf
UTILITIES = util/bin/readelf util/bin/typewriter
EMU = qemu
GENEXT = genext2fs
DD = dd conv=notrunc
@ -99,12 +99,7 @@ initrd/boot/kernel: toaruos-kernel
# Utilities #
################
util/bin/mrboots-installer: util/mrboots-installer.c
@${ECHO} -n "\033[32m CC $<\033[0m"
@${CC} ${NATIVEFLAGS} -o $@ $<
@${ECHO} "\r\033[32;1m CC $<\033[0m"
util/bin/readelf: util/readelf.c
util/bin/%: util/%.c
@${ECHO} -n "\033[32m CC $<\033[0m"
@${CC} ${NATIVEFLAGS} -o $@ $<
@${ECHO} "\r\033[32;1m CC $<\033[0m"

1
initrd/etc/.htop Normal file

File diff suppressed because one or more lines are too long

View File

@ -128,7 +128,7 @@ start_shell() {
size_t bytes_read = read_fs(file, 0, file->length, (uint8_t *)bufferb);
size_t i = 0;
for (i = 0; i < bytes_read; ++i) {
ansi_put(bufferb[i]);
kprintf("%c", bufferb[i]);
}
free(bufferb);
close_fs(file);

View File

@ -12,7 +12,7 @@
#define ANSI_BRACKET '['
/* Anything in this range (should) exit escape mode. */
#define ANSI_LOW 'A'
#define ANSI_HIGH 'u'
#define ANSI_HIGH 'z'
/* Escape commands */
#define ANSI_CUU 'A' /* CUrsor Up */
#define ANSI_CUD 'B' /* CUrsor Down */
@ -153,9 +153,12 @@ ansi_put(
} else if (arg >= 40 && arg < 50) {
/* Set background */
state.bg = arg - 40;
} else if (arg >= 30 && arg < 40) {
} else if (arg >= 30 && arg < 39) {
/* Set Foreground */
state.fg = arg - 30;
} else if (arg == 39) {
/* Default Foreground */
state.fg = 7;
} else if (arg == 20) {
/* FRAKTUR: Like old German stuff */
state.flags |= ANSI_FRAKTUR;
@ -187,6 +190,58 @@ ansi_put(
}
}
break;
case ANSI_SHOW:
if (!strcmp(argv[0], "?1049")) {
cls();
bochs_set_csr(0,0);
}
break;
case ANSI_CUP:
if (argc < 2) {
bochs_set_csr(0,0);
break;
}
bochs_set_csr(atoi(argv[1]) - 1, atoi(argv[0]) - 1);
break;
case ANSI_EL:
{
int what = 0, x = 0, y = 0;
if (argc >= 1) {
what = atoi(argv[0]);
}
if (what == 0) {
x = bochs_get_csr_x();
y = bochs_get_width();
} else if (what == 1) {
x = 0;
y = bochs_get_csr_x();
} else if (what == 2) {
x = 0;
y = bochs_get_width();
}
for (int i = x; i < y; ++i) {
bochs_set_cell(i, bochs_get_csr_y(), ' ');
}
}
break;
case 'X':
{
int how_many = 1;
if (argc >= 1) {
how_many = atoi(argv[0]);
}
for (int i = 0; i < how_many; ++i) {
ansi_writer(' ');
}
}
break;
case 'd':
if (argc < 1) {
bochs_set_csr(bochs_get_csr_x(), 0);
} else {
bochs_set_csr(bochs_get_csr_x(), atoi(argv[0]) - 1);
}
break;
default:
/* Meh */
break;

View File

@ -38,6 +38,7 @@ static uint8_t * term_buffer;
static uint8_t current_fg = 7;
static uint8_t current_bg = 0;
static uint16_t current_scroll = 0;
static uint8_t cursor_on = 1;
void
bochs_set_y_offset(uint16_t y) {
@ -307,6 +308,7 @@ void bochs_reset_colors() {
}
void draw_cursor() {
if (!cursor_on) return;
for (uint32_t x = 0; x < 8; ++x) {
bochs_set_point(csr_x * 8 + x, csr_y * 12 + 11, bochs_colors[current_fg]);
}
@ -323,6 +325,9 @@ void bochs_write(char c) {
}
csr_x = 0;
++csr_y;
} else if (c == '\r') {
cell_redraw(csr_x,csr_y);
csr_x = 0;
} else if (c == '\b') {
--csr_x;
cell_set(csr_x, csr_y, ' ',current_fg, current_bg, 0);
@ -365,3 +370,41 @@ void bochs_draw_line(uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1, uint32_
}
}
}
void
bochs_set_csr(int x, int y) {
cell_redraw(csr_x,csr_y);
csr_x = x;
csr_y = y;
}
int
bochs_get_csr_x() {
return csr_x;
}
int
bochs_get_csr_y() {
return csr_y;
}
void
bochs_set_csr_show(uint8_t on) {
cursor_on = on;
}
int
bochs_get_width() {
return bochs_resolution_x / 8;
}
int
bochs_get_height() {
return bochs_resolution_y / 12;
}
void
bochs_set_cell(int x, int y, char c) {
cell_set(x, y, c, current_fg, current_bg, 0);
cell_redraw(x, y);
}

View File

@ -249,6 +249,10 @@ extern int detect_cpu();
/* Video Drivers */
/* BOCHS / QEMU VBE Driver */
extern void graphics_install_bochs();
extern void bochs_set_csr(int x, int y);
extern int bochs_get_csr_x();
extern int bochs_get_csr_y();
extern void bochs_set_csr_on(uint8_t);
extern void bochs_set_bank(uint16_t bank);
extern void bochs_set_coord(uint16_t x, uint16_t y, uint32_t color);
extern void bochs_fill_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color);
@ -267,6 +271,9 @@ extern void bochs_write(char c);
extern void bochs_reset_colors();
extern void bochs_set_colors(uint8_t, uint8_t);
extern void bochs_draw_line(uint16_t,uint16_t,uint16_t,uint16_t,uint32_t);
extern int bochs_get_width();
extern int bochs_get_height();
extern void bochs_set_cell(int x, int y, char c);
/* ANSI Terminal Escape Processor */
void ansi_put(char c);

17
util/typewriter.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv) {
if (argc < 3) { return -1; }
FILE * f = fopen(argv[2],"r");
char * buffer = malloc(sizeof(char) * 1);
while (!feof(f)) {
fread(buffer, 1, 1, f);
printf("%c", buffer[0]);
fflush(stdout);
usleep(atoi(argv[1]));
}
fclose(f);
return 0;
}