setup a colors demo
parent
c93739f680
commit
6b1e3ed8ba
Binary file not shown.
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
code="$PWD"
|
||||
opts="-g -Wno-switch"
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
echo colors
|
||||
clang $opts $code/src/colors.main.c -lncurses -o colors
|
||||
|
||||
|
|
@ -24,10 +24,15 @@ load_paths = {
|
|||
commands = {
|
||||
.build_printinput = { .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
|
||||
.win = "build_printinput.bat", .linux = "./build_printinput.sh", .mac = "./build_printinput.sh", },
|
||||
|
||||
.build_animate = { .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
|
||||
.win = "build_animate.bat", .linux = "./build_animate.sh", .mac = "./build_animate.sh", },
|
||||
|
||||
.build_colors = { .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
|
||||
.win = "build_colors.bat", .linux = "./build_colors.sh", .mac = "./build_colors.sh", },
|
||||
};
|
||||
fkey_command = {
|
||||
.F1 = "build_printinput",
|
||||
.F2 = "build_animate",
|
||||
.F3 = "build_colors",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
#include "mr4th/mr4th_base.h"
|
||||
#include <ncurses.h>
|
||||
|
||||
#include "mr4th/mr4th_base.c"
|
||||
|
||||
int main(){
|
||||
Arena *arena = arena_alloc();
|
||||
|
||||
// initializes ncurses
|
||||
initscr();
|
||||
|
||||
if (!has_colors()){
|
||||
goto no_color;
|
||||
}
|
||||
|
||||
start_color();
|
||||
|
||||
// settings
|
||||
noecho();
|
||||
cbreak();
|
||||
|
||||
B32 animating = 1;
|
||||
|
||||
// get size
|
||||
U32 window_x = 0;
|
||||
U32 window_y = 0;
|
||||
getmaxyx(stdscr, window_y, window_x);
|
||||
|
||||
U32 window_stride = window_x;
|
||||
|
||||
// color pairs
|
||||
struct ColorPairs{
|
||||
String8 text;
|
||||
S16 fore;
|
||||
S16 back;
|
||||
};
|
||||
struct ColorPairs color_pairs[] = {
|
||||
{ str8_lit(" WHITE / BLACK"), COLOR_WHITE , COLOR_BLACK },
|
||||
{ str8_lit(" RED / BLACK"), COLOR_RED , COLOR_BLACK },
|
||||
{ str8_lit(" GREEN / BLACK"), COLOR_GREEN , COLOR_BLACK },
|
||||
{ str8_lit(" BLUE / BLACK"), COLOR_BLUE , COLOR_BLACK },
|
||||
{ str8_lit(" YELLOW / BLACK"), COLOR_YELLOW , COLOR_BLACK },
|
||||
{ str8_lit("MAGENTA / BLACK"), COLOR_MAGENTA, COLOR_BLACK },
|
||||
{ str8_lit(" CYAN / BLACK"), COLOR_CYAN , COLOR_BLACK },
|
||||
|
||||
{ str8_lit(" BLACK / WHITE"), COLOR_BLACK , COLOR_WHITE },
|
||||
{ str8_lit(" BLACK / RED"), COLOR_BLACK , COLOR_RED },
|
||||
{ str8_lit(" BLACK / GREEN"), COLOR_BLACK , COLOR_GREEN },
|
||||
{ str8_lit(" BLACK / BLUE"), COLOR_BLACK , COLOR_BLUE },
|
||||
{ str8_lit(" BLACK / YELLOW"), COLOR_BLACK , COLOR_YELLOW },
|
||||
{ str8_lit(" BLACK / MAGENTA"), COLOR_BLACK , COLOR_MAGENTA },
|
||||
{ str8_lit(" BLACK / CYAN"), COLOR_BLACK , COLOR_CYAN },
|
||||
};
|
||||
|
||||
// print
|
||||
for (S16 i = 0; i < ArrayCount(color_pairs); i += 1){
|
||||
S16 pair_idx = i + 1;
|
||||
init_pair(pair_idx, color_pairs[i].fore, color_pairs[i].back);
|
||||
attron(COLOR_PAIR(pair_idx));
|
||||
printw("%.*s\n", (S32)color_pairs[i].text.size, color_pairs[i].text.str);
|
||||
attroff(pair_idx);
|
||||
}
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
|
||||
if (0){ no_color:
|
||||
endwin();
|
||||
printf("no ncurses color support\n");
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
Loading…
Reference in New Issue