2015-05-18 14:47:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
2015-09-17 16:49:57 +00:00
|
|
|
|
|
|
|
"github.com/boltdb/bolt"
|
|
|
|
"github.com/nsf/termbox-go"
|
2015-05-18 14:47:08 +00:00
|
|
|
)
|
|
|
|
|
2015-09-17 16:49:57 +00:00
|
|
|
/*
|
|
|
|
ProgramName is the name of the program
|
|
|
|
*/
|
|
|
|
const ProgramName = "boltbrowser"
|
2015-05-18 14:47:08 +00:00
|
|
|
|
2015-09-17 16:49:57 +00:00
|
|
|
var databaseFile string
|
2015-05-18 14:47:08 +00:00
|
|
|
var db *bolt.DB
|
|
|
|
var memBolt *BoltDB
|
|
|
|
|
|
|
|
func mainLoop(memBolt *BoltDB, style Style) {
|
|
|
|
screens := defaultScreensForData(memBolt)
|
2015-09-17 16:49:57 +00:00
|
|
|
displayScreen := screens[BrowserScreenIndex]
|
|
|
|
layoutAndDrawScreen(displayScreen, style)
|
2015-05-18 14:47:08 +00:00
|
|
|
for {
|
|
|
|
event := termbox.PollEvent()
|
|
|
|
if event.Type == termbox.EventKey {
|
2015-09-17 16:49:57 +00:00
|
|
|
newScreenIndex := displayScreen.handleKeyEvent(event)
|
|
|
|
if newScreenIndex < len(screens) {
|
|
|
|
displayScreen = screens[newScreenIndex]
|
|
|
|
layoutAndDrawScreen(displayScreen, style)
|
2015-05-18 14:47:08 +00:00
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if event.Type == termbox.EventResize {
|
2015-09-17 16:49:57 +00:00
|
|
|
layoutAndDrawScreen(displayScreen, style)
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if len(os.Args) != 2 {
|
2015-09-17 16:49:57 +00:00
|
|
|
fmt.Printf("Usage: %s <filename>\n", ProgramName)
|
2015-05-18 14:47:08 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2015-09-17 16:49:57 +00:00
|
|
|
databaseFile := os.Args[1]
|
|
|
|
db, err = bolt.Open(databaseFile, 0600, nil)
|
2015-05-18 14:47:08 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error reading file: %q\n", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// First things first, load the database into memory
|
|
|
|
memBolt.refreshDatabase()
|
|
|
|
|
|
|
|
err = termbox.Init()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer termbox.Close()
|
|
|
|
|
|
|
|
style := defaultStyle()
|
|
|
|
termbox.SetOutputMode(termbox.Output256)
|
|
|
|
|
|
|
|
mainLoop(memBolt, style)
|
|
|
|
defer db.Close()
|
2016-05-05 19:50:04 +00:00
|
|
|
}
|