~porcellis/t

1a554c83893ca1d76f1890ac0f2ab01294871ff8 — Pedro Lucas Porcellis a month ago 4359886 master
Display notes using the user's pager
3 files changed, 35 insertions(+), 12 deletions(-)

M README.md
M commands/list.go
M main.go
M README.md => README.md +2 -2
@@ 68,8 68,8 @@ Send me your patches to my email at
There's a lot of things I want to implement on `t`, here is some of them:

- Add a improved visualization when displaying notes
- Support OS Pager when listing notes (this can be achieved by `t list
| less -r`)
- ~~Support OS Pager when listing notes (this can be achieved by `t list
| less -r`)~~
- Delete a note
- Make setup through `t` (`t init` would create the notes repository, set a remote, etc).
- Add PGP support for notes (this is a must)

M commands/list.go => commands/list.go +9 -9
@@ 1,7 1,6 @@
package commands

import (
	"fmt"
	"git.sr.ht/~porcellis/t/config"
	"git.sr.ht/~porcellis/t/models"
	. "github.com/logrusorgru/aurora"


@@ 17,21 16,22 @@ func check(e error) {
	}
}

func List(config config.TConfig) error {
func List(config config.TConfig) (string, error) {
	var (
		err error
		err     error
		content string
	)

	notes, err := BuildList(config)

	if err != nil {
		return err
		return "", err
	}

	fmt.Println(Bold("\n \t Your notes\n\n"))
	content += Sprintf(Bold("\n \t Your notes\n\n"))

	for index, note := range notes {
		fmt.Printf("[#%d] %s (%s)\n", index, Bold(note.Title()), Faint(note.UpdatedAt()).BrightYellow())
		content += Sprintf("[#%d] %s (%s)\n", index, Bold(note.Title()), Faint(note.UpdatedAt()).BrightYellow())

		f, err := os.Open(note.Path)
		check(err)


@@ 39,11 39,11 @@ func List(config config.TConfig) error {
		b1 := make([]byte, 240)
		n1, err := f.Read(b1)
		check(err)
		fmt.Printf("%s\n\n", string(b1[:n1]))
		fmt.Printf("------------------------------------\n\n")
		content += Sprintf("%s\n\n", string(b1[:n1]))
		content += Sprintf("------------------------------------\n\n")
	}

	return err
	return content, err
}

func BuildList(config config.TConfig) ([]models.Note, error) {

M main.go => main.go +24 -1
@@ 7,7 7,9 @@ import (
	"git.sr.ht/~porcellis/t/models"
	"log"
	"os"
	"os/exec"
	"strconv"
	"strings"
)

var Version = "0.1.0"


@@ 68,7 70,28 @@ func main() {
		fmt.Println(fmt.Sprintf("Note created %s", note.Name))

	case "list", "l":
		commands.List(*configuration)
		content, err := commands.List(*configuration)

		if err != nil {
			panic("We could not fetch your notes")
		}

		pager := os.Getenv("PAGER")

		if pager == "" {
			// This options display control chars as raw
			pager = "less -r"
		}

		pagerCommand := strings.Split(pager, " ")

		cmd := exec.Command(pagerCommand[0], pagerCommand[1:]...)
		cmd.Stdin = strings.NewReader(content)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		cmd.Run()

	case "edit", "e":
		var note models.Note
		notes, _ := commands.BuildList(*configuration)