Add unicode-based grapheme width estimation method

This commit is contained in:
Joscha 2025-02-23 18:31:20 +01:00
parent 900a686d0d
commit 17185ea536
5 changed files with 56 additions and 7 deletions

View file

@ -5,7 +5,7 @@ use std::{
};
use doc::Document;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
pub use crate::{euph::*, keys::*};
@ -21,6 +21,14 @@ pub enum Error {
Toml(#[from] toml::de::Error),
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, Document)]
#[serde(rename_all = "snake_case")]
pub enum WidthEstimationMethod {
#[default]
Legacy,
Unicode,
}
#[derive(Debug, Default, Deserialize, Document)]
pub struct Config {
/// The directory that cove stores its data in when not running in ephemeral
@ -41,12 +49,26 @@ pub struct Config {
#[serde(default)]
pub ephemeral: bool,
/// Whether to measure the width of characters as displayed by the terminal
/// emulator instead of guessing the width.
/// How to estimate the width of graphemes (i.e. characters) as displayed by
/// the terminal emulator.
///
/// `"legacy"`: Use a legacy method that should mostly work on most terminal
/// emulators. This method will never be correct in all cases since every
/// terminal emulator handles grapheme widths slightly differently. However,
/// those cases are usually rare (unless you view a lot of emoji).
///
/// `"unicode"`: Use the unicode standard in a best-effort manner to
/// determine grapheme widths.
///
/// This method is used when `measure_widths` is set to `false`.
#[serde(default)]
pub width_estimation_method: WidthEstimationMethod,
/// Whether to measure the width of graphemes (i.e. characters) as displayed
/// by the terminal emulator instead of estimating the width.
///
/// Enabling this makes rendering a bit slower but more accurate. The screen
/// might also flash when encountering new characters (or, more accurately,
/// graphemes).
/// might also flash when encountering new graphemes.
///
/// See also the `--measure-widths` command line option.
#[serde(default)]