Final touches for v0.10.0

pull/180/head v0.10.0
Arijit Basu 3 years ago committed by Arijit Basu
parent b99fa927bf
commit a80bf2d683

@ -1,11 +1,11 @@
use crate::app::App;
use crate::app::ExternalMsg;
use crate::app::VERSION;
use crate::config::Config;
use anyhow::bail;
use anyhow::Result;
use mlua::Lua;
use mlua::LuaSerdeExt;
use serde::Deserialize;
use serde::Serialize;
use std::fs;
const DEFAULT_LUA_SCRIPT: &str = include_str!("init.lua");
@ -33,14 +33,11 @@ pub fn check_version(version: &str, path: &str) -> Result<()> {
let (rmajor, rminor, rbugfix, rbeta) = parse_version(VERSION)?;
let (smajor, sminor, sbugfix, sbeta) = parse_version(version)?;
if rmajor == smajor && rminor == sminor && rbugfix <= sbugfix && rbeta == sbeta {
if rmajor == smajor && rminor == sminor && rbugfix >= sbugfix && rbeta == sbeta {
Ok(())
} else {
bail!(
"incompatible script version in {}
The script version is : {}
Required version is : {}
Visit {}",
"incompatible script version in: {}. The script version is: {}, the required version is: {}. Visit {}",
path,
version,
VERSION.to_string(),
@ -115,12 +112,16 @@ pub fn extend(lua: &Lua, path: &str) -> Result<Config> {
Ok(config)
}
/// Used to extend Lua globals
pub fn call(lua: &Lua, func: &str, args: &App) -> Result<Vec<ExternalMsg>> {
/// Used to call lua functions.
pub fn call<'lua, A: Serialize, R: Deserialize<'lua>>(
lua: &'lua Lua,
func: &str,
args: &A,
) -> Result<R> {
let func = resolve_fn(&lua.globals(), func)?;
let args = lua.to_value(args)?;
let msgs: mlua::Value = func.call((args,))?;
let msgs: Vec<ExternalMsg> = lua.from_value(msgs)?;
let msgs: mlua::Value = func.call(args)?;
let msgs: R = lua.from_value(msgs)?;
Ok(msgs)
}
@ -134,11 +135,9 @@ mod test {
assert!(check_version(VERSION, "foo path").is_ok());
assert!(check_version("0.10.0", "foo path").is_ok());
assert!(check_version("0.10.1", "foo path").is_err());
assert!(check_version("0.10.0-beta.6", "foo path").is_err());
assert!(check_version("0.9.0", "foo path").is_err());
assert!(check_version("0.11.0", "foo path").is_err());
assert!(check_version("0.10.0-beta.5", "foo path").is_err());
assert!(check_version("0.10.0-beta.7", "foo path").is_err());
assert!(check_version("1.10.0-beta.6", "foo path").is_err());
assert!(check_version("1.10.0", "foo path").is_err());
}
}

@ -2,7 +2,7 @@ use crate::app;
use crate::app::HelpMenuLine;
use crate::app::{Node, ResolvedNode};
use crate::config::PanelUiConfig;
use crate::lua::resolve_fn;
use crate::lua;
use indexmap::IndexSet;
use lazy_static::lazy_static;
use mlua::Lua;
@ -426,8 +426,6 @@ fn draw_table<B: Backend>(
let header_height = app_config.general().table().header().height().unwrap_or(1);
let height: usize = (layout_size.height.max(header_height + 2) - (header_height + 2)).into();
let globals = lua.globals();
let rows = app
.directory_buffer()
.map(|dir| {
@ -539,11 +537,10 @@ fn draw_table<B: Backend>(
.unwrap_or_default()
.iter()
.filter_map(|c| {
c.format()
.to_owned()
.and_then(|f| resolve_fn(&globals, &f).ok())
c.format().as_ref().map(|f| {
lua::call(lua, f, &v).unwrap_or_else(|e| e.to_string())
})
})
.map(|f| f.call((v.clone(),)).unwrap_or_else(|e| e.to_string()))
.collect::<Vec<String>>()
})
.unwrap_or_default()

Loading…
Cancel
Save