Merge pull request #35 from mattn/some-fix

Some fix for Windows
This commit is contained in:
Felix Angell 2018-04-17 02:35:44 +01:00 committed by GitHub
commit abcb12f1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -2,7 +2,7 @@
<h1>phi-editor</h1> <h1>phi-editor</h1>
Phi is a minimal text editor designed to look pretty, run fast, and be easy Phi is a minimal text editor designed to look pretty, run fast, and be easy
to configure and use. It's primary function is for editing code. to configure and use. It's primary function is for editing code.
Note that this is a work in progress and is very buggy! The editor is written as if it's a game, Note that this is a work in progress and is very buggy! The editor is written as if it's a game,
so it will probably **eat up your battery**, as well as **run possibly quite slow** - especially so it will probably **eat up your battery**, as well as **run possibly quite slow** - especially
@ -22,7 +22,7 @@ The editor must:
* run fast; * run fast;
* load and edit large files with ease; * load and edit large files with ease;
* look pretty; and finally * look pretty; and finally
* be easy to use * be easy to use
# building # building
You'll need Go with the GOPATH, GOBIN, etc. setup, as well as SDL2, SDL2\_image, and SDL2\_ttf. Here's You'll need Go with the GOPATH, GOBIN, etc. setup, as well as SDL2, SDL2\_image, and SDL2\_ttf. Here's
@ -49,7 +49,7 @@ $ ./phi-editor
If you're on windows, you have my condolences. If you're on windows, you have my condolences.
## configuration ## configuration
Configuration files are stored in `$HOME/.phi-editor-editor/config.toml`. Note that Configuration files are stored in `$HOME/.phi-editor/config.toml`. Note that
this directory is created on first startup by the editor, as well as the configuration this directory is created on first startup by the editor, as well as the configuration
files in the 'cfg/' directory are pre-loaded dependening on platform: see 'cfg/linuxconfig.go', for example. files in the 'cfg/' directory are pre-loaded dependening on platform: see 'cfg/linuxconfig.go', for example.

View File

@ -4,6 +4,8 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"path/filepath"
"runtime"
"strings" "strings"
// fork of BurntSushi with hexadecimal support. // fork of BurntSushi with hexadecimal support.
@ -81,8 +83,12 @@ func configureAndValidate(conf *TomlConfig) {
func Setup() TomlConfig { func Setup() TomlConfig {
log.Println("Setting up Phi Editor") log.Println("Setting up Phi Editor")
CONFIG_DIR := os.Getenv("HOME") + CONFIG_DIR_PATH home := os.Getenv("HOME")
CONFIG_PATH := CONFIG_DIR + CONFIG_TOML_FILE if runtime.GOOS == "windows" {
home = os.Getenv("USERPROFILE")
}
CONFIG_DIR := filepath.Join(home, CONFIG_DIR_PATH)
CONFIG_PATH := filepath.Join(CONFIG_DIR, CONFIG_TOML_FILE)
CONFIG_FULL_PATH = CONFIG_PATH CONFIG_FULL_PATH = CONFIG_PATH
// if the user doesn't have a /.phi-editor // if the user doesn't have a /.phi-editor

View File

@ -799,6 +799,9 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
start := b.cam.y start := b.cam.y
upper := b.cam.y + visibleLines upper := b.cam.y + visibleLines
if start > len(b.contents) {
start = len(b.contents)
}
if upper > len(b.contents) { if upper > len(b.contents) {
upper = len(b.contents) upper = len(b.contents)
} }

View File

@ -5,7 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"path" "path/filepath"
"runtime" "runtime"
"time" "time"
@ -42,7 +42,7 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
} }
} else { } else {
// we have no args, open up a scratch file // we have no args, open up a scratch file
tempFile, err := ioutil.TempFile("/var/tmp/", "phi-editor-") tempFile, err := ioutil.TempFile("", "phi-editor-")
if err != nil { if err != nil {
log.Println("Failed to create temp file", err.Error()) log.Println("Failed to create temp file", err.Error())
os.Exit(1) os.Exit(1)
@ -65,14 +65,14 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
fontFolder = path.Join(os.Getenv("%WINDIR%"), "fonts") fontFolder = filepath.Join(os.Getenv("WINDIR"), "fonts")
case "darwin": case "darwin":
fontFolder = "/Library/Fonts/" fontFolder = "/Library/Fonts/"
case "linux": case "linux":
fontFolder = "/usr/share/fonts/" fontFolder = "/usr/share/fonts/"
} }
fontPath := path.Join(fontFolder, cfg.Editor.Font_Face) + ".ttf" fontPath := filepath.Join(fontFolder, cfg.Editor.Font_Face) + ".ttf"
font, err := strife.LoadFont(fontPath, cfg.Editor.Font_Size) font, err := strife.LoadFont(fontPath, cfg.Editor.Font_Size)
if err != nil { if err != nil {