summaryrefslogtreecommitdiff
path: root/apps/plugins/lua_scripts/fileview.lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua_scripts/fileview.lua')
-rwxr-xr-xapps/plugins/lua_scripts/fileview.lua79
1 files changed, 79 insertions, 0 deletions
diff --git a/apps/plugins/lua_scripts/fileview.lua b/apps/plugins/lua_scripts/fileview.lua
new file mode 100755
index 0000000000..920281bbef
--- /dev/null
+++ b/apps/plugins/lua_scripts/fileview.lua
@@ -0,0 +1,79 @@
1--[[
2 __________ __ ___.
3 Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 \/ \/ \/ \/ \/
8 $Id$
9 Example Lua File Viewer script
10 Copyright (C) 2017 William Wilgus
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 KIND, either express or implied.
17]]--
18
19require("actions") -- Contains rb.actions & rb.contexts
20-- require("buttons") -- Contains rb.buttons -- not needed for this example
21
22--local _timer = require("timer")
23--local _clr = require("color") -- clrset, clrinc provides device independent colors
24local _lcd = require("lcd") -- lcd helper functions
25--local _print = require("print") -- advanced text printing
26--local _img = require("image") -- image manipulation save, rotate, resize, tile, new, load
27--local _blit = require("blit") -- handy list of blit operations
28--local _draw = require("draw") -- draw all the things (primitives)
29--local _math = require("math_ex") -- missing math sine cosine, sqrt, clamp functions
30
31
32local scrpath = rb.current_path()--rb.PLUGIN_DIR .. "/demos/lua_scripts/"
33
34package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path
35
36require("printmenu") --menu
37require("filebrowse") -- file browser
38require("fileviewers") -- fileviewer, hexviewer
39
40rb.actions = nil
41package.loaded["actions"] = nil
42
43-- uses print_table to display a menu
44function main_menu()
45
46 local mt = {
47 [1] = "Rocklua File View Example",
48 [2] = "File View",
49 [3] = "File Hex View",
50 [4] = "Simple Browser",
51 [5] = "Exit"
52 }
53
54 local ft = {
55 [0] = exit_now, --if user cancels do this function
56 [1] = function(TITLE) return true end, -- shouldn't happen title occupies this slot
57 [2] = function(VIEWF) -- view file
58 print_file_increment(file_choose("/", "Choose File"))
59 end,
60 [3] = function(VHEXF) -- view hex
61 print_file_hex(file_choose("/", "Choose File"), 8)
62 end,
63 [4] = function(BROWS) -- file browser
64 _lcd:splashf(rb.HZ, "%s", file_choose("/") or "None")
65 end,
66 [5] = function(EXIT_) return true end
67 }
68
69 print_menu(mt, ft)
70
71end
72
73function exit_now()
74 _lcd:update()
75 os.exit()
76end -- exit_now
77
78main_menu()
79exit_now()