improvements to the string library
This commit is contained in:
parent
fb1230e991
commit
48eeb211ae
|
@ -198,23 +198,21 @@ enum Command_ID{
|
|||
cmdid_interactive_kill_buffer,
|
||||
cmdid_kill_buffer,
|
||||
|
||||
cmdid_change_active_panel,
|
||||
|
||||
cmdid_to_uppercase,
|
||||
cmdid_to_lowercase,
|
||||
|
||||
cmdid_toggle_line_wrap,
|
||||
cmdid_toggle_show_whitespace,
|
||||
|
||||
cmdid_eol_dosify,
|
||||
cmdid_eol_nixify,
|
||||
|
||||
cmdid_clean_all_lines,
|
||||
cmdid_auto_tab_range,
|
||||
cmdid_eol_dosify,
|
||||
cmdid_eol_nixify,
|
||||
|
||||
cmdid_open_panel_vsplit,
|
||||
cmdid_open_panel_hsplit,
|
||||
cmdid_close_panel,
|
||||
cmdid_change_active_panel,
|
||||
|
||||
cmdid_page_up,
|
||||
cmdid_page_down,
|
||||
|
@ -226,7 +224,9 @@ enum Command_ID{
|
|||
|
||||
cmdid_hide_scrollbar,
|
||||
cmdid_show_scrollbar,
|
||||
|
||||
cmdid_set_settings,
|
||||
|
||||
cmdid_command_line,
|
||||
//
|
||||
cmdid_count
|
||||
|
@ -360,7 +360,7 @@ struct Theme_Color{
|
|||
#define GET_BINDING_DATA(name) int name(void *data, int size)
|
||||
#define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app)
|
||||
#define HOOK_SIG(name) int name(struct Application_Links *app)
|
||||
#define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target)
|
||||
#define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target, float dt)
|
||||
|
||||
extern "C"{
|
||||
typedef VIEW_ROUTINE_SIG(View_Routine_Function);
|
||||
|
|
|
@ -244,6 +244,7 @@ default_keys(Bind_Helper *context){
|
|||
bind(context, 'k', MDFR_CTRL, cmdid_interactive_kill_buffer);
|
||||
bind(context, 'i', MDFR_CTRL, cmdid_interactive_switch_buffer);
|
||||
bind(context, 'c', MDFR_ALT, cmdid_open_color_tweaker);
|
||||
bind(context, 'd', MDFR_ALT, cmdid_open_debug);
|
||||
bind(context, 'o', MDFR_ALT, open_in_other);
|
||||
bind(context, 'w', MDFR_CTRL, save_as);
|
||||
|
||||
|
|
|
@ -1,30 +1,65 @@
|
|||
enum Key_Code{
|
||||
key_back = 1,
|
||||
key_up = 2,
|
||||
key_down = 3,
|
||||
key_left = 4,
|
||||
key_right = 5,
|
||||
key_del = 6,
|
||||
key_insert = 7,
|
||||
key_home = 8,
|
||||
key_end = 11,
|
||||
key_page_up = 12,
|
||||
key_page_down = 13,
|
||||
key_esc = 14,
|
||||
key_f1 = 127,
|
||||
key_f2 = 128,
|
||||
key_f3 = 129,
|
||||
key_f4 = 130,
|
||||
key_f5 = 131,
|
||||
key_f6 = 132,
|
||||
key_f7 = 133,
|
||||
key_f8 = 134,
|
||||
key_f9 = 135,
|
||||
key_f10 = 136,
|
||||
key_f11 = 137,
|
||||
key_f12 = 138,
|
||||
key_f13 = 139,
|
||||
key_f14 = 140,
|
||||
key_f15 = 141,
|
||||
key_f16 = 142,
|
||||
key_back = 1,
|
||||
key_up = 2,
|
||||
key_down = 3,
|
||||
key_left = 4,
|
||||
key_right = 5,
|
||||
key_del = 6,
|
||||
key_insert = 7,
|
||||
key_home = 8,
|
||||
key_end = 11,
|
||||
key_page_up = 12,
|
||||
key_page_down = 13,
|
||||
key_esc = 14,
|
||||
key_f1 = 127,
|
||||
key_f2 = 128,
|
||||
key_f3 = 129,
|
||||
key_f4 = 130,
|
||||
key_f5 = 131,
|
||||
key_f6 = 132,
|
||||
key_f7 = 133,
|
||||
key_f8 = 134,
|
||||
key_f9 = 135,
|
||||
key_f10 = 136,
|
||||
key_f11 = 137,
|
||||
key_f12 = 138,
|
||||
key_f13 = 139,
|
||||
key_f14 = 140,
|
||||
key_f15 = 141,
|
||||
key_f16 = 142,
|
||||
};
|
||||
static char*
|
||||
global_key_name(int key_code, int *size){
|
||||
char *result = 0;
|
||||
switch(key_code){
|
||||
case key_back: result = "back"; *size = sizeof("back")-1; break;
|
||||
case key_up: result = "up"; *size = sizeof("up")-1; break;
|
||||
case key_down: result = "down"; *size = sizeof("down")-1; break;
|
||||
case key_left: result = "left"; *size = sizeof("left")-1; break;
|
||||
case key_right: result = "right"; *size = sizeof("right")-1; break;
|
||||
case key_del: result = "del"; *size = sizeof("del")-1; break;
|
||||
case key_insert: result = "insert"; *size = sizeof("insert")-1; break;
|
||||
case key_home: result = "home"; *size = sizeof("home")-1; break;
|
||||
case key_end: result = "end"; *size = sizeof("end")-1; break;
|
||||
case key_page_up: result = "page_up"; *size = sizeof("page_up")-1; break;
|
||||
case key_page_down: result = "page_down"; *size = sizeof("page_down")-1; break;
|
||||
case key_esc: result = "esc"; *size = sizeof("esc")-1; break;
|
||||
case key_f1: result = "f1"; *size = sizeof("f1")-1; break;
|
||||
case key_f2: result = "f2"; *size = sizeof("f2")-1; break;
|
||||
case key_f3: result = "f3"; *size = sizeof("f3")-1; break;
|
||||
case key_f4: result = "f4"; *size = sizeof("f4")-1; break;
|
||||
case key_f5: result = "f5"; *size = sizeof("f5")-1; break;
|
||||
case key_f6: result = "f6"; *size = sizeof("f6")-1; break;
|
||||
case key_f7: result = "f7"; *size = sizeof("f7")-1; break;
|
||||
case key_f8: result = "f8"; *size = sizeof("f8")-1; break;
|
||||
case key_f9: result = "f9"; *size = sizeof("f9")-1; break;
|
||||
case key_f10: result = "f10"; *size = sizeof("f10")-1; break;
|
||||
case key_f11: result = "f11"; *size = sizeof("f11")-1; break;
|
||||
case key_f12: result = "f12"; *size = sizeof("f12")-1; break;
|
||||
case key_f13: result = "f13"; *size = sizeof("f13")-1; break;
|
||||
case key_f14: result = "f14"; *size = sizeof("f14")-1; break;
|
||||
case key_f15: result = "f15"; *size = sizeof("f15")-1; break;
|
||||
case key_f16: result = "f16"; *size = sizeof("f16")-1; break;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
|
656
4coder_string.h
656
4coder_string.h
File diff suppressed because it is too large
Load Diff
36
4ed.cpp
36
4ed.cpp
|
@ -2295,37 +2295,47 @@ internal void
|
|||
setup_command_table(){
|
||||
#define SET(n) command_table[cmdid_##n] = command_##n
|
||||
SET(null);
|
||||
|
||||
SET(seek_left);
|
||||
SET(seek_right);
|
||||
|
||||
SET(center_view);
|
||||
|
||||
SET(word_complete);
|
||||
|
||||
SET(copy);
|
||||
SET(cut);
|
||||
SET(paste);
|
||||
SET(paste_next);
|
||||
|
||||
SET(undo);
|
||||
SET(redo);
|
||||
SET(history_backward);
|
||||
SET(history_forward);
|
||||
|
||||
SET(interactive_new);
|
||||
SET(interactive_open);
|
||||
SET(reopen);
|
||||
SET(save);
|
||||
SET(change_active_panel);
|
||||
SET(interactive_switch_buffer);
|
||||
SET(interactive_kill_buffer);
|
||||
SET(kill_buffer);
|
||||
|
||||
SET(to_uppercase);
|
||||
SET(to_lowercase);
|
||||
|
||||
SET(toggle_line_wrap);
|
||||
SET(toggle_show_whitespace);
|
||||
|
||||
SET(clean_all_lines);
|
||||
SET(auto_tab_range);
|
||||
SET(eol_dosify);
|
||||
SET(eol_nixify);
|
||||
SET(auto_tab_range);
|
||||
|
||||
SET(open_panel_vsplit);
|
||||
SET(open_panel_hsplit);
|
||||
SET(close_panel);
|
||||
SET(change_active_panel);
|
||||
|
||||
SET(page_up);
|
||||
SET(page_down);
|
||||
|
@ -3120,7 +3130,7 @@ update_cli_handle_with_file(System_Functions *system, Models *models,
|
|||
char str_space[256];
|
||||
String str = make_fixed_width_string(str_space);
|
||||
append(&str, "exited with code ");
|
||||
append_int_to_str(cli->exit, &str);
|
||||
append_int_to_str(&str, cli->exit);
|
||||
output_file_append(system, models, file, str, cursor_at_end);
|
||||
result = -1;
|
||||
}
|
||||
|
@ -3705,7 +3715,6 @@ App_Step_Sig(app_step){
|
|||
View *view = 0, *active_view = 0;
|
||||
b32 active = 0;
|
||||
Input_Summary summary = {0};
|
||||
Input_Process_Result result = {0};
|
||||
|
||||
active_view = cmd->panel->view;
|
||||
used_panels = &models->layout.used_sentinel;
|
||||
|
@ -3726,13 +3735,8 @@ App_Step_Sig(app_step){
|
|||
if (result.consume_keys || result.consume_esc){
|
||||
consume_input(&available_input, Input_Esc);
|
||||
}
|
||||
}
|
||||
|
||||
for (dll_items(panel, used_panels)){
|
||||
view = panel->view;
|
||||
|
||||
if (view->changed_context_in_step == 0){
|
||||
Assert(view->current_scroll);
|
||||
active = (panel == cmd->panel);
|
||||
summary = (active)?(active_input):(dead_input);
|
||||
if (panel == mouse_panel && !input->mouse.out_of_window){
|
||||
|
@ -3740,15 +3744,15 @@ App_Step_Sig(app_step){
|
|||
}
|
||||
|
||||
GUI_Scroll_Vars *vars = view->current_scroll;
|
||||
// TODO(allen): I feel like the scroll context should actually not
|
||||
// be allowed to change in here at all.
|
||||
result = do_step_file_view(system, view, panel->inner, active,
|
||||
&summary, *vars, view->scroll_region);
|
||||
if (result.is_animating){
|
||||
Input_Process_Result ip_result =
|
||||
do_step_file_view(system, view, panel->inner, active,
|
||||
&summary, *vars, view->scroll_region);
|
||||
if (ip_result.is_animating){
|
||||
app_result.animating = 1;
|
||||
}
|
||||
*vars = result.vars;
|
||||
view->scroll_region = result.region;
|
||||
Assert(view->current_scroll == vars);
|
||||
*vars = ip_result.vars;
|
||||
view->scroll_region = ip_result.region;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1
4ed.h
1
4ed.h
|
@ -54,6 +54,7 @@ get_single_key(Key_Summary *summary, i32 index){
|
|||
struct Input_Summary{
|
||||
Mouse_State mouse;
|
||||
Key_Summary keys;
|
||||
f32 dt;
|
||||
};
|
||||
|
||||
struct Command_Line_Parameters{
|
||||
|
|
|
@ -23,6 +23,19 @@ struct App_Settings{
|
|||
i32 font_size;
|
||||
};
|
||||
|
||||
struct Debug_Input_Event{
|
||||
char key;
|
||||
|
||||
b8 is_hold;
|
||||
b8 is_ctrl;
|
||||
b8 is_alt;
|
||||
b8 is_shift;
|
||||
};
|
||||
|
||||
struct Debug_Data{
|
||||
Debug_Input_Event input_events[16];
|
||||
};
|
||||
|
||||
struct Models{
|
||||
Mem_Options mem;
|
||||
App_Settings settings;
|
||||
|
@ -64,6 +77,8 @@ struct Models{
|
|||
Scroll_Rule_Function *scroll_rule;
|
||||
|
||||
b32 keep_playing;
|
||||
|
||||
Debug_Data debug;
|
||||
};
|
||||
|
||||
// BOTTOM
|
||||
|
|
|
@ -404,7 +404,7 @@ file_set_name(Working_Set *working_set, Editing_File *file, char *filename){
|
|||
if (hit_conflict){
|
||||
file->name.live_name.size = original_len;
|
||||
append(&file->name.live_name, " <");
|
||||
append_int_to_str(file_x, &file->name.live_name);
|
||||
append_int_to_str(&file->name.live_name, file_x);
|
||||
append(&file->name.live_name, ">");
|
||||
}
|
||||
}
|
||||
|
@ -4428,24 +4428,24 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
|||
case IInt_Sure_To_Kill:
|
||||
{
|
||||
i32 action = -1;
|
||||
|
||||
|
||||
String empty_str = {0};
|
||||
String message = make_lit_string("There are unsaved changes, close anyway?");
|
||||
|
||||
|
||||
gui_do_text_field(target, message, empty_str);
|
||||
|
||||
|
||||
id.id[0] = (u64)('y');
|
||||
message = make_lit_string("(Y)es");
|
||||
if (gui_do_fixed_option(target, id, message, 'y')){
|
||||
action = 0;
|
||||
}
|
||||
|
||||
|
||||
id.id[0] = (u64)('n');
|
||||
message = make_lit_string("(N)o");
|
||||
if (gui_do_fixed_option(target, id, message, 'n')){
|
||||
action = 1;
|
||||
}
|
||||
|
||||
|
||||
id.id[0] = (u64)('s');
|
||||
message = make_lit_string("(S)ave and kill");
|
||||
if (gui_do_fixed_option(target, id, message, 's')){
|
||||
|
@ -4468,8 +4468,99 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
|||
|
||||
case VUI_Debug:
|
||||
{
|
||||
|
||||
}break;
|
||||
view->current_scroll = &view->gui_scroll;
|
||||
|
||||
// TODO(allen):
|
||||
// - Incoming input
|
||||
// - Memory info
|
||||
// - Thread info
|
||||
// - View inspection
|
||||
// - Buffer inspection
|
||||
// - Command maps inspection
|
||||
|
||||
String empty_str = string_zero();
|
||||
char space[512];
|
||||
String string = make_fixed_width_string(space);
|
||||
|
||||
// Time Watcher
|
||||
{
|
||||
string.size = 0;
|
||||
u64 time = system->now_time_stamp();
|
||||
|
||||
append(&string, "last event time stamp: ");
|
||||
append_u64_to_str(&string, time);
|
||||
|
||||
gui_do_text_field(target, string, empty_str);
|
||||
}
|
||||
|
||||
// Incoming input
|
||||
// - keeping track of where something get's consumed!?
|
||||
// - convert mouse clicks into key coded events??!!
|
||||
{
|
||||
Debug_Data *debug = &view->persistent.models->debug;
|
||||
|
||||
{
|
||||
int mx = input.mouse.x;
|
||||
int my = input.mouse.y;
|
||||
|
||||
string.size = 0;
|
||||
append(&string, "mouse: (");
|
||||
append_int_to_str(&string, mx);
|
||||
append(&string, ",");
|
||||
append_int_to_str(&string, my);
|
||||
append(&string, ")");
|
||||
}
|
||||
|
||||
gui_do_text_field(target, string, empty_str);
|
||||
|
||||
Debug_Input_Event *input_event = debug->input_events;
|
||||
for (i32 i = 0;
|
||||
i < ArrayCount(debug->input_events);
|
||||
++i, ++input_event){
|
||||
string.size = 0;
|
||||
|
||||
if (input_event->is_hold){
|
||||
append(&string, "hold: ");
|
||||
}
|
||||
else{
|
||||
append(&string, "press: ");
|
||||
}
|
||||
|
||||
if (input_event->is_ctrl){
|
||||
append(&string, "ctrl-");
|
||||
}
|
||||
else{
|
||||
append(&string, " -");
|
||||
}
|
||||
|
||||
if (input_event->is_alt){
|
||||
append(&string, "alt-");
|
||||
}
|
||||
else{
|
||||
append(&string, " -");
|
||||
}
|
||||
|
||||
if (input_event->is_shift){
|
||||
append(&string, "shift ");
|
||||
}
|
||||
else{
|
||||
append(&string, " ");
|
||||
}
|
||||
|
||||
if (input_event->key >= ' ' && input_event->key <= '~'){
|
||||
append(&string, make_string(&input_event->key, 1));
|
||||
}
|
||||
else{
|
||||
String str;
|
||||
str.str = global_key_name(input_event->key, &str.size);
|
||||
str.memory_size = str.size + 1;
|
||||
append(&string, str);
|
||||
}
|
||||
|
||||
gui_do_text_field(target, string, empty_str);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4748,7 +4839,7 @@ do_step_file_view(System_Functions *system,
|
|||
|
||||
if (view->persistent.models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y,
|
||||
&scroll_vars.scroll_x, &scroll_vars.scroll_y,
|
||||
(view->persistent.id) + 1, is_new_target)){
|
||||
(view->persistent.id) + 1, is_new_target, user_input->dt)){
|
||||
result.is_animating = 1;
|
||||
}
|
||||
|
||||
|
@ -5040,9 +5131,9 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re
|
|||
char line_number_space[30];
|
||||
String line_number = make_fixed_width_string(line_number_space);
|
||||
append(&line_number, " L#");
|
||||
append_int_to_str(view->recent->cursor.line, &line_number);
|
||||
append_int_to_str(&line_number, view->recent->cursor.line);
|
||||
append(&line_number, " C#");
|
||||
append_int_to_str(view->recent->cursor.character, &line_number);
|
||||
append_int_to_str(&line_number, view->recent->cursor.character);
|
||||
|
||||
intbar_draw_string(target, &bar, line_number, base_color);
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
enum Key_Code{
|
||||
key_back = 1,
|
||||
key_up = 2,
|
||||
key_down = 3,
|
||||
key_left = 4,
|
||||
key_right = 5,
|
||||
key_del = 6,
|
||||
key_insert = 7,
|
||||
key_home = 8,
|
||||
key_end = 11,
|
||||
key_page_up = 12,
|
||||
key_page_down = 13,
|
||||
key_esc = 14,
|
||||
key_f1 = 127,
|
||||
key_f2 = 128,
|
||||
key_f3 = 129,
|
||||
key_f4 = 130,
|
||||
key_f5 = 131,
|
||||
key_f6 = 132,
|
||||
key_f7 = 133,
|
||||
key_f8 = 134,
|
||||
key_f9 = 135,
|
||||
key_f10 = 136,
|
||||
key_f11 = 137,
|
||||
key_f12 = 138,
|
||||
key_f13 = 139,
|
||||
key_f14 = 140,
|
||||
key_f15 = 141,
|
||||
key_f15 = 142,
|
||||
}
|
|
@ -125,7 +125,7 @@ char* generate_keycode_enum(){
|
|||
file = fopen(filename, "wb");
|
||||
fprintf(file, "enum Key_Code{\n");
|
||||
count = ArrayCount(keys_that_need_codes);
|
||||
for (i = 0; i < count;){
|
||||
for (i = 0; i < count; i){
|
||||
if (strcmp(keys_that_need_codes[i], "f1") == 0 && code < 0x7F){
|
||||
code = 0x7F;
|
||||
}
|
||||
|
@ -134,11 +134,32 @@ char* generate_keycode_enum(){
|
|||
case '\t': code++; break;
|
||||
case 0x20: code = 0x7F; break;
|
||||
default:
|
||||
fprintf(file, " key_%s = %d,\n", keys_that_need_codes[i++], code++);
|
||||
fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fprintf(file, "};\n");
|
||||
|
||||
fprintf(file,
|
||||
"static char*\n"
|
||||
"global_key_name(int key_code, int *size){\n"
|
||||
"char *result = 0;\n"
|
||||
"switch(key_code){\n"
|
||||
);
|
||||
for (i = 0; i < count; ++i){
|
||||
fprintf(file,
|
||||
"case key_%s: result = \"%s\"; *size = sizeof(\"%s\")-1; break;\n",
|
||||
keys_that_need_codes[i],
|
||||
keys_that_need_codes[i],
|
||||
keys_that_need_codes[i]
|
||||
);
|
||||
}
|
||||
fprintf(file,
|
||||
"}\n"
|
||||
"return(result);\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
fclose(file);
|
||||
return(filename);
|
||||
}
|
||||
|
|
|
@ -1326,10 +1326,9 @@ struct Casey_Scroll_Velocity
|
|||
};
|
||||
|
||||
Casey_Scroll_Velocity casey_scroll_velocity_[16] = {0};
|
||||
Casey_Scroll_Velocity *casey_scroll_velocity = casey_scroll_velocity_;
|
||||
Casey_Scroll_Velocity *casey_scroll_velocity = casey_scroll_velocity_ - 1;
|
||||
|
||||
SCROLL_RULE_SIG(casey_smooth_scroll_rule){
|
||||
float dt = 1.0f/60.0f; // TODO(casey): Why do I not get the timestep here?
|
||||
Casey_Scroll_Velocity *velocity = casey_scroll_velocity + view_id;
|
||||
int result = 0;
|
||||
if(is_new_target)
|
||||
|
|
Loading…
Reference in New Issue