forked from len0rd/rockbox
hwstub: Add completion and some pretty printing to the shell
This uses slightly hacked luaprompt to provide all the goodis. See https://github.com/dpapavas/luaprompt for original. Change-Id: Iedddb79abae5809299322bc215722dd928c35cca
This commit is contained in:
parent
465eb727a3
commit
e70ea5d21f
5 changed files with 1724 additions and 18 deletions
|
@ -26,7 +26,7 @@ $(REGTOOLS_LIB_DIR)/libsocdesc.a:
|
|||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
hwstub_shell: hwstub_shell.o $(LIBS)
|
||||
hwstub_shell: hwstub_shell.o prompt.o $(LIBS)
|
||||
$(LD) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
hwstub_load: hwstub_load.o $(LIBS)
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
#include <lua.hpp>
|
||||
#include <unistd.h>
|
||||
#include "soc_desc.hpp"
|
||||
extern "C" {
|
||||
#include "prompt.h"
|
||||
}
|
||||
|
||||
#if LUA_VERSION_NUM < 502
|
||||
#warning You need at least lua 5.2
|
||||
|
@ -941,21 +944,8 @@ int main(int argc, char **argv)
|
|||
printf("error: %s\n", lua_tostring(g_lua, -1));
|
||||
}
|
||||
|
||||
// use readline to provide some history and completion
|
||||
rl_bind_key('\t', rl_complete);
|
||||
while(!g_exit)
|
||||
{
|
||||
char *input = readline("> ");
|
||||
if(!input)
|
||||
break;
|
||||
add_history(input);
|
||||
// evaluate string
|
||||
if(luaL_dostring(g_lua, input))
|
||||
printf("error: %s\n", lua_tostring(g_lua, -1));
|
||||
// pop everything to start from a clean stack
|
||||
lua_pop(g_lua, lua_gettop(g_lua));
|
||||
free(input);
|
||||
}
|
||||
// start interactive shell
|
||||
luap_enter(g_lua, &g_exit);
|
||||
|
||||
Lerr:
|
||||
// display log if handled
|
||||
|
|
|
@ -22,6 +22,8 @@ function HWLIB.load_blob(filename, address)
|
|||
io.close(f)
|
||||
end
|
||||
|
||||
function HWLIB.printf(s,...)
|
||||
return io.write(s:format(...))
|
||||
function HWLIB.printf(...)
|
||||
local function wrapper(...) io.write(string.format(...)) end
|
||||
local status, result = pcall(wrapper, ...)
|
||||
if not status then error(result, 2) end
|
||||
end
|
||||
|
|
1659
utils/hwstub/tools/prompt.c
Normal file
1659
utils/hwstub/tools/prompt.c
Normal file
File diff suppressed because it is too large
Load diff
55
utils/hwstub/tools/prompt.h
Normal file
55
utils/hwstub/tools/prompt.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* Copyright (C) 2012-2015 Papavasileiou Dimitris
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _PROMPT_H_
|
||||
#define _PROMPT_H_
|
||||
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#define HAVE_LIBREADLINE
|
||||
#define HAVE_READLINE_HISTORY
|
||||
#define HAVE_IOCTL
|
||||
#define COMPLETE_KEYWORDS
|
||||
#define COMPLETE_MODULES
|
||||
#define COMPLETE_TABLE_KEYS
|
||||
#define COMPLETE_METATABLE_KEYS
|
||||
#define COMPLETE_FILE_NAMES
|
||||
|
||||
#define LUAP_VERSION "0.6"
|
||||
|
||||
void luap_setprompts(lua_State *L, const char *single, const char *multi);
|
||||
void luap_sethistory(lua_State *L, const char *file);
|
||||
void luap_setname(lua_State *L, const char *name);
|
||||
void luap_setcolor(lua_State *L, int enable);
|
||||
|
||||
void luap_getprompts(lua_State *L, const char **single, const char **multi);
|
||||
void luap_gethistory(lua_State *L, const char **file);
|
||||
void luap_getcolor(lua_State *L, int *enabled);
|
||||
void luap_getname(lua_State *L, const char **name);
|
||||
|
||||
void luap_enter(lua_State *L, bool *terminate);
|
||||
char *luap_describe (lua_State *L, int index);
|
||||
int luap_call (lua_State *L, int n);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue