Merge pull request #1 from mattn/windows

Windows Support
master
Sina Siadat 9 years ago
commit f76c1381d7

@ -5,6 +5,7 @@ import (
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"github.com/andrew-d/go-termutil" "github.com/andrew-d/go-termutil"
"github.com/mattn/go-colorable"
"github.com/mgutz/ansi" "github.com/mgutz/ansi"
"io/ioutil" "io/ioutil"
"log" "log"
@ -16,6 +17,8 @@ import (
"time" "time"
) )
var out = colorable.NewColorableStdout()
// Attr holds the data fetched from a row // Attr holds the data fetched from a row
// Only 1 ValueXxx field should have value, the others should be nil // Only 1 ValueXxx field should have value, the others should be nil
type Attr struct { type Attr struct {
@ -223,12 +226,12 @@ func (attr Attr) Print(w *tabwriter.Writer, verbose bool, indent int, highlighte
//fmt.Printf(strings.Repeat(" ", indent)) //fmt.Printf(strings.Repeat(" ", indent))
if attr.GetMark() == 0 { if attr.GetMark() == 0 {
fmt.Printf("[%s] %s\n", Color(attr.GetIdentifier(), "yellow+b"), attr.Title()) fmt.Fprintf(out, "[%s] %s\n", Color(attr.GetIdentifier(), "yellow+b"), attr.Title())
} else { } else {
fmt.Printf("[%s] %s\n", Color(attr.GetIdentifier(), "black+b:white"), Color(attr.Title(), "default")) fmt.Fprintf(out, "[%s] %s\n", Color(attr.GetIdentifier(), "black+b:white"), Color(attr.Title(), "default"))
} }
if len(highlighteds) > 0 { if len(highlighteds) > 0 {
fmt.Println(attr.PrettyMatches(highlighteds, after)) fmt.Fprintln(out, attr.PrettyMatches(highlighteds, after))
} }
} }
} }
@ -318,7 +321,7 @@ func (attr Attr) SetAlias(db *sql.DB, alias string) {
if !unset { if !unset {
var validAlias = regexp.MustCompile(`[^\s\d]+`) var validAlias = regexp.MustCompile(`[^\s\d]+`)
if !validAlias.MatchString(alias) { if !validAlias.MatchString(alias) {
fmt.Println("Alias must contain a non-numeric character") fmt.Fprintln(out, "Alias must contain a non-numeric character")
return return
} }
} }
@ -335,9 +338,9 @@ func (attr Attr) SetAlias(db *sql.DB, alias string) {
//check(err) //check(err)
if err == nil { if err == nil {
if unset { if unset {
fmt.Printf("ID:%d unaliased\n", attr.GetID()) fmt.Fprintf(out, "ID:%d unaliased\n", attr.GetID())
} else { } else {
fmt.Printf("alias set: %s => %s\n", attr.GetIdentifier(), alias) fmt.Fprintf(out, "alias set: %s => %s\n", attr.GetIdentifier(), alias)
} }
} else { } else {
log.Fatalf("error while setting alias \"%s\" for ID:%d -- alias must be unique\n", alias, attr.GetID()) // , err) log.Fatalf("error while setting alias \"%s\" for ID:%d -- alias must be unique\n", alias, attr.GetID()) // , err)
@ -726,7 +729,7 @@ func InitializeDatabase(db *sql.DB) bool {
log.Fatal(err) log.Fatal(err)
return false return false
} }
fmt.Println("repository initiated") fmt.Fprintln(out, "repository initiated")
return true return true
} }

@ -157,8 +157,11 @@ func cmdNew(db *sql.DB, opts Options) bool {
} else { } else {
f, err := ioutil.TempFile("", "eton-edit") f, err := ioutil.TempFile("", "eton-edit")
check(err) check(err)
f.Close()
openEditor(f.Name()) if openEditor(f.Name()) == false {
return false
}
value_text = readFile(f.Name()) value_text = readFile(f.Name())
} }
@ -368,7 +371,7 @@ func cmdUnmark(db *sql.DB, opts Options) bool {
/******************************************************************************/ /******************************************************************************/
func openEditor(filepath string) { func openEditor(filepath string) bool {
var cmd *exec.Cmd var cmd *exec.Cmd
editor := os.Getenv("EDITOR") editor := os.Getenv("EDITOR")
@ -385,7 +388,12 @@ func openEditor(filepath string) {
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Run() err := cmd.Run()
if err != nil {
log.Println(err)
return false
}
return true
} }
func readFile(filepath string) string { func readFile(filepath string) string {

Loading…
Cancel
Save