Repurpose FocusFriend to get AntiDrift off the ground.
This commit is contained in:
33
config.py
33
config.py
@@ -1,33 +1,36 @@
|
||||
import json
|
||||
import os
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Block(BaseModel):
|
||||
name: str = ''
|
||||
prefix: str = ''
|
||||
postfix: str = ''
|
||||
items: List[str]
|
||||
name: str
|
||||
keywords: List[str]
|
||||
|
||||
|
||||
def load(filename: str) -> List[Block]:
|
||||
result = [Block(path=filename, **block) for block in block_list]
|
||||
return result
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
directory: str
|
||||
blocks: List[Block]
|
||||
start_as_user: bool = True
|
||||
sleep_time: int = 1
|
||||
aw_focus_cmd: str = "aw-focus"
|
||||
window_names: str = "window_names.txt"
|
||||
enforce_aw_commit: bool = True
|
||||
blackblocks: List[Block]
|
||||
whiteblocks: List[Block]
|
||||
check_delay: int = 1
|
||||
minimize_delay: int = 5
|
||||
blackblocks_only: bool = True
|
||||
|
||||
class Config:
|
||||
extra = 'forbid'
|
||||
|
||||
@classmethod
|
||||
def load_config(cls, config_file: str) -> Config:
|
||||
def load(cls, config_file: str) -> Config:
|
||||
config_file = os.path.expanduser(config_file)
|
||||
with open(config_file, 'r', encoding='utf8') as f:
|
||||
config_dict = json.load(f)
|
||||
with open(config_file, "r") as f:
|
||||
config_dict = yaml.safe_load(f)
|
||||
config = cls(**config_dict)
|
||||
config.directory = os.path.expanduser(config.directory)
|
||||
return config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user