experimenting with various ideas to avoid repeating code in config.rs
This commit is contained in:
@@ -10,6 +10,21 @@ use std::fs;
|
|||||||
use std::io::{Error, Result};
|
use std::io::{Error, Result};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
// macro_rules! generate_field_names {
|
||||||
|
// ($(#[$attr:meta])* struct $name:ident { $($fname:ident : $ftype:ty),* }) => {
|
||||||
|
// $(#[$attr])* struct $name {
|
||||||
|
// $($fname : $ftype),*
|
||||||
|
// }
|
||||||
|
|
||||||
|
// impl $name {
|
||||||
|
// fn field_names() -> &'static [&'static str] {
|
||||||
|
// static NAMES: &'static [&'static str] = &[$(stringify!($fname)),*];
|
||||||
|
// NAMES
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
conf_file: PathBuf,
|
conf_file: PathBuf,
|
||||||
|
|||||||
+1
-1
@@ -193,7 +193,7 @@ pub fn make_padding_string(len: usize) -> String {
|
|||||||
/// convert color setting to ansi escape sequence
|
/// convert color setting to ansi escape sequence
|
||||||
pub fn parse_color(color: String) -> Result<String> {
|
pub fn parse_color(color: String) -> Result<String> {
|
||||||
// check for numbered color
|
// check for numbered color
|
||||||
if let Ok(numbered) = color.parse::<u8>() {
|
if let Ok(numbered) = color.parse::<u8>() { // TODO: only accept numbers between 16 and 256
|
||||||
return Ok(generate_256color_sequence(
|
return Ok(generate_256color_sequence(
|
||||||
ColorContext::Foreground,
|
ColorContext::Foreground,
|
||||||
numbered,
|
numbered,
|
||||||
|
|||||||
Reference in New Issue
Block a user