18void kprintf(
const char *fmt, ...) {
29 unsigned int index = 0;
30 bool isDimmed =
false;
32 for (index = 0; index <
strlen(fmt); index++) {
37 if (fmt[index] ==
'\033') {
40 if (fmt[index] ==
'[') {
44 unsigned int format_start_index = index;
48 #define ANSI_TEXT_EFFECT 1
50 unsigned int format_type = ANSI_NONE;
52 while (index <
strlen(fmt)) {
55 format_type = ANSI_TEXT_EFFECT;
63 if (format_type != ANSI_NONE)
break;
66 index = format_start_index;
68 if (format_type != ANSI_NONE) {
69 if (format_type == ANSI_TEXT_EFFECT) {
71 ansi_text_effect_format:
76 switch (fmt[index - 1]) {
118 switch (fmt[index]) {
150 switch (fmt[index]) {
183 switch (fmt[index]) {
187 switch (fmt[index]) {
236 switch (fmt[index]) {
261 if (fmt[index] ==
';') {
264 goto ansi_text_effect_format;
275 if (fmt[index] !=
'%') {
282 unsigned int starting_index = index;
289 while (fmt[index] >=
'0' && fmt[index] <=
'9') {
290 len = (len * 10) + (((uint8_t)fmt[index]) -
'0');
294 while (l_count < 2) {
295 if (fmt[index] ==
'l') {
304 switch (fmt[index]) {
306 kputc((
char) va_arg(ap,
int));
309 const char *str = va_arg(ap,
const char*);
312 for (
unsigned int j = 0; j <
strlen(str); j++) {
382 void *value = va_arg(ap,
void *);
388 char *str =
"(null)";
389 for (
unsigned int j = 0; j <
strlen(str); j++) {
398 for (
unsigned int j = starting_index; j <= index; j++) {
415void print_unsigned(
unsigned long long value, uint8_t base,
bool uppercase, uint8_t _length) {
416 if (base > 36)
return;
419 char *digits =
"0123456789abcdefghijklmnopqrstuvwxyz";
421 digits =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
423 unsigned long long next = value;
437 uint64_t length = _length > index ? _length : index;
440 for (
int i = 0; i < length; i++)
450 chars[index] = digits[next % base];
458 index = _length <= 0 ? 1 : _length;
459 }
else index = length;
461 for (
int i = index - 1; i >= 0; i--) {
467 unsigned long long magnitude;
471 magnitude = 0 - (
unsigned long long)value;
struct rgb add_rgb(struct rgb a, struct rgb b)
Adds two RGB color values.
struct rgb sub_rgb(struct rgb a, struct rgb b)
Subtracts the second RGB color from the first.
void set_bg_color(struct rgb color)
Sets the background colour.
void console_putc(char c)
Arranges the cursor and prints characters.
struct rgb get_default_bg_color(void)
Gets the default bg colour.
bool get_console_status(void)
Returns the status of the console (initialized or uninitialized).
struct rgb get_fg_color(void)
Gets the current fg colour.
struct rgb get_bg_color(void)
Gets the current bg colour.
struct rgb get_default_fg_color(void)
Gets the default fg colour.
void set_fg_color(struct rgb color)
Sets the foreground colour.
Console utilities and configuration.
Provides utilities for IO operations with the hardware.
void kputc(char c)
Sends characters to print in the console and serial.
void print_signed(long long value, uint8_t len)
Prepares a signed number to be printed through the unsigned print.
void kvprintf(const char *fmt, va_list ap)
Handles printing a formatted string.
void print_unsigned(unsigned long long value, uint8_t base, bool uppercase, uint8_t _length)
Prints unsigned integers of any base lower than base 36.
Tools for printing to the console and serial output.
void kprintf(const char *fmt,...) __attribute__((format(printf
Wrapper for a standard print.
Utilities for memory and string operations.
size_t strlen(const char *str)
Calculates the length of a string.
bool get_serial_status(void)
Returns the status of the serial output (enabled or disabled).
void serial_putc(char c)
Prints a character to serial port.
Serial utilities and configuration.