2016-11-14 10:24:19 +03:00
|
|
|
package cfg
|
|
|
|
|
2018-04-13 19:50:10 +03:00
|
|
|
import (
|
2018-04-13 23:08:26 +03:00
|
|
|
"errors"
|
2018-04-21 21:50:31 +03:00
|
|
|
"github.com/felixangell/strife"
|
2018-04-13 19:50:10 +03:00
|
|
|
"log"
|
2018-04-21 21:50:31 +03:00
|
|
|
"regexp"
|
2018-04-13 19:50:10 +03:00
|
|
|
"strconv"
|
|
|
|
)
|
2016-11-27 21:06:17 +03:00
|
|
|
|
2016-11-14 11:14:53 +03:00
|
|
|
type TomlConfig struct {
|
2018-04-17 16:20:22 +03:00
|
|
|
Editor EditorConfig `toml:"editor"`
|
|
|
|
Cursor CursorConfig `toml:"cursor"`
|
|
|
|
Render RenderConfig `toml:"render"`
|
|
|
|
Theme ThemeConfig `toml:"theme"`
|
|
|
|
Associations map[string]FileAssociations `toml:"file_associations"`
|
|
|
|
Commands map[string]Command `toml:"commands"`
|
2018-04-13 23:08:26 +03:00
|
|
|
|
2018-04-17 16:20:22 +03:00
|
|
|
associations map[string]*LanguageSyntaxConfig
|
2018-04-13 23:08:26 +03:00
|
|
|
}
|
|
|
|
|
2018-04-17 16:20:22 +03:00
|
|
|
// GetSyntaxConfig returns a pointer to the parsed
|
|
|
|
// syntax language file for the given file extension
|
|
|
|
// e.g. what syntax def we need for a .cpp file or a .h file
|
|
|
|
func (t *TomlConfig) GetSyntaxConfig(ext string) (*LanguageSyntaxConfig, error) {
|
2018-04-13 23:08:26 +03:00
|
|
|
if val, ok := t.associations[ext]; ok {
|
|
|
|
return val, nil
|
|
|
|
}
|
2018-04-17 16:20:22 +03:00
|
|
|
return nil, errors.New("no language for extension '" + ext + "'")
|
2018-04-13 23:08:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type FileAssociations struct {
|
|
|
|
Extensions []string
|
2016-11-27 19:58:12 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 23:08:26 +03:00
|
|
|
type SyntaxCriteria struct {
|
2018-04-14 03:57:01 +03:00
|
|
|
Colour int `toml:"colouring"`
|
|
|
|
Match []string `toml:"match"`
|
|
|
|
Pattern string `toml:"pattern"`
|
2018-04-21 20:58:21 +03:00
|
|
|
|
2018-04-21 21:05:20 +03:00
|
|
|
CompiledPattern *regexp.Regexp
|
2018-04-21 21:50:31 +03:00
|
|
|
MatchList map[string]bool
|
2018-04-13 23:08:26 +03:00
|
|
|
}
|
|
|
|
|
2018-02-28 03:54:59 +03:00
|
|
|
type Command struct {
|
|
|
|
Shortcut string
|
|
|
|
}
|
|
|
|
|
2016-11-27 19:58:12 +03:00
|
|
|
type CursorConfig struct {
|
2016-12-03 08:38:33 +03:00
|
|
|
Flash_Rate int64
|
|
|
|
Reset_Delay int64
|
2016-11-27 19:58:12 +03:00
|
|
|
Draw bool
|
|
|
|
Flash bool
|
2016-11-27 21:06:17 +03:00
|
|
|
Block_Width string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c CursorConfig) GetCaretWidth() int {
|
|
|
|
if c.Block_Width == "block" {
|
|
|
|
return -1
|
|
|
|
}
|
2016-11-28 13:34:09 +03:00
|
|
|
if c.Block_Width == "" {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2016-11-27 21:06:17 +03:00
|
|
|
value, err := strconv.ParseInt(c.Block_Width, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return int(value)
|
2016-11-27 19:58:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type RenderConfig struct {
|
2018-04-17 23:38:52 +03:00
|
|
|
Aliased bool
|
|
|
|
Accelerated bool
|
|
|
|
Throttle_Cpu_Usage bool
|
|
|
|
Always_Render bool
|
|
|
|
Syntax_Highlighting bool
|
2016-11-27 19:58:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo make this more extendable...
|
2018-02-19 02:25:45 +03:00
|
|
|
// e.g. .phi-editor/themes with TOML
|
2016-11-27 19:58:12 +03:00
|
|
|
// themes in them and we can select
|
|
|
|
// the default theme in the EditorConfig
|
|
|
|
// instead.
|
|
|
|
type ThemeConfig struct {
|
2018-02-19 02:51:04 +03:00
|
|
|
Background int32
|
|
|
|
Foreground int32
|
|
|
|
Cursor int32
|
|
|
|
Cursor_Invert int32
|
2016-11-14 11:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type EditorConfig struct {
|
2016-12-03 08:38:33 +03:00
|
|
|
Tab_Size int
|
2016-11-27 21:06:17 +03:00
|
|
|
Hungry_Backspace bool
|
|
|
|
Tabs_Are_Spaces bool
|
|
|
|
Match_Braces bool
|
|
|
|
Maintain_Indentation bool
|
2016-11-28 13:34:09 +03:00
|
|
|
Highlight_Line bool
|
2018-04-15 21:18:01 +03:00
|
|
|
Font_Face string
|
|
|
|
Font_Size int
|
2018-04-16 21:17:45 +03:00
|
|
|
Show_Line_Numbers bool
|
2018-04-21 21:50:31 +03:00
|
|
|
Loaded_Font *strife.Font
|
2016-11-14 10:24:19 +03:00
|
|
|
}
|
|
|
|
|
2016-11-14 11:14:53 +03:00
|
|
|
func NewDefaultConfig() *TomlConfig {
|
2018-02-28 03:54:59 +03:00
|
|
|
log.Println("Loading default configuration... this should never happen")
|
2016-11-14 11:14:53 +03:00
|
|
|
return &TomlConfig{
|
2016-11-27 17:07:05 +03:00
|
|
|
Editor: EditorConfig{},
|
2016-11-27 19:58:12 +03:00
|
|
|
Theme: ThemeConfig{
|
2018-02-19 02:51:04 +03:00
|
|
|
Background: 0x002649,
|
|
|
|
Foreground: 0xf2f4f6,
|
|
|
|
Cursor: 0xf2f4f6,
|
|
|
|
Cursor_Invert: 0xffffff,
|
2016-11-27 19:58:12 +03:00
|
|
|
},
|
2016-11-14 10:24:19 +03:00
|
|
|
}
|
|
|
|
}
|