From: Mike Lowis Date: Thu, 6 Oct 2016 13:08:07 +0000 (-0400) Subject: General cleanup and commenting X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=029f68fa000a235b60bf6bbd1a42f6c2191469a0;p=projs%2Ftide.git General cleanup and commenting --- diff --git a/edit.h b/edit.h index 2e15ea3..0388397 100644 --- a/edit.h +++ b/edit.h @@ -4,28 +4,8 @@ #include #include -/* Definitons +/* Input Handling *****************************************************************************/ -/* color indexes for the colorscheme */ -enum ColorId { - CLR_BASE03 = 0, - CLR_BASE02, - CLR_BASE01, - CLR_BASE00, - CLR_BASE0, - CLR_BASE1, - CLR_BASE2, - CLR_BASE3, - CLR_YELLOW, - CLR_ORANGE, - CLR_RED, - CLR_MAGENTA, - CLR_VIOLET, - CLR_BLUE, - CLR_CYAN, - CLR_GREEN, -}; - /* key definitions */ enum Keys { /* Define some runes in the private use area of unicode to represent @@ -107,12 +87,22 @@ enum MouseBtn { MOUSE_WHEELDOWN }; -/* Represents an ARGB color value */ -typedef uint32_t Color; +/* UTF-8 Handling + *****************************************************************************/ +enum { + UTF_MAX = 6u, /* maximum number of bytes that make up a rune */ + RUNE_SELF = 0x80, /* byte values larger than this are *not* ascii */ + RUNE_ERR = 0xFFFD, /* rune value representing an error */ + RUNE_MAX = 0x10FFFF, /* Maximum decodable rune value */ + RUNE_EOF = EOF /* ruen value representing end of file */ +}; /* Represents a unicode code point */ typedef uint32_t Rune; +size_t utf8encode(char str[UTF_MAX], Rune rune); +bool utf8decode(Rune* rune, size_t* length, int byte); + /* Buffer management functions *****************************************************************************/ typedef struct buf { @@ -162,18 +152,40 @@ Rune screen_getcell(unsigned row, unsigned col); *****************************************************************************/ void die(char* msg); -/* UTF-8 Handling +/* Color Scheme Handling *****************************************************************************/ -enum { - UTF_MAX = 6u, /* maximum number of bytes that make up a rune */ - RUNE_SELF = 0x80, /* byte values larger than this are *not* ascii */ - RUNE_ERR = 0xFFFD, /* rune value representing an error */ - RUNE_MAX = 0x10FFFF, /* Maximum decodable rune value */ - RUNE_EOF = EOF /* ruen value representing end of file */ + +/* color indexes for the colorscheme */ +enum ColorId { + CLR_BASE03 = 0, + CLR_BASE02, + CLR_BASE01, + CLR_BASE00, + CLR_BASE0, + CLR_BASE1, + CLR_BASE2, + CLR_BASE3, + CLR_YELLOW, + CLR_ORANGE, + CLR_RED, + CLR_MAGENTA, + CLR_VIOLET, + CLR_BLUE, + CLR_CYAN, + CLR_GREEN, }; -size_t utf8encode(char str[UTF_MAX], Rune rune); -bool utf8decode(Rune* rune, size_t* length, int byte); +/* Represents an ARGB color value */ +typedef uint32_t Color; + +/* two colorscheme variants are supported, a light version and a dark version */ +enum ColorScheme { + DARK = 0, + LIGHT = 1 +}; + +/* variable for holding the currently selected color scheme */ +enum ColorScheme ColorBase; /* Configuration *****************************************************************************/ @@ -185,8 +197,6 @@ enum { BufSize = 8192, /* default buffer size */ }; -static enum { DARK = 0, LIGHT = 1 } ColorBase = DARK; - static const Color Palette[][2] = { /* Color Name = Dark Light */ [CLR_BASE03] = { 0x002b36, 0xfdf6e3 }, @@ -207,8 +217,11 @@ static const Color Palette[][2] = { [CLR_GREEN] = { 0x859900, 0x859900 }, }; +/* choose the font to use for xft */ #ifdef __MACH__ #define FONTNAME "Inconsolata:pixelsize=14:antialias=true:autohint=true" #else #define FONTNAME "Liberation Mono:pixelsize=14:antialias=true:autohint=true" #endif + +#define DEFAULT_COLORSCHEME DARK diff --git a/screen.c b/screen.c index 742818f..55db854 100644 --- a/screen.c +++ b/screen.c @@ -19,10 +19,8 @@ void screen_reflow(Buf* buf) { } void screen_setsize(Buf* buf, unsigned nrows, unsigned ncols) { - unsigned pos = 0; /* free the old row data */ if (Rows) { - pos = Rows[1]->off; for (unsigned i = 0; i < NumRows; i++) free(Rows[i]); free(Rows); diff --git a/xedit.c b/xedit.c index 9500a30..27f21f4 100644 --- a/xedit.c +++ b/xedit.c @@ -26,6 +26,7 @@ struct { } X; Buf Buffer; unsigned CursorPos = 0; +enum ColorScheme ColorBase = DEFAULT_COLORSCHEME; void die(char* m) { fprintf(stderr, "dying, %s\n", m); @@ -119,7 +120,7 @@ static Rune getkey(XEvent* e) { if (buf[0] == '\r') buf[0] = '\n'; for(int i = 0; i < 8 && !utf8decode(&rune, &len, buf[i]); i++); } - printf("key: 0x%#x\n", rune); + printf("key: %#x\n", rune); /* translate the key code into a unicode codepoint */ switch (key) { case XK_F1: return KEY_F1;