can save files
This commit is contained in:
35
edit.jai
35
edit.jai
@@ -15,6 +15,8 @@ first_line := 0;
|
|||||||
cursor_x := 0;
|
cursor_x := 0;
|
||||||
cursor_y := 0;
|
cursor_y := 0;
|
||||||
|
|
||||||
|
file_name: string;
|
||||||
|
|
||||||
White :: Vector4.{1, 1, 1, 1};
|
White :: Vector4.{1, 1, 1, 1};
|
||||||
|
|
||||||
Special_Character_Lookup : [10]u8 : .[
|
Special_Character_Lookup : [10]u8 : .[
|
||||||
@@ -34,8 +36,8 @@ main :: () {
|
|||||||
args := get_command_line_arguments();
|
args := get_command_line_arguments();
|
||||||
assert(args.count == 2, "The file name must be passed as a CLI argument");
|
assert(args.count == 2, "The file name must be passed as a CLI argument");
|
||||||
|
|
||||||
|
file_name = args[1];
|
||||||
window_name := ifx args.count == 1 then "edit" else args[1];
|
window_name := file_name;
|
||||||
window := create_window(window_width, window_height, window_name);
|
window := create_window(window_width, window_height, window_name);
|
||||||
|
|
||||||
my_init_fonts();
|
my_init_fonts();
|
||||||
@@ -45,7 +47,7 @@ main :: () {
|
|||||||
should_quit := false;
|
should_quit := false;
|
||||||
prev := get_time();
|
prev := get_time();
|
||||||
|
|
||||||
assert(read_file_lines(args[1]), "Must be able to read file!");
|
assert(read_file_lines(file_name), "Must be able to read file!");
|
||||||
|
|
||||||
while !should_quit {
|
while !should_quit {
|
||||||
reset_temporary_storage();
|
reset_temporary_storage();
|
||||||
@@ -81,7 +83,15 @@ main :: () {
|
|||||||
if !event.shift_pressed {
|
if !event.shift_pressed {
|
||||||
key += #char "a" - #char "A";
|
key += #char "a" - #char "A";
|
||||||
}
|
}
|
||||||
insert_character_at_cursor(cast(u8) key);
|
|
||||||
|
if event.ctrl_pressed {
|
||||||
|
if event.key_code == {
|
||||||
|
case #char "S"; #through;
|
||||||
|
case #char "s"; handle_save();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
insert_character_at_cursor(cast(u8) key);
|
||||||
|
}
|
||||||
} else if 33 <= event.key_code && event.key_code <= 126 {
|
} else if 33 <= event.key_code && event.key_code <= 126 {
|
||||||
// NOTE: this doesn't quite work for some keys, like ` or []
|
// NOTE: this doesn't quite work for some keys, like ` or []
|
||||||
key := event.key_code;
|
key := event.key_code;
|
||||||
@@ -149,6 +159,23 @@ insert_character_at_cursor :: (char: u8) {
|
|||||||
cursor_x += 1;
|
cursor_x += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle_save :: () {
|
||||||
|
out_builder: String_Builder;
|
||||||
|
init_string_builder(*out_builder);
|
||||||
|
|
||||||
|
for line: lines {
|
||||||
|
line_str := string.{count=line.count, data=line.data};
|
||||||
|
append(*out_builder, line_str);
|
||||||
|
if it_index != lines.count - 1 {
|
||||||
|
append(*out_builder, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content := builder_to_string(*out_builder);
|
||||||
|
out_file_name := tprint("%.new", file_name);
|
||||||
|
write_entire_file(out_file_name, content);
|
||||||
|
}
|
||||||
|
|
||||||
handle_window_resizes :: (window: Window_Type) {
|
handle_window_resizes :: (window: Window_Type) {
|
||||||
for Input.get_window_resizes() {
|
for Input.get_window_resizes() {
|
||||||
Simp.update_window(it.window);
|
Simp.update_window(it.window);
|
||||||
|
|||||||
Reference in New Issue
Block a user