Skip to content

Commit

Permalink
Merge pull request #18 from IdlePhysicist/new-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
IdlePhysicist authored Jun 20, 2020
2 parents 2b347d9 + 35d7c5b commit 231cb20
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 445 deletions.
14 changes: 7 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -48,21 +48,21 @@ func main() {


// Read config file
cfg := func (_yamlFile string) *model.Config {
cfg := func(_file string) *model.Config {
var _cfg model.Config

if _yamlFile == `` {
_yamlFile = fmt.Sprintf("%s/.config/cave-logger/config.yml", os.Getenv("HOME"))
if _file == `` {
_file = fmt.Sprintf("%s/.config/cave-logger/config.json", os.Getenv("HOME"))
}

yamlFile, err := ioutil.ReadFile(_yamlFile)
file, err := ioutil.ReadFile(_file)
if err != nil {
log.Fatalf("main.readfile: %v", err)
}

err = yaml.Unmarshal(yamlFile, &_cfg)
err = json.Unmarshal(file, &_cfg)
if err != nil {
log.Fatalf("main.unmarshalYAML: %v", err)
log.Fatalf("main.unmarshal: %v", err)
}

return &_cfg
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ require (
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.2
)
8 changes: 4 additions & 4 deletions internal/gui/cavers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newCavers(g *Gui) *cavers {
}

func (c *cavers) name() string {
return `people`
return `cavers`
}

func (c *cavers) setKeybinding(g *Gui) {
Expand All @@ -39,8 +39,8 @@ func (c *cavers) setKeybinding(g *Gui) {
switch event.Key() {
case tcell.KeyEnter:
g.inspectPerson()
case tcell.KeyTAB:
g.switchPanel(`menu`)
case tcell.KeyCtrlR:
c.setEntries(g)
}

switch event.Rune() {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *cavers) entries(g *Gui) {
return
}

g.state.resources.people = cavers
g.state.resources.people = cavers
}

func (c *cavers) focus(g *Gui) {
Expand Down
6 changes: 3 additions & 3 deletions internal/gui/caves.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newCaves(g *Gui) *caves {
}

func (c *caves) name() string {
return `locations`
return `caves`
}

func (c *caves) setKeybinding(g *Gui) {
Expand All @@ -39,8 +39,8 @@ func (c *caves) setKeybinding(g *Gui) {
switch event.Key() {
case tcell.KeyEnter:
g.inspectCave()
case tcell.KeyTAB:
g.switchPanel(`menu`)
case tcell.KeyCtrlR:
c.setEntries(g)
}

switch event.Rune() {
Expand Down
55 changes: 20 additions & 35 deletions internal/gui/cud.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ func (g *Gui) createTripForm() {
g.closeAndSwitchPanel("form", "trips")
})

g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)//.ShowPage("main")
//REVIEW: main or trips ? ^^
g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)
}

func (g *Gui) createTrip(form *tview.Form) {
Expand All @@ -64,9 +63,7 @@ func (g *Gui) createTrip(form *tview.Form) {
}

g.closeAndSwitchPanel(`form`, `trips`)
g.app.QueueUpdateDraw(func() {
g.tripsPanel().setEntries(g)
})
g.tripsPanel().updateEntries(g)
}

func (g *Gui) createLocationForm() {
Expand Down Expand Up @@ -116,11 +113,10 @@ func (g *Gui) createLocationForm() {
g.createLocation(form)
}).
AddButton("Cancel", func() {
g.closeAndSwitchPanel("form", "locations")
g.closeAndSwitchPanel("form", "caves")
})

g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)//.ShowPage("main")
//REVIEW: main or trips ? ^^
g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)
}

func (g *Gui) createLocation(form *tview.Form) {
Expand All @@ -135,10 +131,8 @@ func (g *Gui) createLocation(form *tview.Form) {
return
}

g.closeAndSwitchPanel(`form`, `locations`)
g.app.QueueUpdateDraw(func() {
g.locationsPanel().setEntries(g)
})
g.closeAndSwitchPanel(`form`, `caves`)
g.cavesPanel().updateEntries(g)
}

func (g *Gui) createPersonForm() {
Expand All @@ -162,7 +156,7 @@ func (g *Gui) createPersonForm() {
}

return
})
})

form.
AddInputField("Name", "", inputWidth, nil, nil).
Expand All @@ -171,11 +165,10 @@ func (g *Gui) createPersonForm() {
g.createPerson(form)
}).
AddButton("Cancel", func() {
g.closeAndSwitchPanel("form", "people")
g.closeAndSwitchPanel("form", "cavers")
})

g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)
//REVIEW: main or trips ? ^^
}

func (g *Gui) createPerson(form *tview.Form) {
Expand All @@ -188,10 +181,8 @@ func (g *Gui) createPerson(form *tview.Form) {
return
}

g.closeAndSwitchPanel(`form`, `people`)
g.app.QueueUpdateDraw(func() {
g.peoplePanel().setEntries(g)
})
g.closeAndSwitchPanel(`form`, `cavers`)
g.caversPanel().updateEntries(g)
}

//
Expand Down Expand Up @@ -257,9 +248,7 @@ func (g *Gui) modifyTrip(id string, form *tview.Form) {
}

g.closeAndSwitchPanel(`form`, `trips`)
g.app.QueueUpdateDraw(func() {
g.tripsPanel().setEntries(g)
})
g.tripsPanel().updateEntries(g)
}


Expand Down Expand Up @@ -289,7 +278,7 @@ func (g *Gui) modifyPersonForm() {
}

return
})
})

form.
AddInputField("Name", selectedPerson.Name, inputWidth, nil, nil).
Expand All @@ -298,7 +287,7 @@ func (g *Gui) modifyPersonForm() {
g.modifyPerson(selectedPerson.ID, form)
}).
AddButton("Cancel", func() {
g.closeAndSwitchPanel("form", "people")
g.closeAndSwitchPanel("form", "cavers")
})

g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)
Expand All @@ -315,10 +304,8 @@ func (g *Gui) modifyPerson(id string, form *tview.Form) {
return
}

g.closeAndSwitchPanel(`form`, `people`)
g.app.QueueUpdateDraw(func() {
g.peoplePanel().updateEntries(g)//setEntries(g)
})
g.closeAndSwitchPanel(`form`, `cavers`)
g.caversPanel().updateEntries(g)
}


Expand Down Expand Up @@ -376,7 +363,7 @@ func (g *Gui) modifyLocationForm() {
g.modifyLocation(selectedLocation.ID, form)
}).
AddButton("Cancel", func() {
g.closeAndSwitchPanel("form", "locations")
g.closeAndSwitchPanel("form", "caves")
})

g.pages.AddAndSwitchToPage("form", g.modal(form, 80, 29), true)
Expand All @@ -395,10 +382,8 @@ func (g *Gui) modifyLocation(id string, form *tview.Form) {
return
}

g.closeAndSwitchPanel(`form`, `locations`)
g.app.QueueUpdateDraw(func() {
g.locationsPanel().setEntries(g)
})
g.closeAndSwitchPanel(`form`, `caves`)
g.cavesPanel().updateEntries(g)
}


Expand Down Expand Up @@ -434,7 +419,7 @@ func (g *Gui) deleteLocation() {
g.warning(err.Error(), `form`, []string{`OK`}, func() {return})
return
}
g.locationsPanel().updateEntries(g)
g.cavesPanel().updateEntries(g)
})
}

Expand All @@ -451,6 +436,6 @@ func (g *Gui) deletePerson() {
g.warning(err.Error(), `form`, []string{`OK`}, func() {return})
return
}
g.peoplePanel().updateEntries(g)
g.caversPanel().updateEntries(g)
})
}
Loading

0 comments on commit 231cb20

Please sign in to comment.