Editing in external editor working - issue with Mouse
This commit is contained in:
@@ -2,6 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@@ -11,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ajaxray/geek-life/model"
|
"github.com/ajaxray/geek-life/model"
|
||||||
"github.com/ajaxray/geek-life/repository"
|
"github.com/ajaxray/geek-life/repository"
|
||||||
|
"github.com/ajaxray/geek-life/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const dateLayoutISO = "2006-01-02"
|
const dateLayoutISO = "2006-01-02"
|
||||||
@@ -175,14 +179,7 @@ func (td *TaskDetailPane) prepareDetailsEditor() {
|
|||||||
td.taskDetailView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
td.taskDetailView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
td.task.Details = td.taskDetailView.Buf.String()
|
td.updateTaskNote(td.taskDetailView.Buf.String())
|
||||||
err := taskRepo.Update(td.task)
|
|
||||||
if err == nil {
|
|
||||||
statusBar.showForSeconds("[lime]Saved task detail", 5)
|
|
||||||
} else {
|
|
||||||
statusBar.showForSeconds("[red]Could not save: "+err.Error(), 5)
|
|
||||||
}
|
|
||||||
|
|
||||||
td.deactivateEditor()
|
td.deactivateEditor()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -191,6 +188,16 @@ func (td *TaskDetailPane) prepareDetailsEditor() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (td *TaskDetailPane) updateTaskNote(note string) {
|
||||||
|
td.task.Details = note
|
||||||
|
err := taskRepo.Update(td.task)
|
||||||
|
if err == nil {
|
||||||
|
statusBar.showForSeconds("[lime]Saved task detail", 5)
|
||||||
|
} else {
|
||||||
|
statusBar.showForSeconds("[red]Could not save: "+err.Error(), 5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func makeBufferFromString(content string) *femto.Buffer {
|
func makeBufferFromString(content string) *femto.Buffer {
|
||||||
buff := femto.NewBufferFromString(content, "")
|
buff := femto.NewBufferFromString(content, "")
|
||||||
// taskDetail.Settings["ruler"] = false
|
// taskDetail.Settings["ruler"] = false
|
||||||
@@ -217,6 +224,64 @@ func (td *TaskDetailPane) deactivateEditor() {
|
|||||||
app.SetFocus(td)
|
app.SetFocus(td)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (td *TaskDetailPane) editInExternalEditor() {
|
||||||
|
|
||||||
|
tmpFileName, err := writeToTmpFile(td.task.Details)
|
||||||
|
if err != nil {
|
||||||
|
statusBar.showForSeconds("[red::]Failed to create tmp file. Try in-app editing by pressing i", 5)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var messageToShow, updatedContent string
|
||||||
|
app.Suspend(func() {
|
||||||
|
cmd := exec.Command(util.GetEnvStr("EDITOR", "vim"), tmpFileName)
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
messageToShow = "[red::]Failed to save content. Try in-app editing by pressing i"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if content, readErr := ioutil.ReadFile(tmpFileName); readErr == nil {
|
||||||
|
updatedContent = string(content)
|
||||||
|
} else {
|
||||||
|
messageToShow = "[red::]Failed to load external editing. Try in-app editing by pressing i"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if messageToShow != "" {
|
||||||
|
statusBar.showForSeconds(messageToShow, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
if updatedContent != "" {
|
||||||
|
td.updateTaskNote(updatedContent)
|
||||||
|
td.SetTask(td.task)
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ForceDraw()
|
||||||
|
// @TODO: Not working - fix it
|
||||||
|
app.EnableMouse(true)
|
||||||
|
_ = os.Remove(tmpFileName)
|
||||||
|
|
||||||
|
// app.SetFocus(td)
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeToTmpFile writes given content to a tmpFile and returns the filename
|
||||||
|
func writeToTmpFile(content string) (string, error) {
|
||||||
|
tmpFile, err := ioutil.TempFile("", "geek_life_task_note_*.md")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
fileName := tmpFile.Name()
|
||||||
|
|
||||||
|
if err = ioutil.WriteFile(fileName, []byte(content), 0777); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName, tmpFile.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
@@ -229,6 +294,8 @@ func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey
|
|||||||
switch event.Rune() {
|
switch event.Rune() {
|
||||||
case 'e':
|
case 'e':
|
||||||
td.activateEditor()
|
td.activateEditor()
|
||||||
|
case 'v':
|
||||||
|
td.editInExternalEditor()
|
||||||
case 'd':
|
case 'd':
|
||||||
app.SetFocus(td.taskDate)
|
app.SetFocus(td.taskDate)
|
||||||
case ' ':
|
case ' ':
|
||||||
|
|||||||
@@ -147,8 +147,10 @@ func (pane *TaskPane) ClearCompletedTasks() {
|
|||||||
|
|
||||||
func (pane TaskPane) setHintMessage() {
|
func (pane TaskPane) setHintMessage() {
|
||||||
if len(projectPane.projects) == 0 {
|
if len(projectPane.projects) == 0 {
|
||||||
pane.hint.SetText("Welcome to the organized life!\n------------------------------\n Create TaskList/Project at the bottom of Projects pane.\n (Press p,n)")
|
pane.hint.SetText("Welcome to the organized life!\n------------------------------\n Create TaskList/Project at the bottom of Projects pane.\n (Press p,n) \n\nHelp - https://bit.ly/cli-task")
|
||||||
} else {
|
} else {
|
||||||
pane.hint.SetText("Select a TaskList/Project to load tasks.\nPress p,n to create new Project.")
|
pane.hint.SetText("Select a TaskList/Project to load tasks.\nPress p,n to create new Project.\n\nHelp - https://bit.ly/cli-task")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add: For help - https://bit.ly/cli-task
|
||||||
}
|
}
|
||||||
|
|||||||
1
build.sh
1
build.sh
@@ -1,3 +1,4 @@
|
|||||||
|
# go build -o geek-life ./app
|
||||||
env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o builds/geek-life_darwin-amd64 ./app
|
env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o builds/geek-life_darwin-amd64 ./app
|
||||||
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o builds/geek-life_linux-amd64 ./app
|
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o builds/geek-life_linux-amd64 ./app
|
||||||
env GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o builds/geek-life_linux-arm64 ./app
|
env GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o builds/geek-life_linux-arm64 ./app
|
||||||
|
|||||||
Reference in New Issue
Block a user