mirror of
https://github.com/felixangell/phi.git
synced 2024-10-05 12:17:20 +03:00
cleanups; more default config settings
This commit is contained in:
parent
4515cc3f4a
commit
3a493dd378
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.14
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.2
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/felixangell/strife v0.2.0
|
||||
github.com/felixangell/strife v0.2.1
|
||||
github.com/fsnotify/fsnotify v1.4.9
|
||||
github.com/lithammer/fuzzysearch v1.1.1
|
||||
github.com/stretchr/testify v1.6.1
|
||||
|
2
go.sum
2
go.sum
@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/felixangell/strife v0.2.0 h1:UoKznQghuOC/pio4C1eYBGd5z23H+u2GJXHhGytuf60=
|
||||
github.com/felixangell/strife v0.2.0/go.mod h1:I48zwoDuHBbURAmbBqjh3CzqVa4+yoAKePtfyj5v7po=
|
||||
github.com/felixangell/strife v0.2.1 h1:H6T5gIFE8qd5H1i1u5xcG56OTUNhEz8g5AIByZEh/Xg=
|
||||
github.com/felixangell/strife v0.2.1/go.mod h1:I48zwoDuHBbURAmbBqjh3CzqVa4+yoAKePtfyj5v7po=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/lithammer/fuzzysearch v1.1.1 h1:8F9OAV2xPuYblToVohjanztdnPjbtA0MLgMvDKQ0Z08=
|
||||
|
@ -125,7 +125,7 @@ type Buffer struct {
|
||||
index int
|
||||
parent *BufferView
|
||||
curs *Cursor
|
||||
cfg *cfg.TomlConfig
|
||||
cfg *cfg.PhiEditorConfig
|
||||
buffOpts BufferConfig
|
||||
cam *camera
|
||||
table *piecetable.PieceTable
|
||||
@ -137,23 +137,12 @@ type Buffer struct {
|
||||
}
|
||||
|
||||
// NewBuffer creates a new buffer with the given configurations
|
||||
func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *BufferView, index int) *Buffer {
|
||||
func NewBuffer(conf *cfg.PhiEditorConfig, buffOpts BufferConfig, parent *BufferView, index int) *Buffer {
|
||||
config := conf
|
||||
if config == nil {
|
||||
config = cfg.NewDefaultConfig()
|
||||
}
|
||||
|
||||
// TODO we load the font in config, instead
|
||||
// we should load it when used, for example here.
|
||||
// DPI FIX.
|
||||
newSize := int(float64(config.Editor.FontSize) * cfg.ScaleFactor)
|
||||
scaledFont, err := config.Editor.LoadedFont.DeriveFont(newSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("loading new font thing")
|
||||
config.Editor.LoadedFont = scaledFont
|
||||
|
||||
curs := sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_IBEAM)
|
||||
|
||||
// TODO do this only if we are hovering over the buffer
|
||||
@ -209,8 +198,8 @@ func (s *selection) renderAt(ctx *strife.Renderer, _ int, _ int) {
|
||||
width = s.ex * lastCharW
|
||||
}
|
||||
|
||||
xPos := (s.sx * lastCharW)
|
||||
yPos := ((s.sy + y) * (lastCharH + pad))
|
||||
xPos := s.sx * lastCharW
|
||||
yPos := (s.sy + y) * (lastCharH + pad)
|
||||
|
||||
ctx.SetColor(strife.Blue)
|
||||
ctx.Rect(b.ex+xPos, b.ey+yPos, width, height, strife.Fill)
|
||||
|
@ -2,9 +2,6 @@ package buff
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/felixangell/phi/internal/cfg"
|
||||
"github.com/felixangell/phi/internal/gui"
|
||||
"github.com/felixangell/strife"
|
||||
@ -19,18 +16,10 @@ type BufferPane struct {
|
||||
}
|
||||
|
||||
func NewBufferPane(buff *Buffer) *BufferPane {
|
||||
fontPath := filepath.Join(cfg.FontFolder, buff.cfg.Editor.FontFace+".ttf")
|
||||
// FIXME DPI
|
||||
metaPanelFont, err := strife.LoadFont(fontPath, int(14.0*cfg.ScaleFactor))
|
||||
if err != nil {
|
||||
log.Println("Note: failed to load meta panel font ", fontPath)
|
||||
metaPanelFont = buff.buffOpts.font
|
||||
}
|
||||
|
||||
return &BufferPane{
|
||||
gui.BaseComponent{},
|
||||
buff,
|
||||
metaPanelFont,
|
||||
gui.GetDefaultFont(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ type CommandPalette struct {
|
||||
gui.BaseComponent
|
||||
buff *Buffer
|
||||
parentBuff *Buffer
|
||||
conf *cfg.TomlConfig
|
||||
conf *cfg.PhiEditorConfig
|
||||
parent *BufferView
|
||||
|
||||
pathToIndex map[string]int
|
||||
@ -80,12 +80,12 @@ func (s *suggestion) render(x, y int, ctx *strife.Renderer) {
|
||||
ctx.Text(s.name, x+border, y+yOffs)
|
||||
}
|
||||
|
||||
func NewCommandPalette(conf cfg.TomlConfig, view *BufferView) *CommandPalette {
|
||||
func NewCommandPalette(conf cfg.PhiEditorConfig, view *BufferView) *CommandPalette {
|
||||
conf.Editor.ShowLineNumbers = false
|
||||
conf.Editor.HighlightLine = false
|
||||
|
||||
newSize := int(float64(conf.Editor.FontSize) * cfg.ScaleFactor)
|
||||
paletteFont, err := conf.Editor.LoadedFont.DeriveFont(newSize)
|
||||
paletteFont, err := gui.GetDefaultFont().DeriveFont(newSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func (r *reloadBufferEvent) String() string {
|
||||
type BufferView struct {
|
||||
gui.BaseComponent
|
||||
|
||||
conf *cfg.TomlConfig
|
||||
conf *cfg.PhiEditorConfig
|
||||
buffers []*BufferPane
|
||||
focusedBuff int
|
||||
commandPalette *CommandPalette
|
||||
@ -48,7 +48,7 @@ type BufferView struct {
|
||||
|
||||
// NewView creaets a new view with the given width and height
|
||||
// as well as configurations.
|
||||
func NewView(width, height int, conf *cfg.TomlConfig) *BufferView {
|
||||
func NewView(width, height int, conf *cfg.PhiEditorConfig) *BufferView {
|
||||
view := &BufferView{
|
||||
conf: conf,
|
||||
buffers: []*BufferPane{},
|
||||
@ -392,7 +392,7 @@ func (n *BufferView) AddBuffer() *Buffer {
|
||||
conf.Theme.HighlightLineBackground,
|
||||
conf.Theme.GutterBackground,
|
||||
conf.Theme.GutterForeground,
|
||||
conf.Editor.LoadedFont,
|
||||
gui.GetDefaultFont(),
|
||||
}, n, len(n.buffers))
|
||||
|
||||
c.SetFocus(true)
|
||||
|
@ -5,11 +5,9 @@ import (
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/felixangell/strife"
|
||||
)
|
||||
|
||||
type TomlConfig struct {
|
||||
type PhiEditorConfig struct {
|
||||
Editor *EditorConfig `toml:"editor"`
|
||||
Cursor *CursorConfig `toml:"cursor"`
|
||||
Render *RenderConfig `toml:"render"`
|
||||
@ -23,7 +21,7 @@ type TomlConfig struct {
|
||||
// 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) {
|
||||
func (t *PhiEditorConfig) GetSyntaxConfig(ext string) (*LanguageSyntaxConfig, error) {
|
||||
if val, ok := t.associations[ext]; ok {
|
||||
return val, nil
|
||||
}
|
||||
@ -72,12 +70,12 @@ func (c CursorConfig) GetCaretWidth() int {
|
||||
}
|
||||
|
||||
type RenderConfig struct {
|
||||
Aliased bool `toml:"aliased"`
|
||||
Accelerated bool `toml:"accelerated"`
|
||||
ThrottleCpuUsage bool `toml:"throttle_cpu_usage"`
|
||||
AlwaysRender bool `toml:"always_render"`
|
||||
VerticalSync bool `toml:"vertical_sync"`
|
||||
SyntaxHighlighting bool `toml:"syntax_highlighting"`
|
||||
Aliased bool `toml:"aliased"`
|
||||
Accelerated bool `toml:"accelerated"`
|
||||
ThrottleCpuUsage bool `toml:"throttle_cpu_usage"`
|
||||
AlwaysRender bool `toml:"always_render"`
|
||||
VerticalSync bool `toml:"vertical_sync"`
|
||||
SyntaxHighlighting bool `toml:"syntax_highlighting"`
|
||||
FrameSleepInterval uint32 `toml:"frame_sleep_interval"`
|
||||
}
|
||||
|
||||
@ -113,17 +111,16 @@ type PaletteConfig struct {
|
||||
}
|
||||
|
||||
type EditorConfig struct {
|
||||
TabSize int `toml:"tab_size"`
|
||||
HungryBackspace bool `toml:"hungry_backspace"`
|
||||
TabsAreSpaces bool `toml:"tabs_are_spaces"`
|
||||
MatchBraces bool `toml:"match_braces"`
|
||||
MaintainIndentation bool `toml:"maintain_indentation"`
|
||||
HighlightLine bool `toml:"highlight_line"`
|
||||
FontPath string `toml:"font_path"`
|
||||
FontFace string `toml:"font_face"`
|
||||
FontSize int `toml:"font_size"`
|
||||
ShowLineNumbers bool `toml:"show_line_numbers"`
|
||||
LoadedFont *strife.Font `toml:"loaded_font"`
|
||||
TabSize int `toml:"tab_size"`
|
||||
HungryBackspace bool `toml:"hungry_backspace"`
|
||||
TabsAreSpaces bool `toml:"tabs_are_spaces"`
|
||||
MatchBraces bool `toml:"match_braces"`
|
||||
MaintainIndentation bool `toml:"maintain_indentation"`
|
||||
HighlightLine bool `toml:"highlight_line"`
|
||||
FontPath string `toml:"font_path"`
|
||||
FontFace string `toml:"font_face"`
|
||||
FontSize int `toml:"font_size"`
|
||||
ShowLineNumbers bool `toml:"show_line_numbers"`
|
||||
}
|
||||
|
||||
type shortcutConfig struct {
|
||||
@ -136,9 +133,9 @@ var Shortcuts = shortcutConfig{
|
||||
Controls: map[string]string{},
|
||||
}
|
||||
|
||||
func NewDefaultConfig() *TomlConfig {
|
||||
func NewDefaultConfig() *PhiEditorConfig {
|
||||
log.Println("Loading default configuration")
|
||||
return &TomlConfig{
|
||||
return &PhiEditorConfig{
|
||||
Render: &RenderConfig{
|
||||
Aliased: true,
|
||||
Accelerated: true,
|
||||
@ -147,13 +144,31 @@ func NewDefaultConfig() *TomlConfig {
|
||||
VerticalSync: true,
|
||||
SyntaxHighlighting: true,
|
||||
},
|
||||
Editor: &EditorConfig{},
|
||||
Editor: &EditorConfig{
|
||||
TabSize: 4,
|
||||
HungryBackspace: false,
|
||||
TabsAreSpaces: true,
|
||||
MatchBraces: true,
|
||||
MaintainIndentation: true,
|
||||
HighlightLine: true,
|
||||
FontPath: "/Library/Fonts",
|
||||
FontFace: "Arial Unicode",
|
||||
FontSize: 24,
|
||||
ShowLineNumbers: true,
|
||||
},
|
||||
Theme: &ThemeConfig{
|
||||
Background: 0x002649,
|
||||
Foreground: 0xf2f4f6,
|
||||
Cursor: 0xf2f4f6,
|
||||
CursorInvert: 0xffffff,
|
||||
},
|
||||
Cursor: &CursorConfig{
|
||||
FlashRate: 0,
|
||||
ResetDelay: 0,
|
||||
Draw: true,
|
||||
Flash: false,
|
||||
BlockWidth: "block",
|
||||
},
|
||||
|
||||
// TODO syntax defaults
|
||||
associations: map[string]*LanguageSyntaxConfig{},
|
||||
|
@ -3,6 +3,7 @@ package editor
|
||||
import (
|
||||
"github.com/felixangell/phi/internal/buff"
|
||||
"github.com/felixangell/phi/internal/cfg"
|
||||
"github.com/felixangell/phi/internal/gui"
|
||||
"github.com/felixangell/strife"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -11,7 +12,6 @@ import (
|
||||
|
||||
type PhiEditor struct {
|
||||
running bool
|
||||
defaultFont *strife.Font
|
||||
mainView *buff.BufferView
|
||||
}
|
||||
|
||||
@ -25,7 +25,9 @@ func (n *PhiEditor) Resize(w, h int) {
|
||||
|
||||
func (n *PhiEditor) HandleEvent(_ strife.StrifeEvent) {}
|
||||
|
||||
func (n *PhiEditor) ApplyConfig(conf *cfg.TomlConfig) {
|
||||
func (n *PhiEditor) ApplyConfig(conf *cfg.PhiEditorConfig) {
|
||||
gui.LoadDefaultFont(conf)
|
||||
|
||||
mainView := buff.NewView(int(1280.0*cfg.ScaleFactor), int(720.0*cfg.ScaleFactor), conf)
|
||||
|
||||
args := os.Args
|
||||
@ -47,7 +49,6 @@ func (n *PhiEditor) ApplyConfig(conf *cfg.TomlConfig) {
|
||||
}
|
||||
|
||||
n.mainView = mainView
|
||||
n.defaultFont = conf.Editor.LoadedFont
|
||||
}
|
||||
|
||||
func (n *PhiEditor) Update() bool {
|
||||
@ -55,6 +56,6 @@ func (n *PhiEditor) Update() bool {
|
||||
}
|
||||
|
||||
func (n *PhiEditor) Render(ctx *strife.Renderer) {
|
||||
ctx.SetFont(n.defaultFont)
|
||||
ctx.SetFont(gui.GetDefaultFont())
|
||||
n.mainView.OnRender(ctx)
|
||||
}
|
||||
|
@ -1,9 +1,29 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/felixangell/phi/internal/cfg"
|
||||
"github.com/felixangell/strife"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var loadedFont *strife.Font
|
||||
|
||||
func LoadDefaultFont(config *cfg.PhiEditorConfig) {
|
||||
fontPath := filepath.Join(config.Editor.FontPath, config.Editor.FontFace+".ttf")
|
||||
var err error
|
||||
loadedFont, err = strife.LoadFont(fontPath, int(14.0*cfg.ScaleFactor))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func GetDefaultFont() *strife.Font {
|
||||
if loadedFont == nil {
|
||||
panic("No font loaded")
|
||||
}
|
||||
return loadedFont
|
||||
}
|
||||
|
||||
type Component interface {
|
||||
SetPosition(x, y int)
|
||||
Translate(x, y int)
|
||||
|
Loading…
Reference in New Issue
Block a user