diff options
-rw-r--r-- | src/kilo.c | 21 | ||||
-rw-r--r-- | src/lua.c | 23 |
2 files changed, 32 insertions, 12 deletions
diff --git a/src/kilo.c b/src/kilo.c index 7ddfa39..22cf624 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -103,6 +103,7 @@ static struct editorConfig E; enum KEY_ACTION { KEY_NULL = 0, + CTRL_B = 2, CTRL_C = 3, CTRL_D = 4, CTRL_E = 5, @@ -667,6 +668,7 @@ static void editorMenu(void) { attroff(A_BOLD); } draw_menu_item("^g", "go"); + draw_menu_item("^b", "big picture"); draw_menu_item("^f", "find"); attrset(A_NORMAL); } @@ -1041,7 +1043,8 @@ static void editorGo(lua_State* L) { /* Process events arriving from the standard input, which is, the user * is typing stuff on the terminal. */ -int Quit = 0; +static int Quit = 0; +static int Back_to_big_picture = 0; static void editorProcessKeypress(lua_State* L) { int c = getch(); switch(c) { @@ -1061,6 +1064,12 @@ static void editorProcessKeypress(lua_State* L) { /* Go to a different definition. */ editorGo(L); break; + case CTRL_B: + /* Go to big-picture view. */ + editorSaveToDisk(); + Quit = 1; + Back_to_big_picture = 1; + break; case CTRL_F: editorFind(); break; @@ -1110,7 +1119,10 @@ static void initEditor(void) { E.syntax = &HLDB[0]; } -void edit(lua_State* L, char* filename, const char* message) { +/* return true if user chose to back into the big picture view */ +int edit(lua_State* L, char* filename, const char* message) { + Quit = 0; + Back_to_big_picture = 0; initEditor(); editorOpen(filename); editorSetStatusMessage(message); @@ -1118,13 +1130,16 @@ void edit(lua_State* L, char* filename, const char* message) { editorRefreshScreen(editorMenu); editorProcessKeypress(L); } + return Back_to_big_picture; } -void resumeEdit(lua_State* L) { +int resumeEdit(lua_State* L) { Quit = 0; + Back_to_big_picture = 0; editorSetStatusMessage(Previous_error); while(!Quit) { editorRefreshScreen(editorMenu); editorProcessKeypress(L); } + return Back_to_big_picture; } diff --git a/src/lua.c b/src/lua.c index d3eb29e..0ca8924 100644 --- a/src/lua.c +++ b/src/lua.c @@ -412,17 +412,16 @@ static void save_image (lua_State *L) { /* death and rebirth */ char **Argv = NULL; -extern void edit (lua_State *L, char *filename, const char *message); +extern int edit (lua_State *L, char *filename, const char *message); extern void clearEditor (void); extern int editorOpen (char *filename); -void edit_buffer (lua_State *L, const char *message) { - edit(L, "teliva_editbuffer", message); +int edit_buffer (lua_State *L, const char *message) { + return edit(L, "teliva_editbuffer", message); } void editor_refresh_buffer (void) { clearEditor(); editorOpen("teliva_editbuffer"); } -extern void resumeEdit (lua_State *L); int load_editor_buffer_to_current_definition_in_image(lua_State *L) { @@ -436,10 +435,13 @@ int load_editor_buffer_to_current_definition_in_image(lua_State *L) { } +/* return true if user chose to back into the big picture view */ +/* But only if there are no errors. Otherwise things can get confusing. */ const char *Previous_error = NULL; -void edit_image (lua_State *L, const char *definition) { +extern int resumeEdit (lua_State *L); +int edit_image (lua_State *L, const char *definition) { save_to_current_definition_and_editor_buffer(L, definition); - edit_buffer(L, /*status message*/ ""); + int back_to_big_picture = edit_buffer(L, /*status message*/ ""); // error handling while (1) { int status; @@ -448,9 +450,10 @@ void edit_image (lua_State *L, const char *definition) { break; Previous_error = lua_tostring(L, -1); if (Previous_error == NULL) Previous_error = "(error object is not a string)"; - resumeEdit(L); + back_to_big_picture = resumeEdit(L); lua_pop(L, 1); } + return back_to_big_picture; } @@ -600,7 +603,8 @@ int big_picture (lua_State *L) { } else if (c == ESC) { return 0; } else if (c == ENTER) { - edit_image(L, query); + int back_to_browse = edit_image(L, query); + if (back_to_browse) return big_picture(L); // retry while leaking stack return 1; } else if (c == CTRL_U) { qlen = 0; @@ -624,7 +628,8 @@ void switch_to_editor (lua_State *L) { for (int i = 0; i < 8; ++i) init_pair(i+8, -1, i); nodelay(stdscr, 0); - if (big_picture(L)) + int submitted = big_picture(L); + if (submitted) cleanup_curses(); execv(Argv[0], Argv); /* never returns */ |