aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lpm.c1
-rw-r--r--lpm.lua4
-rw-r--r--plugins/plugin_manager/init.lua40
-rw-r--r--plugins/plugin_manager/plugin_view.lua43
4 files changed, 64 insertions, 24 deletions
diff --git a/lpm.c b/lpm.c
index 0c5d228..117e616 100644
--- a/lpm.c
+++ b/lpm.c
@@ -429,6 +429,7 @@ static int lpm_get(lua_State* L) {
const char* path = luaL_optstring(L, 2, NULL);
// curl_easy_reset(curl);
curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
if (path) {
FILE* file = fopen(path, "wb");
if (!file)
diff --git a/lpm.lua b/lpm.lua
index c0004d9..cab07c3 100644
--- a/lpm.lua
+++ b/lpm.lua
@@ -471,7 +471,7 @@ local function log_warning(message)
if not QUIET then io.stderr:write("warning: " .. message .. "\n") end
end
local function fatal_warning(message)
- if not FORCE then error(message) else log_warning(message) end
+ if not FORCE then error(message .. "; use --force to override") else log_warning(message) end
end
local function prompt(message)
io.stderr:write(message .. " [Y/n]: ")
@@ -1108,7 +1108,7 @@ xpcall(function()
local ARGS = parse_arguments(ARGV, {
json = "flag", userdir = "string", cachedir = "string", version = "flag", verbose = "flag",
quiet = "flag", version = "string", ["mod-version"] = "string", remotes = "flag", help = "flag",
- remotes = "flag", ssl_certs = "string", force = "string", arch = "string", ["assume-yes"] = "flag"
+ remotes = "flag", ssl_certs = "string", force = "flag", arch = "string", ["assume-yes"] = "flag"
})
if ARGS["version"] then
io.stdout:write(VERSION .. "\n")
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua
index 1769bd0..97ec914 100644
--- a/plugins/plugin_manager/init.lua
+++ b/plugins/plugin_manager/init.lua
@@ -5,8 +5,6 @@ local common = require "core.common"
local config = require "core.config"
local command = require "core.command"
local json = require "libraries.json"
-local keymap = require "core.keymap"
-local PluginView = require "plugins.plugin_manager.plugin_view"
local PluginManager = {
@@ -23,7 +21,11 @@ config.plugins.plugin_manager = common.merge({
-- Path to the folder that holds user-specified plugins.
userdir = USERDIR,
-- Path to ssl certificate directory.
- ssl_certs = nil
+ ssl_certs = nil,
+ -- Whether or not to force install things.
+ force = false,
+ -- Dumps commands that run to stdout, as well as responses from lpm.
+ debug = true
}, config.plugins.plugin_manager)
if not config.plugins.plugin_manager.lpm_binary_path then
@@ -68,8 +70,10 @@ local function run(cmd)
table.insert(cmd, "--mod-version=" .. MOD_VERSION)
table.insert(cmd, "--quiet")
table.insert(cmd, "--userdir=" .. USERDIR)
- -- print(table.unpack(cmd))
+ table.insert(cmd, "--assume-yes")
+ if config.plugins.plugin_manager.force then table.insert(cmd, "--force") end
local proc = process.start(cmd)
+ if config.plugins.plugin_manager.debug then for i, v in ipairs(cmd) do print((i > 1 and " " or "") .. v) end end
local promise = Promise.new()
table.insert(running_processes, { proc, promise, "" })
if #running_processes == 1 then
@@ -83,6 +87,7 @@ local function run(cmd)
local still_running = true
while true do
local chunk = v[1]:read_stdout(2048)
+ if config.plugins.plugin_manager.debug then print(chunk) end
if chunk and #chunk == 0 then break end
if chunk ~= nil then
v[3] = v[3] .. chunk
@@ -128,6 +133,19 @@ function PluginManager:refresh()
end
+function PluginManager:get_plugins()
+ local prom = Promise.new()
+ if self.plugins then
+ prom:resolve(self.plugins)
+ else
+ self:refresh():done(function()
+ prom:resolve(self.plugins)
+ end)
+ end
+ return prom
+end
+
+
function PluginManager:install(plugin)
local promise = Promise.new()
run({ "plugin", "install", plugin.name .. (plugin.version and (":" .. plugin.version) or "") }):done(function(result)
@@ -195,15 +213,11 @@ command.add(nil, {
["plugin-manager:refresh"] = function() PluginManager:refresh():done(function() core.log("Successfully refreshed plugin listing.") end) end,
})
-PluginManager.view = PluginView
-PluginManager:refresh()
-
+PluginManager.promise = Promise
+PluginManager.initialized = Promise.new()
+PluginManager:refresh():done(function()
+ PluginManager.initialized:resolve()
+end)
-keymap.add {
- ["up"] = "plugin-manager:select-prev",
- ["down"] = "plugin-manager:select-next",
- ["lclick"] = "plugin-manager:select",
- ["2lclick"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" }
-}
return PluginManager
diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua
index 5d5af8e..f661b00 100644
--- a/plugins/plugin_manager/plugin_view.lua
+++ b/plugins/plugin_manager/plugin_view.lua
@@ -9,7 +9,7 @@ local View = require "core.view"
local keymap = require "core.keymap"
local RootView = require "core.rootview"
local ContextMenu = require "core.contextmenu"
-
+local PluginManager = require "plugins.plugin_manager"
local PluginView = View:extend()
@@ -34,11 +34,15 @@ function PluginView:new()
self.scrollable = true
self.show_incompatible_plugins = false
self.plugin_table_columns = { "Name", "Version", "Modversion", "Status", "Tags", "Description" }
- self:refresh()
self.hovered_plugin = nil
self.hovered_plugin_idx = nil
self.selected_plugin = nil
self.selected_plugin_idx = nil
+ self.initialized = false
+ PluginManager.initialized:done(function()
+ self.initialized = true
+ self:refresh()
+ end)
plugin_view = self
end
@@ -82,11 +86,13 @@ end
function PluginView:on_mouse_moved(x, y, dx, dy)
PluginView.super.on_mouse_moved(self, x, y, dx, dy)
- local th = style.font:get_height()
- local lh = th + style.padding.y
- local offset = math.floor((y - self.position.y + self.scroll.y) / lh)
- self.hovered_plugin = offset > 0 and self:get_plugins()[offset]
- self.hovered_plugin_idx = offset > 0 and offset
+ if self.initialized then
+ local th = style.font:get_height()
+ local lh = th + style.padding.y
+ local offset = math.floor((y - self.position.y + self.scroll.y) / lh)
+ self.hovered_plugin = offset > 0 and self:get_plugins()[offset]
+ self.hovered_plugin_idx = offset > 0 and offset
+ end
end
@@ -105,13 +111,14 @@ end
function PluginView:get_plugins()
- if self.show_incompatible_plugins then return PluginManager.plugins end
- return PluginManager.valid_plugins
+ return self.show_incompatible_plugins and PluginManager.plugins or PluginManager.valid_plugins
end
function PluginView:get_scrollable_size()
+ if not self.initialized then return math.huge end
local th = style.font:get_height() + style.padding.y
+ local plugins = self:get_plugins()
return th * #self:get_plugins()
end
@@ -123,6 +130,7 @@ end
function PluginView:draw()
self:draw_background(style.background)
+ if not self.initialized then return end
local th = style.font:get_height()
local lh = th + style.padding.y
@@ -174,6 +182,14 @@ function PluginView:uninstall(plugin)
end
+command.add(nil, {
+ ["plugin-manager:show"] = function()
+ local node = core.root_view:get_active_node_default()
+ node:add_view(PluginView())
+ end
+})
+
+
command.add(PluginView, {
["plugin-manager:select"] = function(x, y)
plugin_view.selected_plugin, plugin_view.selected_plugin_idx = plugin_view.hovered_plugin, plugin_view.hovered_plugin_idx
@@ -200,4 +216,13 @@ end, {
["plugin-manager:uninstall-hovered"] = function() plugin_view:uninstall(plugin_view.hovered_plugin) end
})
+
+keymap.add {
+ ["up"] = "plugin-manager:select-prev",
+ ["down"] = "plugin-manager:select-next",
+ ["lclick"] = "plugin-manager:select",
+ ["2lclick"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" }
+}
+
+
return PluginView