yum/FastTextPager

Compressed text paging over OSC.

git clone https://git.yummers.dev/yum/FastTextPager

yumMove core app logic into folder0ebc793

master
1.1 KiB39 linesraw
1import os
2import sys
3import typing
4
5def getConfig(path: str) -> typing.Dict[str, typing.Union[str, float, int, bool]]:
6    # Helper functions to detect and convert the type
7    def is_int(value: str) -> bool:
8        try:
9            int(value)
10            return True
11        except ValueError:
12            return False
13
14    def is_float(value: str) -> bool:
15        try:
16            float(value)
17            return True
18        except ValueError:
19            return False
20
21    def convert_value(key: str, value: str):
22        if key.startswith(("enable_", "remove_", "use_", "clear_")):
23            return bool(int(value))
24        elif is_int(value):
25            return int(value)
26        elif is_float(value):
27            return float(value)
28        else:
29            return value
30
31    config = {}
32    with open(path, 'r') as file:
33        for line in file:
34            key_value = line.strip().split(": ", maxsplit=1)
35            key = key_value[0]
36            value = key_value[1] if len(key_value) > 1 else ""
37            config[key] = convert_value(key, value.strip())
38    return config
39