reorg: pull Teliva-specific stuff out of lua.c
It should now be easier to diff against the Lua 5.1 sources upstream.
This commit is contained in:
parent
1fdfa8909b
commit
bb6e79aa0d
|
@ -26,9 +26,9 @@ LUA_A= liblua.a
|
|||
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
|
||||
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
|
||||
lundump.o lvm.o lzio.o \
|
||||
kilo.o tlv.o
|
||||
LIB_O= lauxlib.o lbaselib.o menu.o ldblib.o liolib.o lmathlib.o \
|
||||
loslib.o ltablib.o lstrlib.o loadlib.o linit.o
|
||||
kilo.o tlv.o teliva.o
|
||||
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o \
|
||||
ltablib.o lstrlib.o loadlib.o linit.o
|
||||
|
||||
LUA_T= teliva
|
||||
LUA_O= lua.o
|
||||
|
|
11
src/kilo.c
11
src/kilo.c
|
@ -656,15 +656,11 @@ writeerr:
|
|||
|
||||
/* ============================= Terminal update ============================ */
|
||||
|
||||
extern char *Previous_error;
|
||||
extern void draw_menu_item(const char* key, const char* name);
|
||||
|
||||
static void editorMenu(void) {
|
||||
attrset(A_REVERSE);
|
||||
for (int x = 0; x < COLS; ++x)
|
||||
mvaddch(LINES-1, x, ' ');
|
||||
attrset(A_NORMAL);
|
||||
extern int menu_column;
|
||||
menu_column = 2;
|
||||
draw_menu_item("^e", "run");
|
||||
if (Previous_error != NULL) {
|
||||
|
@ -695,13 +691,11 @@ static void editorMenu(void) {
|
|||
attrset(A_NORMAL);
|
||||
}
|
||||
|
||||
extern void draw_string_on_menu (const char* s);
|
||||
static void editorFindMenu(void) {
|
||||
attrset(A_REVERSE);
|
||||
for (int x = 0; x < COLS; ++x)
|
||||
mvaddch(LINES-1, x, ' ');
|
||||
attrset(A_NORMAL);
|
||||
extern int menu_column;
|
||||
menu_column = 2;
|
||||
draw_menu_item("^x", "cancel");
|
||||
draw_menu_item("Enter", "submit");
|
||||
|
@ -727,7 +721,6 @@ static void editorGoMenu(void) {
|
|||
for (int x = 0; x < COLS; ++x)
|
||||
mvaddch(LINES-1, x, ' ');
|
||||
attrset(A_NORMAL);
|
||||
extern int menu_column;
|
||||
menu_column = 2;
|
||||
draw_menu_item("^x", "cancel");
|
||||
draw_menu_item("Enter", "submit");
|
||||
|
@ -736,7 +729,6 @@ static void editorGoMenu(void) {
|
|||
attrset(A_NORMAL);
|
||||
}
|
||||
|
||||
extern int render_previous_error();
|
||||
static void editorRefreshScreen(void (*menu_func)(void)) {
|
||||
int y;
|
||||
erow *r;
|
||||
|
@ -1031,8 +1023,6 @@ void word_at_cursor(char* out, int capacity) {
|
|||
}
|
||||
|
||||
/* Jump to some definition. */
|
||||
extern void save_to_current_definition_and_editor_buffer(lua_State *L, char *name);
|
||||
extern void load_editor_buffer_to_current_definition_in_image(lua_State *L);
|
||||
extern char Current_definition[];
|
||||
#define CURRENT_DEFINITION_LEN 256
|
||||
static void editorGo(lua_State* L) {
|
||||
|
@ -1078,7 +1068,6 @@ static void editorGo(lua_State* L) {
|
|||
* is typing stuff on the terminal. */
|
||||
static int Quit = 0;
|
||||
static int Back_to_big_picture = 0;
|
||||
extern void save_editor_state(int rowoff, int coloff, int cy, int cx);
|
||||
static void editorProcessKeypress(lua_State* L) {
|
||||
int c = getch();
|
||||
//? mvprintw(LINES-3, 60, "key: %d\n", c);
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
|
||||
|
||||
|
||||
extern char *Image_name;
|
||||
|
||||
|
||||
/* mark for precompiled code (`<esc>Lua') */
|
||||
#define LUA_SIGNATURE "\033Lua"
|
||||
|
||||
|
|
49
src/menu.c
49
src/menu.c
|
@ -1,49 +0,0 @@
|
|||
#include <ncurses.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "teliva.h"
|
||||
|
||||
|
||||
int menu_column = 0;
|
||||
void draw_string_on_menu (const char* s) {
|
||||
mvaddstr(LINES-1, menu_column, " ");
|
||||
++menu_column;
|
||||
mvaddstr(LINES-1, menu_column, s);
|
||||
menu_column += strlen(s);
|
||||
mvaddstr(LINES-1, menu_column, " ");
|
||||
++menu_column;
|
||||
}
|
||||
void draw_menu_item (const char* key, const char* name) {
|
||||
attroff(A_REVERSE);
|
||||
draw_string_on_menu(key);
|
||||
attron(A_REVERSE);
|
||||
draw_string_on_menu(name);
|
||||
}
|
||||
|
||||
void draw_menu (lua_State *L) {
|
||||
attron(A_BOLD|A_REVERSE|COLOR_PAIR(COLOR_PAIR_MENU));
|
||||
for (int x = 0; x < COLS; ++x)
|
||||
mvaddch(LINES-1, x, ' ');
|
||||
menu_column = 2;
|
||||
draw_menu_item("^x", "exit");
|
||||
draw_menu_item("^e", "edit");
|
||||
|
||||
/* render any app-specific items */
|
||||
lua_getglobal(L, "menu");
|
||||
int table = lua_gettop(L);
|
||||
if (lua_istable(L, -1)) {
|
||||
for (int i = 1; i <= luaL_getn(L, table); ++i) {
|
||||
lua_rawgeti(L, table, i);
|
||||
int menu_item = lua_gettop(L);
|
||||
lua_rawgeti(L, menu_item, 1); /* key */
|
||||
lua_rawgeti(L, menu_item, 2); /* value */
|
||||
draw_menu_item(lua_tostring(L, -2), lua_tostring(L, -1));
|
||||
lua_pop(L, 3);
|
||||
}
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
attrset(A_NORMAL);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
29
src/teliva.h
29
src/teliva.h
|
@ -1,6 +1,35 @@
|
|||
#ifndef __TELIVA_H__
|
||||
#define __TELIVA_H__
|
||||
|
||||
/* Each category of primitives below shows a few options from high to low
|
||||
* levels of abstraction.
|
||||
* (Lower levels aren't complete or well-designed, just what code outside
|
||||
* teliva.c needs.) */
|
||||
|
||||
/* Integrate with Lua VM */
|
||||
extern char** Argv;
|
||||
extern int handle_image(lua_State* L, char** argv, int n);
|
||||
|
||||
extern int load_editor_buffer_to_current_definition_in_image(lua_State* L);
|
||||
extern void save_to_current_definition_and_editor_buffer(lua_State* L, const char* definition);
|
||||
extern void save_editor_state(int rowoff, int coloff, int cy, int cx);
|
||||
|
||||
/* Standard UI elements */
|
||||
extern void render_trusted_teliva_data(lua_State* L);
|
||||
|
||||
extern void draw_menu_item(const char* key, const char* name);
|
||||
|
||||
extern void draw_string_on_menu(const char* s);
|
||||
|
||||
extern int menu_column;
|
||||
|
||||
/* Error reporting */
|
||||
|
||||
extern const char* Previous_error;
|
||||
extern int report_in_developer_mode(lua_State* L, int status);
|
||||
|
||||
extern void render_previous_error(void);
|
||||
|
||||
// Some names for hotkeys beyond those provided by ncurses.
|
||||
|
||||
enum KEY_ACTION {
|
||||
|
|
15
src/tlv.c
15
src/tlv.c
|
@ -184,3 +184,18 @@ void save_tlv(lua_State* L, char* filename) {
|
|||
rename(outfilename, filename);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
static const char* special_history_keys[] = {
|
||||
"__teliva_timestamp",
|
||||
"__teliva_undo",
|
||||
"__teliva_note",
|
||||
NULL,
|
||||
};
|
||||
|
||||
int is_special_history_key(const char* key) {
|
||||
for (const char** curr = special_history_keys; *curr != NULL; ++curr) {
|
||||
if (strcmp(*curr, key) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue