package main import "core:encoding/hex" import "core:encoding/ini" import "core:fmt" import "core:log" import "core:mem" import "core:strconv" import "core:strings" parse_config :: proc(config_path: string, allocator := context.allocator) -> (Config, bool) { ini_map, err, ok := ini.load_map_from_path(config_path, allocator=allocator) if err != nil { log.error("failed to parse config file") return {}, false } defer ini.delete_map(ini_map) config: Config config.font_size = DEFAULT_FONT_SIZE config.colours.background = DEFAULT_BACKGROUND_COLOUR config.colours.text = DEFAULT_TEXT_COLOUR config.colours.line_numbers = DEFAULT_LINE_NUMBERS_COLOUR config.colours.line_numbers_background = DEFAULT_LINE_NUMBER_BG_COLOUR config.colours.active_tab = DEFAULT_ACTIVE_TAB_COLOUR config.colours.inactive_tab = DEFAULT_INACTIVE_TAB_COLOUR config.colours.cursor = DEFAULT_CURSOR_COLOUR config.colours.highlight = DEFAULT_HIGHLIGHT_COLOUR config.colours.status_bar = DEFAULT_STATUS_BAR_COLOUR config.colours.status_bar_text = DEFAULT_STATUS_BAR_TEXT_COLUR // TODO: Tidy this up for section in ini_map { lower_case_section := strings.to_lower(section) defer delete(lower_case_section) if lower_case_section == "general" { for key, value in ini_map[section] { lower_case_key := strings.to_lower(key) defer delete(lower_case_key) if lower_case_key == "font" { config.font = strings.clone(ini_map[section][key]) } else if lower_case_key == "font size" { config.font_size = strconv.atoi(ini_map[section][key]) } } } else if lower_case_section == "colours" { for key, value in ini_map[section] { lower_case_key := strings.to_lower(key) defer delete(lower_case_key) red, green, blue, ok := hex_to_rgb(ini_map[section][key]) if !ok { log.error("failed to parse hex value for", lower_case_key) } if lower_case_key == "background" do config.colours.background = Colour{red, green, blue, 255} else if lower_case_key == "text" do config.colours.text = Colour{red, green, blue, 255} else if lower_case_key == "line numbers" do config.colours.line_numbers = Colour{red, green, blue, 255} else if lower_case_key == "line number background" do config.colours.line_numbers_background = Colour{ red, green, blue, 255 } else if lower_case_key == "active tab" do config.colours.active_tab = Colour{red, green, blue, 255} else if lower_case_key == "inactive tab" do config.colours.inactive_tab = Colour{red, green, blue, 255} else if lower_case_key == "tab border" do config.colours.tab_border = Colour{red, green, blue, 255} else if lower_case_key == "cursor" do config.colours.cursor = Colour{red, green, blue, 255} } } } if len(config.font) == 0 do config.font = strings.clone(DEFAULT_FONT) return config, true } config_destroy :: proc(config: Config, allocator := context.allocator) { delete(config.font) }