socsvn commit: r272006 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua
pedrosouza at FreeBSD.org
pedrosouza at FreeBSD.org
Wed Aug 6 21:50:13 UTC 2014
Author: pedrosouza
Date: Wed Aug 6 21:50:12 2014
New Revision: 272006
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272006
Log:
Added autoboot timer before entering menu
Modified:
soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua
soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c
soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua
Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua Wed Aug 6 19:38:03 2014 (r272005)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua Wed Aug 6 21:50:12 2014 (r272006)
@@ -76,4 +76,8 @@
function core.autoboot()
loader.perform("autoboot");
+end
+
+function core.boot()
+ loader.perform("boot");
end
\ No newline at end of file
Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Wed Aug 6 19:38:03 2014 (r272005)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Wed Aug 6 21:50:12 2014 (r272006)
@@ -56,6 +56,12 @@
return 1;
}
+int lua_ischar(lua_State *L)
+{
+ lua_pushboolean(L, ischar());
+ return 1;
+}
+
int
lua_gets(lua_State *L)
{
@@ -66,6 +72,13 @@
}
int
+lua_time(lua_State *L)
+{
+ lua_pushnumber(L, time(NULL));
+ return 1;
+}
+
+int
lua_delay(lua_State *L)
{
int n = lua_gettop(L);
@@ -316,9 +329,11 @@
utils_func reg_funcs[] = {
{lua_perform, "loader", "perform"},
{lua_delay, "loader", "delay"},
+ {lua_time, "loader", "time"},
{lua_include, "loader", "include"},
{lua_getenv, "loader", "getenv"},
{lua_getchar, "io", "getchar"},
+ {lua_ischar, "io", "ischar"},
{lua_gets, "io", "gets"},
{lua_openfile, "io", "open"},
{lua_closefile, "io", "close"},
Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Wed Aug 6 19:38:03 2014 (r272005)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Wed Aug 6 21:50:12 2014 (r272006)
@@ -26,13 +26,18 @@
opts = menu.options;
end
- while true do
+ local draw = function()
screen.clear();
menu.draw(6, 11, opts);
menu.drawbox(4, 10, 40, 10);
drawer.drawbrand();
drawer.drawlogo();
screen.defcursor();
+ end
+
+ draw();
+ menu.autoboot();
+ while true do
local ch = string.char(io.getchar());
if (opts[ch] ~= nil) then
local ret = opts[ch].func();
@@ -52,6 +57,7 @@
end
end
end
+ draw();
end
end
@@ -79,18 +85,62 @@
for i = 1, h-1 do screen.setcursor(x+w, y+i); print(vl); end
end
+function menu.autoboot()
+ if menu.already_autoboot == true then
+ return;
+ end
+ menu.already_autoboot = true;
+
+ local ab = loader.getenv("autoboot_delay");
+ if ab == "NO" or ab == "no" then
+ core.boot();
+ end
+ ab = tonumber(ab) or 10;
+
+ local x = loader.getenv("loader_menu_timeout_x") or 5;
+ local y = loader.getenv("loader_menu_timeout_y") or 22;
+
+ local endtime = loader.time() + ab;
+ local time;
+ repeat
+
+ time = endtime - loader.time();
+ screen.setcursor(x, y);
+ print("Autoboot in "..time.." seconds, hit [Enter] to boot or any other key to stop ");
+ screen.defcursor();
+ if io.ischar() then
+ local ch = io.getchar();
+ if ch == 13 then
+ break;
+ else
+ -- prevent autoboot when escaping to interpreter
+ loader.perform("set autoboot_delay=NO");
+ -- erase autoboot msg
+ screen.setcursor(0, y);
+ print(" ");
+ screen.defcursor();
+ return;
+ end
+ end
+
+ loader.delay(50000);
+ until time <= 0
+ core.boot();
+
+end
+
menu.options = {
-- Boot multi user
["1"] = {
index = 1,
name = "Boot Multi user "..color.highlight("[Enter]"),
- func = function () core.setSingleUser(false); loader.perform("boot"); end
+ func = function () core.setSingleUser(false); core.boot(); end
},
-- boot single user
["2"] = {
index = 2,
name = "Boot "..color.highlight("S").."ingle user",
- func = function () core.setSingleUser(true); loader.perform("boot"); end
+ func = function () core.setSingleUser(true); core.boot(); end
},
-- escape to interpreter
["3"] = {
More information about the svn-soc-all
mailing list