Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The Terminal is a Command line shell built into the kernel with an 8 entry comma

### Notepad

A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. Defaults to editing the file `records/notes`. Using the `edit` command in shell allows editing of any file.
A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. `Ctrl+S` saves and `Ctrl+O` opens a file by path (a path that doesn't exist starts a new note there). Defaults to editing the file `records/notes`. Using the `edit` command in shell allows editing of any file. Closing with `X` while there are unsaved changes asks whether to Save, Discard or Cancel.

### Files

Expand Down
30 changes: 28 additions & 2 deletions apps/notepad/notepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const vigil_api_t* api = 0;

#define STATUS_ROWS 1
#define STATUS_TEXT_X 8
#define STATUS_LINE_MAX 120
#define STATUS_LINE_MAX 128

#define NOTE_FG GFX_WHITE
#define NOTE_BG GFX_BLACK
Expand Down Expand Up @@ -229,7 +229,7 @@ static void draw_status(void) {
line[0] = '\0';

append_text(line, &pos, file_path);
append_text(line, &pos, " | Ctrl+S: save | ");
append_text(line, &pos, " | Ctrl+S: save Ctrl+O: open | ");

api->kuitoa((uint32_t) length, number);
append_text(line, &pos, number);
Expand Down Expand Up @@ -562,6 +562,29 @@ static void notepad_open_file(const char* path) {
open_file(path);
}

// --- open prompt ---

static void start_open_prompt(void) {
api->mouse_hide_cursor();

if (dirty) {
status_note = "unsaved changes - press Ctrl+S first";
draw_status();
return;
}

const char* initial = "";
if (api->kstrlen(file_path) < PROMPT_BUFFER_SIZE) {
initial = file_path;
}

api->prompt_open("Open file (new path = new note):", initial, FS_MAX_PATH - 1, "");
}

static void notepad_prompt_done(const char* path) {
open_file(path);
}

// --- close dialog ---

static const char* const close_labels[3] = {
Expand Down Expand Up @@ -618,6 +641,8 @@ static void notepad_redraw(void) {
static void notepad_handle_char(char c) {
if (c == KEY_CTRL_S) {
save_note();
} else if (c == KEY_CTRL_O) {
start_open_prompt();
} else if (c == '\b') {
backspace();
} else if (c == KEY_DELETE) {
Expand Down Expand Up @@ -693,6 +718,7 @@ int app_entry(const vigil_api_t* kernel_api, app_t* out_app) {
out_app->on_tick = notepad_update_cursor;
out_app->on_click = notepad_handle_click;
out_app->on_open_file = notepad_open_file;
out_app->on_prompt_done = notepad_prompt_done;
out_app->on_close_request = notepad_close_request;
out_app->on_dialog_done = notepad_dialog_done;
out_app->icon = notepad_icon;
Expand Down
2 changes: 1 addition & 1 deletion apps/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void shell_handle_char(char c) {
return;
}

if (c == KEY_CTRL_S || c == KEY_ARROW_LEFT || c == KEY_ARROW_RIGHT || c == KEY_HOME || c == KEY_END || c == KEY_DELETE) {
if (c == KEY_CTRL_S || c == KEY_CTRL_O || c == KEY_ARROW_LEFT || c == KEY_ARROW_RIGHT || c == KEY_HOME || c == KEY_END || c == KEY_DELETE) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions kernel/drivers/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ static void keyboard_callback(struct registers regs) {
if (ctrl_held) {
if (lower == 's') {
key_queue_push(KEY_CTRL_S);
} else if (lower == 'o') {
key_queue_push(KEY_CTRL_O);
}
return;
}
Expand Down
1 change: 1 addition & 0 deletions kernel/drivers/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define KEY_ESCAPE 27

#define KEY_CTRL_S 0x13
#define KEY_CTRL_O 0x0f

#define KEY_ARROW_UP 0x01
#define KEY_ARROW_DOWN 0x02
Expand Down
Loading