mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 15:04:36 +03:00
config: add wezterm.gradient_colors
This commit is contained in:
parent
5aa4abbac4
commit
ab6c4777cb
@ -1,3 +1,4 @@
|
||||
use luahelper::impl_lua_conversion;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
|
||||
@ -158,6 +159,8 @@ pub struct Gradient {
|
||||
pub noise: Option<usize>,
|
||||
}
|
||||
|
||||
impl_lua_conversion!(Gradient);
|
||||
|
||||
impl Gradient {
|
||||
pub fn build(&self) -> anyhow::Result<colorgrad::Gradient> {
|
||||
use colorgrad::{BlendMode as CGMode, Interpolation as CGInterp};
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::Gradient;
|
||||
use crate::{FontAttributes, FontStretch, FontWeight, TextStyle};
|
||||
use anyhow::anyhow;
|
||||
use bstr::BString;
|
||||
@ -255,6 +256,7 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
|
||||
wezterm_mod.set("format", lua.create_function(format)?)?;
|
||||
wezterm_mod.set("strftime", lua.create_function(strftime)?)?;
|
||||
wezterm_mod.set("battery_info", lua.create_function(battery_info)?)?;
|
||||
wezterm_mod.set("gradient_colors", lua.create_function(gradient_colors)?)?;
|
||||
|
||||
package.set("path", path_array.join(";"))?;
|
||||
|
||||
@ -834,6 +836,17 @@ fn permute_mods<'lua>(
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn gradient_colors<'lua>(
|
||||
_lua: &'lua Lua,
|
||||
(gradient, num_colors): (Gradient, usize),
|
||||
) -> mlua::Result<Vec<String>> {
|
||||
let g = gradient.build().map_err(|e| mlua::Error::external(e))?;
|
||||
Ok(g.colors(num_colors)
|
||||
.into_iter()
|
||||
.map(|c| c.to_hex_string())
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
@ -78,6 +78,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* New: [wezterm.add_to_config_reload_watch_list](config/lua/wezterm/add_to_config_reload_watch_list.md) function to aid with automatically reloading the config when you've split your config across multiple files. Thanks to [@AusCyberman](https://github.com/AusCyberman)! [#989](https://github.com/wez/wezterm/pull/989)
|
||||
* Improved: wezterm now respects default emoji presentation and explicit emoji variation selectors (VS15 and VS16) so that glyphs that have both textual (usually monochrome, single cell width) and emoji (color, double width) presentations can be more faithfully rendered. [#997](https://github.com/wez/wezterm/issues/997)
|
||||
* New: [window_background_gradient](config/lua/config/window_background_gradient.md) option to configure color gradients for your window background
|
||||
* New: [wezterm.gradient_colors](config/lua/wezterm/gradient_colors.md) function to compute RGB values for gradients for use in your config.
|
||||
|
||||
### 20210502-154244-3f7122cb
|
||||
|
||||
|
21
docs/config/lua/wezterm/gradient_colors.md
Normal file
21
docs/config/lua/wezterm/gradient_colors.md
Normal file
@ -0,0 +1,21 @@
|
||||
# wezterm.gradient_colors(gradient, num_colors)
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Given a gradient spec and a number of colors, returns a table
|
||||
holding that many colors spaced evenly across the range of
|
||||
the gradient.
|
||||
|
||||
This is useful for example to generate colors for tabs, or
|
||||
to do something fancy like interpolate colors across a gradient
|
||||
based on the time of the day.
|
||||
|
||||
`gradient` is any gradient allowed by the
|
||||
[window_background_gradient](../config/window_background_gradient.md) option.
|
||||
|
||||
This example is what you'd see if you opened up the [debug overlay](../keyassignment/ShowDebugOverlay.md) to try this out in the repl:
|
||||
|
||||
```lua
|
||||
> wezterm.gradient_colors({preset="Rainbow"}, 4)
|
||||
["#6e40aa", "#ff8c38", "#5dea8d", "#6e40aa"]
|
||||
```
|
Loading…
Reference in New Issue
Block a user