Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ability to edit entries #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func keybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("entries", gocui.KeyCtrlR, gocui.ModNone, deleteItem); err != nil {
return err
}
if err := g.SetKeybinding("entries", gocui.KeyArrowRight, gocui.ModNone, startEditingEntry); err != nil {
return err
}
if err := g.SetKeybinding("output", gocui.KeyCtrlS, gocui.ModNone, save); err != nil {
return err
}
Expand Down
33 changes: 33 additions & 0 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,39 @@ func newEntry(g *gocui.Gui, v *gocui.View) error {
return err
}

// Enable edit mode for an existing entry
// After editing the details of the entry its end time will be updated
func startEditingEntry(g *gocui.Gui, v *gocui.View) error {
var err error
v.Highlight = false
ov, err := g.SetCurrentView("output")
if err != nil {
return err
}
if err = outputEntryDetails(g, ov); err != nil {
return err
}
ov.Editable = true
g.Cursor = true
ov.SetCursor(0, 0)
return err
}

// v will always equal output view
// This outputs only the details of the entry for the purpose of further editing it
func outputEntryDetails(g *gocui.Gui, v *gocui.View) error {
var err error

v.Clear()
details := models.CurrentEntry.Details

if _, err := fmt.Fprintln(v, details); err != nil {
log.Println("Error writing entry to the output view:", err)
}

return err
}

// v will always equal output view
// This saves the text in the output view and does what it needs to do
// with it depending on what view it was called from (before switching to the output view).
Expand Down