From owner-svn-soc-all@FreeBSD.ORG Wed Aug 6 21:50:13 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9E8C6C10 for ; Wed, 6 Aug 2014 21:50:13 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8156C2D73 for ; Wed, 6 Aug 2014 21:50:13 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s76LoDPF047787 for ; Wed, 6 Aug 2014 21:50:13 GMT (envelope-from pedrosouza@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s76LoCct047780 for svn-soc-all@FreeBSD.org; Wed, 6 Aug 2014 21:50:12 GMT (envelope-from pedrosouza@FreeBSD.org) Date: Wed, 6 Aug 2014 21:50:12 GMT Message-Id: <201408062150.s76LoCct047780@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to pedrosouza@FreeBSD.org using -f From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272006 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Aug 2014 21:50:13 -0000 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"] = {