Color theming
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#ifndef BUFFER_H_
|
||||
#define BUFFER_H_
|
||||
|
||||
#include "data.h"
|
||||
|
||||
int new_buffer(enum buffer_type type, char * filename, int width, int height);
|
||||
|
||||
#endif
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
#ifndef COLOR_H_
|
||||
#define COLOR_H_
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// TEXT STYLES / ATTRIBUTES
|
||||
// ============================================================================
|
||||
#define ANSI_RESET "\x1b[0m" // Reset all attributes
|
||||
#define ANSI_BOLD "\x1b[1m" // Bold text
|
||||
#define ANSI_DIM "\x1b[2m" // Dim/faint text
|
||||
#define ANSI_ITALIC "\x1b[3m" // Italic text
|
||||
#define ANSI_UNDERLINE "\x1b[4m" // Underline text
|
||||
#define ANSI_BLINK "\x1b[5m" // Blinking text
|
||||
#define ANSI_REVERSE "\x1b[7m" // Reverse video (invert colors)
|
||||
#define ANSI_HIDDEN "\x1b[8m" // Hidden/invisible text
|
||||
#define ANSI_STRIKETHROUGH "\x1b[9m" // Strikethrough text
|
||||
|
||||
// ============================================================================
|
||||
// FOREGROUND COLORS (30-37 standard, 90-97 bright)
|
||||
// ============================================================================
|
||||
#define ANSI_BLACK "\x1b[30m"
|
||||
#define ANSI_RED "\x1b[31m"
|
||||
#define ANSI_GREEN "\x1b[32m"
|
||||
#define ANSI_YELLOW "\x1b[33m"
|
||||
#define ANSI_BLUE "\x1b[34m"
|
||||
#define ANSI_MAGENTA "\x1b[35m"
|
||||
#define ANSI_CYAN "\x1b[36m"
|
||||
#define ANSI_WHITE "\x1b[37m"
|
||||
|
||||
// Bright/Light foreground colors (90-97)
|
||||
#define ANSI_BRIGHT_BLACK "\x1b[90m"
|
||||
#define ANSI_BRIGHT_RED "\x1b[91m"
|
||||
#define ANSI_BRIGHT_GREEN "\x1b[92m"
|
||||
#define ANSI_BRIGHT_YELLOW "\x1b[93m"
|
||||
#define ANSI_BRIGHT_BLUE "\x1b[94m"
|
||||
#define ANSI_BRIGHT_MAGENTA "\x1b[95m"
|
||||
#define ANSI_BRIGHT_CYAN "\x1b[96m"
|
||||
#define ANSI_BRIGHT_WHITE "\x1b[97m"
|
||||
|
||||
// ============================================================================
|
||||
// BACKGROUND COLORS (40-47 standard, 100-107 bright)
|
||||
// ============================================================================
|
||||
#define ANSI_BG_BLACK "\x1b[40m"
|
||||
#define ANSI_BG_RED "\x1b[41m"
|
||||
#define ANSI_BG_GREEN "\x1b[42m"
|
||||
#define ANSI_BG_YELLOW "\x1b[43m"
|
||||
#define ANSI_BG_BLUE "\x1b[44m"
|
||||
#define ANSI_BG_MAGENTA "\x1b[45m"
|
||||
#define ANSI_BG_CYAN "\x1b[46m"
|
||||
#define ANSI_BG_WHITE "\x1b[47m"
|
||||
|
||||
// Bright/Light background colors (100-107)
|
||||
#define ANSI_BG_BRIGHT_BLACK "\x1b[100m"
|
||||
#define ANSI_BG_BRIGHT_RED "\x1b[101m"
|
||||
#define ANSI_BG_BRIGHT_GREEN "\x1b[102m"
|
||||
#define ANSI_BG_BRIGHT_YELLOW "\x1b[103m"
|
||||
#define ANSI_BG_BRIGHT_BLUE "\x1b[104m"
|
||||
#define ANSI_BG_BRIGHT_MAGENTA "\x1b[105m"
|
||||
#define ANSI_BG_BRIGHT_CYAN "\x1b[106m"
|
||||
#define ANSI_BG_BRIGHT_WHITE "\x1b[107m"
|
||||
|
||||
// ============================================================================
|
||||
// 256-COLOR MODE (for more colors)
|
||||
// ============================================================================
|
||||
// Foreground: \x1b[38;5;Nm where N is 0-255
|
||||
// Background: \x1b[48;5;Nm where N is 0-255
|
||||
// Example macros:
|
||||
#define ANSI_FG_256(N) "\x1b[38;5;" #N "m"
|
||||
#define ANSI_BG_256(N) "\x1b[48;5;" #N "m"
|
||||
|
||||
// ============================================================================
|
||||
// TRUE COLOR / 24-BIT COLOR (RGB)
|
||||
// ============================================================================
|
||||
// Foreground: \x1b[38;2;R;G;Bm
|
||||
// Background: \x1b[48;2;R;G;Bm
|
||||
// Example macros:
|
||||
#define ANSI_FG_RGB(R,G,B) "\x1b[38;2;" #R ";" #G ";" #B "m"
|
||||
#define ANSI_BG_RGB(R,G,B) "\x1b[48;2;" #R ";" #G ";" #B "m"
|
||||
|
||||
// ============================================================================
|
||||
// CURSOR MOVEMENT
|
||||
// ============================================================================
|
||||
#define ANSI_CURSOR_UP(N) "\x1b[" #N "A" // Move up N lines
|
||||
#define ANSI_CURSOR_DOWN(N) "\x1b[" #N "B" // Move down N lines
|
||||
#define ANSI_CURSOR_RIGHT(N) "\x1b[" #N "C" // Move right N columns
|
||||
#define ANSI_CURSOR_LEFT(N) "\x1b[" #N "D" // Move left N columns
|
||||
#define ANSI_CURSOR_HOME "\x1b[H" // Move to home (0,0)
|
||||
#define ANSI_CURSOR_HIDE "\x1b[?25l" // Hide cursor
|
||||
#define ANSI_CURSOR_SHOW "\x1b[?25h" // Show cursor
|
||||
|
||||
// ============================================================================
|
||||
// SCREEN CONTROL
|
||||
// ============================================================================
|
||||
#define ANSI_CLEAR_SCREEN "\x1b[2J" // Clear entire screen
|
||||
#define ANSI_CLEAR_LINE "\x1b[K" // Clear from cursor to end of line
|
||||
#define ANSI_CLEAR_UP "\x1b[1J" // Clear from cursor to start
|
||||
#define ANSI_CLEAR_DOWN "\x1b[0J" // Clear from cursor to end
|
||||
|
||||
// ============================================================================
|
||||
// EXAMPLE USAGE
|
||||
// ============================================================================
|
||||
/*
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
// Simple color example
|
||||
printf("%sHello in Red%s\n", ANSI_RED, ANSI_RESET);
|
||||
|
||||
// Bold and colored
|
||||
printf("%s%sBold Green%s\n", ANSI_BOLD, ANSI_GREEN, ANSI_RESET);
|
||||
|
||||
// Background color
|
||||
printf("%s%sYellow on Blue%s\n", ANSI_YELLOW, ANSI_BG_BLUE, ANSI_RESET);
|
||||
|
||||
// Combine multiple styles
|
||||
printf("%s%s%sUnderlined Bold Cyan%s\n",
|
||||
ANSI_UNDERLINE, ANSI_BOLD, ANSI_CYAN, ANSI_RESET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
+31
-6
@@ -20,15 +20,27 @@ typedef struct erow {
|
||||
char *render; /**< The actual line we will print */
|
||||
} erow;
|
||||
|
||||
typedef struct theme {
|
||||
char *BACKGROUND_COLOR;
|
||||
char *COLOR_KEYWORD;
|
||||
char *COLOR_TYPE;
|
||||
char *COLOR_STRING;
|
||||
char *COLOR_COMMENT;
|
||||
char *COLOR_NUMBER;
|
||||
char *COLOR_DEFAULT;
|
||||
|
||||
} theme_t;
|
||||
|
||||
enum editorStatus_e {
|
||||
IDLE,
|
||||
READ_ONLY,
|
||||
READ_AND_WRITE,
|
||||
READ_AND_WRITE,
|
||||
};
|
||||
|
||||
struct const_t {
|
||||
int TAB_LENGTH;
|
||||
int QUIT_TIMES;
|
||||
char *THEME;
|
||||
};
|
||||
|
||||
struct prefix_t {
|
||||
@@ -40,7 +52,16 @@ struct keyBind_t {
|
||||
char *key_sequence;
|
||||
int prefix_id;
|
||||
Lisp command;
|
||||
|
||||
};
|
||||
|
||||
enum buffer_type { FILE_BUFF, TERMINAL_BUFF };
|
||||
|
||||
struct buffer_t {
|
||||
enum buffer_type type;
|
||||
int buffer_id;
|
||||
int width, height;
|
||||
int x, y; /**< Position of the buffer*/
|
||||
char *filename;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -74,12 +95,17 @@ struct editorConfig {
|
||||
Lisp ctx_data; /** Lisp data context */
|
||||
LispError ctx_error; /** Lisp ctx error */
|
||||
|
||||
struct keyBind_t* key_binds;
|
||||
struct keyBind_t *key_binds;
|
||||
int number_of_keybinds;
|
||||
|
||||
struct prefix_t* prefix;
|
||||
|
||||
struct prefix_t *prefix;
|
||||
int number_of_prefix;
|
||||
|
||||
struct buffer_t buffers[64];
|
||||
struct buffer_t ***screen_layout; /**< Which buffer is the current cell*/
|
||||
int number_of_buffer;
|
||||
|
||||
theme_t theme;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -94,5 +120,4 @@ struct abuf {
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,4 +8,6 @@ void editorInsertNewLine();
|
||||
|
||||
void editorDelChar();
|
||||
|
||||
void editorSetStatusMessage(const char *fmt, ...);
|
||||
|
||||
#endif // EDITOR_OP_H_
|
||||
|
||||
@@ -23,6 +23,4 @@ void editorDrawStatusBar(struct abuf *ab);
|
||||
|
||||
void editorDrawMessageBar(struct abuf *ab);
|
||||
|
||||
void editorSetStatusMessage(const char *fmt, ...);
|
||||
|
||||
#endif // OUTPUT_H_
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#define COLOR_RESET "\033[0m"
|
||||
#define COLOR_KEYWORD "\033[1;35m" // Bold magenta
|
||||
#define COLOR_TYPE "\033[1;34m" // Bold blue
|
||||
#define COLOR_STRING "\033[1;32m" // Bold green
|
||||
#define COLOR_COMMENT "\033[0;36m" // Cyan
|
||||
#define COLOR_NUMBER "\033[1;33m" // Bold yellow
|
||||
#define COLOR_DEFAULT "\033[0;37m" // White
|
||||
#ifndef SYNTAX_HIGHLIGHTER_H_
|
||||
#define SYNTAX_HIGHLIGHTER_H_
|
||||
|
||||
#include "color.h"
|
||||
|
||||
// Color codes that only affect foreground, preserving your background color
|
||||
#define COLOR_RESET "\x1b[39m" // Reset all (4 bytes)
|
||||
|
||||
// Token types
|
||||
typedef enum {
|
||||
@@ -18,3 +18,6 @@ typedef enum {
|
||||
} TokenType;
|
||||
|
||||
char *highlight_line(const char * line, int *length);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user