~laumann/acme-git

5e7e77c571b3d7575dd32dfb83e5bcbf0ff9c768 — Thomas Bracht Laumann Jespersen 2 years ago
initial commit
3 files changed, 98 insertions(+), 0 deletions(-)

A Git.go
A go.mod
A go.sum
A  => Git.go +91 -0
@@ 1,91 @@
package main

import (
	"fmt"
	"os"
	"os/exec"
	"log"
	"strings"
	"9fans.net/go/acme"
)

var win *acme.Win

func status() {
	cmd := exec.Command("git", "status")
	r, w, err := os.Pipe()
	if err != nil {
		log.Fatal(err)
	}
	cmd.Stdout = w
	cmd.Stderr = w

	err = cmd.Start()
	w.Close()
	if err != nil {
		r.Close()
		win.Fprintf("data", "(exec: %s)\n", err)
	}

	buf := make([]byte, 4096)
	for {
		n, err := r.Read(buf)
		if err != nil {
			break
		}
		if n > 0 {
			win.Write("data", buf)
		}
	}
}

func main() {
	var err error

	win, err = acme.New()
	if err != nil {
		log.Fatal(err)
	}
	pwd, _ := os.Getwd()
	pwdslash := strings.TrimSuffix(pwd, "/") + "/"
	win.Name(pwdslash + "+git")
	win.Ctl("clean")

	win.Fprintf("tag", "Status Diff Log Commit")
	win.Fprintf("body", "PLACEHOLDER")

	go events()
	r, err := acme.Log()
	if err != nil {
		log.Fatal(err)
	}
	for {
		ev, err := r.Read()
		if err != nil {
			log.Fatal(err)
		}
		if ev.Op == "put" {
			fmt.Println("Saved!")
		}
	}
}

func events() {
	for e := range win.EventChan() {
		switch e.C2 {
		case 'x', 'X': // execute
			text := string(e.Text)
			switch text {
			case "Kill", "Quit", "Del":
				win.Ctl("delete")
			case "Status":
				status()
			default:
				fmt.Println(text)
			}
		}
		win.WriteEvent(e)
	}
	os.Exit(0)
}
	
\ No newline at end of file

A  => go.mod +5 -0
@@ 1,5 @@
module git.sr.ht/~laumann.xyz/acme-git

go 1.13

require 9fans.net/go v0.0.4 // indirect

A  => go.sum +2 -0
@@ 1,2 @@
9fans.net/go v0.0.4 h1:g7K+b5I1PlSBFLnjuco3LAx5boK39UUl0Gsrmw6Gl2U=
9fans.net/go v0.0.4/go.mod h1:lfPdxjq9v8pVQXUMBCx5EO5oLXWQFlKRQgs1kEkjoIM=