réplica de
https://github.com/Arnau478/quark.git
synced 2024-11-23 12:58:07 +01:00
ANSI text coloring
This commit is contained in:
pare
b941e48f4b
commit
7f48dc6a17
S'han modificat 3 arxius amb 36 adicions i 5 eliminacions
|
@ -1,7 +1,7 @@
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
#include "../arch/i686/io.h"
|
#include "../arch/i686/io.h"
|
||||||
|
|
||||||
static uint8_t current_color = VGA_COLOR_BG_BLACK | VGA_COLOR_FG_WHITE;
|
static uint8_t current_color = VGA_COLOR_DEFAULT;
|
||||||
|
|
||||||
void set_char(int x, int y, char c){
|
void set_char(int x, int y, char c){
|
||||||
VGA_MEMORY[(x+y*VGA_WIDTH)*2] = c;
|
VGA_MEMORY[(x+y*VGA_WIDTH)*2] = c;
|
||||||
|
@ -77,11 +77,40 @@ void print_string_at(char *str, int x, int y){
|
||||||
}
|
}
|
||||||
|
|
||||||
while(*str){
|
while(*str){
|
||||||
|
if(*str == '\x1b'){
|
||||||
|
str++;
|
||||||
|
if(*str != '[') continue;
|
||||||
|
str++;
|
||||||
|
int ansi_col = 0;
|
||||||
|
while(*str >= '0' && *str <= '9'){
|
||||||
|
ansi_col *= 10;
|
||||||
|
ansi_col += *str - '0';
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
if(*str != 'm') continue;
|
||||||
|
str++;
|
||||||
|
if(ansi_col == 0) current_color = VGA_COLOR_DEFAULT;
|
||||||
|
else if(ansi_col >= 30 && ansi_col <= 37){
|
||||||
|
switch (ansi_col)
|
||||||
|
{
|
||||||
|
case 30: current_color = (current_color & 0xf0) | VGA_COLOR_FG_BLACK; break;
|
||||||
|
case 31: current_color = (current_color & 0xf0) | VGA_COLOR_FG_RED; break;
|
||||||
|
case 32: current_color = (current_color & 0xf0) | VGA_COLOR_FG_GREEN; break;
|
||||||
|
case 33: current_color = (current_color & 0xf0) | VGA_COLOR_FG_ORANGE; break;
|
||||||
|
case 34: current_color = (current_color & 0xf0) | VGA_COLOR_FG_BLUE; break;
|
||||||
|
case 35: current_color = (current_color & 0xf0) | VGA_COLOR_FG_PINK; break;
|
||||||
|
case 36: current_color = (current_color & 0xf0) | VGA_COLOR_FG_CYAN; break;
|
||||||
|
case 37: current_color = (current_color & 0xf0) | VGA_COLOR_FG_WHITE; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
offset = print_char(*(str++), x, y);
|
offset = print_char(*(str++), x, y);
|
||||||
x = get_offset_x(offset);
|
x = get_offset_x(offset);
|
||||||
y = get_offset_y(offset);
|
y = get_offset_y(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void print_string(char *str){
|
void print_string(char *str){
|
||||||
print_string_at(str, -1, -1);
|
print_string_at(str, -1, -1);
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#define VGA_MEMORY ((char *)0xB8000)
|
#define VGA_MEMORY ((char *)0xB8000)
|
||||||
|
|
||||||
|
#define VGA_COLOR_DEFAULT (VGA_COLOR_BG_BLACK | VGA_COLOR_FG_WHITE)
|
||||||
|
|
||||||
#define VGA_COLOR_FG_BLACK 0x00
|
#define VGA_COLOR_FG_BLACK 0x00
|
||||||
#define VGA_COLOR_FG_BLUE 0x01
|
#define VGA_COLOR_FG_BLUE 0x01
|
||||||
#define VGA_COLOR_FG_GREEN 0x02
|
#define VGA_COLOR_FG_GREEN 0x02
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
#include "drivers/vga.h"
|
#include "drivers/vga.h"
|
||||||
|
|
||||||
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
|
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
|
||||||
print_string("Hello world!\n:D");
|
print_string("Hello world!\n\x1b[32m:D\x1b[0m\n");
|
||||||
for(;;); // Halt here
|
for(;;); // Halt here
|
||||||
}
|
}
|
||||||
|
|
Loading…
Referencia en una nova incidència