diff --git a/src/config/font.rs b/src/config/font.rs index 186fc1d81..122664c24 100644 --- a/src/config/font.rs +++ b/src/config/font.rs @@ -41,7 +41,7 @@ impl Default for FontAntiAliasing { } } -#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] pub struct FontAttributes { /// The font family name pub family: String, @@ -74,7 +74,7 @@ impl Default for FontAttributes { } /// Represents textual styling. -#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] pub struct TextStyle { #[serde(default)] pub font: Vec, diff --git a/src/config/mod.rs b/src/config/mod.rs index f23073457..5645d1a0e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -9,7 +9,7 @@ use crate::keyassignment::KeyAssignment; use anyhow::{anyhow, bail, Context, Error}; use lazy_static::lazy_static; use portable_pty::{CommandBuilder, PtySize}; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std; use std::collections::HashMap; use std::convert::TryInto; diff --git a/src/scripting/mod.rs b/src/scripting/mod.rs index a3cf7a161..fd9e3d7a2 100644 --- a/src/scripting/mod.rs +++ b/src/scripting/mod.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use mlua::{Lua, Table}; +use mlua::{Lua, Table, Value}; use std::path::Path; mod serde_lua; @@ -122,17 +122,20 @@ fn hostname<'lua>(_: &'lua Lua, _: ()) -> mlua::Result { fn font_family<'lua>( lua: &'lua Lua, (family, map_defaults): (String, Option>), -) -> mlua::Result> { - let font_array = lua.create_table()?; - let font = lua.create_table()?; - font.set("family", family)?; - font_array.set(1, font)?; +) -> mlua::Result> { + use crate::config::{FontAttributes, TextStyle}; - let font_map = match map_defaults { - Some(tbl) => tbl, - None => lua.create_table()?, + let mut text_style: TextStyle = match map_defaults { + Some(def) => from_lua_value(Value::Table(def))?, + None => TextStyle::default(), }; - font_map.set("font", font_array)?; - Ok(font_map) + text_style.font.clear(); + text_style.font.push(FontAttributes { + family, + bold: false, + italic: false, + }); + + Ok(to_lua_value(lua, text_style)?) } diff --git a/src/scripting/serde_lua/mod.rs b/src/scripting/serde_lua/mod.rs index a5e913acc..8f51e177a 100644 --- a/src/scripting/serde_lua/mod.rs +++ b/src/scripting/serde_lua/mod.rs @@ -58,6 +58,12 @@ impl SerdeDeError for Error { } } +impl From for mlua::Error { + fn from(e: Error) -> mlua::Error { + mlua::Error::external(e) + } +} + #[derive(Debug)] struct ValueWrapper<'lua>(Value<'lua>); diff --git a/src/scripting/serde_lua/ser.rs b/src/scripting/serde_lua/ser.rs index 570f6368e..cfbfc596c 100644 --- a/src/scripting/serde_lua/ser.rs +++ b/src/scripting/serde_lua/ser.rs @@ -24,6 +24,12 @@ impl Error { } } +impl From for mlua::Error { + fn from(e: Error) -> mlua::Error { + mlua::Error::external(e) + } +} + impl SerError for Error { fn custom(msg: T) -> Self { Error::Custom {