You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
Plaintext
81 lines
2.8 KiB
Plaintext
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"
|
|
import sdl "vendor:sdl2"
|
|
|
|
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
|
|
|
|
// 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" {
|
|
fmt.println("test", ini_map[section][key])
|
|
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 = sdl.Colour{red, green, blue, 255}
|
|
else if lower_case_key == "text" do config.colours.text = sdl.Colour{red, green, blue, 255}
|
|
else if lower_case_key == "line numbers" do config.colours.line_numbers = sdl.Colour{red, green, blue, 255}
|
|
else if lower_case_key == "line number background" do config.colours.line_numbers_background = sdl.Colour{
|
|
red, green, blue, 255
|
|
}
|
|
else if lower_case_key == "active tab" do config.colours.active_tab = sdl.Colour{red, green, blue, 255}
|
|
else if lower_case_key == "inactive tab" do config.colours.inactive_tab = sdl.Colour{red, green, blue, 255}
|
|
else if lower_case_key == "tab border" do config.colours.tab_border = sdl.Colour{red, green, blue, 255}
|
|
else if lower_case_key == "cursor" do config.colours.cursor = sdl.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)
|
|
}
|