N_GUI_SYNTAXVIEW line-count, mode, and text-selection/copy regression test (headless).
N_GUI_SYNTAXVIEW line-count, mode, and text-selection/copy regression test (headless).
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int opt;
while ((opt = getopt(argc, argv, "V:")) != -1) {
switch (opt) {
case 'V':
if (!strcmp("LOG_NULL", optarg))
else if (!strcmp("LOG_NOTICE", optarg))
else if (!strcmp("LOG_INFO", optarg))
else if (!strcmp("LOG_ERR", optarg))
else if (!strcmp("LOG_DEBUG", optarg))
else
return -1;
break;
default:
return -1;
}
}
return 0;
}
if (!cond) {
}
}
int main(
int argc,
char** argv) {
fprintf(stderr, "Usage: %s [-V LOG_LEVEL]\n", argv[0]);
return 2;
}
if (!al_init() || !al_init_font_addon()) {
return 1;
}
ALLEGRO_FONT* font = al_create_builtin_font();
if (!font) {
return 1;
}
al_destroy_font(font);
return 1;
}
const char* http =
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"Accept: */*\r\n"
"\r\n"
"body line";
{
expect_true(
"get_text round-trips", got && strcmp(got, http) == 0);
}
{
expect_true(
"selection [0,3) is GET", sel && strcmp(sel,
"GET") == 0);
}
{
expect_true(
"reversed [3,0) is GET", sel && strcmp(sel,
"GET") == 0);
}
{
expect_true(
"over-long end clamps to text", sel && strcmp(sel, http) == 0);
}
{
expect_true(
"select_all returns full text", sel && strcmp(sel, http) == 0);
}
{
char big[4096];
size_t pos = 0;
int line60_offset = 0;
for (int ln = 0; ln < 100 && pos + 16 < sizeof(big); ln++) {
if (ln == 60) line60_offset = (int)pos;
pos += (size_t)snprintf(big + pos, sizeof(big) - pos, "line %03d\n", ln);
}
if (yd) {
}
}
al_destroy_font(font);
return 1;
}
return 0;
}
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
#define Free(__ptr)
Free Handler to get errors.
void * data
widget-specific data (union via void pointer)
int scroll_offset
first visible line
const char * n_gui_syntaxview_get_text(N_GUI_CTX *ctx, int widget_id)
get the text currently shown by a syntax view
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
Set the display (viewport) size for global scrollbar computation.
#define N_GUI_SYNTAX_HTTP
syntax view: HTTP message highlighting (request/status line and headers)
void n_gui_syntaxview_set_selection(N_GUI_CTX *ctx, int widget_id, int start, int end)
set the selection range of a syntax view (byte offsets into the text)
int n_gui_syntaxview_get_line_count(N_GUI_CTX *ctx, int widget_id)
get the number of text lines in a syntax view
void n_gui_syntaxview_set_mode(N_GUI_CTX *ctx, int widget_id, int mode)
set the highlighting mode of a syntax view
#define N_GUI_SYNTAX_XML
syntax view: XML/HTML highlighting (tags, attributes, quoted values, comments)
#define N_GUI_SYNTAX_JSON
syntax view: JSON highlighting (keys, strings, numbers, punctuation)
char * n_gui_syntaxview_get_selected_text(N_GUI_CTX *ctx, int widget_id)
get a copy of the currently selected text in a syntax view
N_GUI_WIDGET * n_gui_get_widget(N_GUI_CTX *ctx, int widget_id)
Get a widget pointer by id.
int n_gui_add_syntaxview(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int mode)
Add a read-only syntax-highlighted text view.
int n_gui_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
void n_gui_syntaxview_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set (copy) the text shown by a syntax view
void n_gui_syntaxview_scroll_to_offset(N_GUI_CTX *ctx, int widget_id, int byte_offset)
scroll a syntax view so the line holding a byte offset is vertically centered
void n_gui_syntaxview_select_all(N_GUI_CTX *ctx, int widget_id)
select the entire text of a syntax view
#define N_GUI_SYNTAX_YAML
syntax view: YAML highlighting (keys, quoted values, list markers, comments)
#define N_GUI_SYNTAX_JS
syntax view: JavaScript highlighting (keywords, strings, numbers, comments)
#define N_GUI_SYNTAX_PLAIN
syntax view: no highlighting
The top-level GUI context that holds all windows.
syntax view specific data: read-only highlighted text
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.