diff --git a/README.md b/README.md index e19717c..a3bea4d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ editing the config file for the editor itself. # goals The editor must: -* run at 60 fps; +* run fast; * load and edit large files with ease; * look pretty; and finally * be easy to use @@ -38,30 +38,42 @@ $ ./phi-editor If you're on macOS, you can get these dependencies via. homebrew. If you're on windows; you have my condolences. ## configuration -Configuration files are stored in `$HOME/.phi-editor-editor/config.toml`, here's -an example, which just so happens to be the defualt configuration: +Configuration files are stored in `$HOME/.phi-editor-editor/config.toml`. Note that +this directory is created on first startup by the editor, as well as the configuration +file below is pre-loaded: ```toml [editor] -tab_size = 2 +tab_size = 4 hungry_backspace = true tabs_are_spaces = true match_braces = false +maintain_indentation = true +highlight_line = true [render] aliased = true +accelerated = true +throttle_cpu_usage = true [theme] -background = "0xfdf6e3" -foreground = "0x7a7a7a" -cursor = "0x657B83" -cursor_invert = "0xffffff" +background = 0x002649 +foreground = 0xf2f4f6 +cursor = 0xf2f4f6 +cursor_invert = 0x000000 [cursor] flash_rate = 400 reset_delay = 400 draw = true flash = true + +[commands] +[commands.save] +shortcut = "super+s" + +[commands.delete_line] +shortcut = "super+d" ``` # license diff --git a/cfg/config.go b/cfg/config.go index 35f87d7..9ca4f83 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -12,7 +12,7 @@ type TomlConfig struct { } var DEFUALT_TOML_CONFIG string = `[editor] -tab_size = 2 +tab_size = 4 hungry_backspace = true tabs_are_spaces = true match_braces = false @@ -22,12 +22,13 @@ highlight_line = true [render] aliased = true accelerated = true +throttle_cpu_usage = true [theme] background = 0x002649 foreground = 0xf2f4f6 cursor = 0xf2f4f6 -cursor_invert = 0xffffff +cursor_invert = 0x000000 [cursor] flash_rate = 400 @@ -71,8 +72,9 @@ func (c CursorConfig) GetCaretWidth() int { } type RenderConfig struct { - Aliased bool - Accelerated bool + Aliased bool + Accelerated bool + Throttle_Cpu_Usage bool } // todo make this more extendable... diff --git a/gui/buffer.go b/gui/buffer.go index ea3bbbf..1a29174 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -101,7 +101,7 @@ var shiftAlternative = map[rune]rune{ '[': '{', ']': '}', ';': ':', - '"': '\'', + '\'': '"', '\\': '|', '§': '±', } diff --git a/main.go b/main.go index 4119c50..2f54cfc 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "runtime" + "time" "github.com/felixangell/phi-editor/cfg" "github.com/felixangell/phi-editor/gui" @@ -21,7 +22,8 @@ type PhiEditor struct { } func (n *PhiEditor) init(cfg *cfg.TomlConfig) { - n.AddComponent(gui.NewView(1280, 720, cfg)) + n.AddComponent(gui.NewView(1280/2, 720, cfg)) + n.AddComponent(gui.NewView(1280/2, 720, cfg)) font, err := strife.LoadFont("./res/firacode.ttf", 14) if err != nil { @@ -48,14 +50,11 @@ func (n *PhiEditor) update() bool { } func (n *PhiEditor) render(ctx *strife.Renderer) { - ctx.Clear() ctx.SetFont(n.defaultFont) for _, child := range n.GetComponents() { gui.Render(child, ctx) } - - ctx.Display() } func main() { @@ -100,11 +99,15 @@ func main() { editor.init(&config) timer := strife.CurrentTimeMillis() - num_frames := 0 + frames, updates := 0, 0 + fps, ups := frames, updates ctx := window.GetRenderContext() + ctx.Clear() editor.render(ctx) + ctx.Display() + for { window.PollEvents() if window.CloseRequested() { @@ -112,17 +115,29 @@ func main() { } if editor.update() { + ctx.Clear() editor.render(ctx) - } - num_frames += 1 + // this is only printed on each + // render... + ctx.SetColor(strife.White) + ctx.String(fmt.Sprintf("fps: %d, ups %d", fps, ups), ww-256, wh-128) + + ctx.Display() + frames += 1 + } + updates += 1 if strife.CurrentTimeMillis()-timer > 1000 { timer = strife.CurrentTimeMillis() - if PRINT_FPS { - fmt.Println("frames: ", num_frames) - } - num_frames = 0 + fps, ups = frames, updates + frames, updates = 0, 0 + } + + if config.Render.Throttle_Cpu_Usage { + // todo put in the config how long + // we sleep for! + time.Sleep(16) } } diff --git a/screenshot.png b/screenshot.png index 7da301d..d997ff0 100644 Binary files a/screenshot.png and b/screenshot.png differ