mirror of
https://github.com/wez/wezterm.git
synced 2024-12-01 00:35:46 +03:00
lua: use to_lua_value for wezterm.font
This is now more type-safe and clearer to read.
This commit is contained in:
parent
fa01ca59ca
commit
8b9fcd3063
@ -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<FontAttributes>,
|
||||
|
@ -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;
|
||||
|
@ -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<String> {
|
||||
fn font_family<'lua>(
|
||||
lua: &'lua Lua,
|
||||
(family, map_defaults): (String, Option<Table<'lua>>),
|
||||
) -> mlua::Result<Table<'lua>> {
|
||||
let font_array = lua.create_table()?;
|
||||
let font = lua.create_table()?;
|
||||
font.set("family", family)?;
|
||||
font_array.set(1, font)?;
|
||||
) -> mlua::Result<Value<'lua>> {
|
||||
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)?)
|
||||
}
|
||||
|
@ -58,6 +58,12 @@ impl SerdeDeError for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for mlua::Error {
|
||||
fn from(e: Error) -> mlua::Error {
|
||||
mlua::Error::external(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ValueWrapper<'lua>(Value<'lua>);
|
||||
|
||||
|
@ -24,6 +24,12 @@ impl Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for mlua::Error {
|
||||
fn from(e: Error) -> mlua::Error {
|
||||
mlua::Error::external(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl SerError for Error {
|
||||
fn custom<T: std::fmt::Display>(msg: T) -> Self {
|
||||
Error::Custom {
|
||||
|
Loading…
Reference in New Issue
Block a user