<commit_before>package main

import (
	"bufio"
	"fmt"
	"github.com/codegangsta/cli"
	kval "github.com/kval-access-language/kval-boltdb"
	"github.com/olekukonko/tablewriter"
	"log"
	"os"
	"strings"
)

var instructionLine = "> Enter bucket to explore (CTRL-Q to quit, CTRL-B to go back, ENTER to reset):\n\n"

func main() {
	var file string

	cli.AppHelpTemplate = `NAME:
  {{.Name}} - {{.Usage}}

VERSION:
  {{.Version}}

USAGE:
  {{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}

GLOBAL OPTIONS:
  {{range .VisibleFlags}}{{.}}
  {{end}}
AUTHOR:
  {{range .Authors}}{{ . }}{{end}}
COPYRIGHT:
  {{.Copyright}}
`
	app := cli.NewApp()
	app.Name = "bolter"
	app.Usage = "view boltdb file interactively in your terminal"
	app.Version = "2.0.0-kval-fork"
	app.Author = "Originally by <NAME>. Interactive mode: Ross Spencer"
	app.Copyright = "(c) 2016 <NAME>"
	//app.Email = ""
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:        "file, f",
			Usage:       "boltdb `FILE` to view",
			Destination: &file,
		},
	}
	app.Action = func(c *cli.Context) error {
		if file == "" {
			cli.ShowAppHelp(c)
			return nil
		}

		var i impl
		i = impl{fmt: &tableFormatter{}}
		if _, err := os.Stat(file); os.IsNotExist(err) {
			log.Fatal(err)
			return err
		}
		i.initDB(file)
		defer kval.Disconnect(i.kb)

		i.readInput()

		return nil
	}
	app.Run(os.Args)
}

func (i *impl) readInput() {
	i.listBuckets()
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		bucket := scanner.Text()
		fmt.Fprintln(os.Stdout, "")
		switch bucket {
		case "\x11":
			return
		case "\x02":
			// TODO: Change KVAL to get first record...
			if !strings.Contains(i.loc, "") || !strings.Contains(i.loc, ">>") {
				fmt.Println("> Going back...")
				i.loc = ""
				i.listBuckets()
			} else {
				i.listBucketItems(bucket, true)
			}
		case "":
			i.listBuckets()
		default:<commit_msg>[bugfix] ctrl-q didn't work on linux. ctrl-x instead.<commit_after>package main

import (
	"bufio"
	"fmt"
	"github.com/codegangsta/cli"
	kval "github.com/kval-access-language/kval-boltdb"
	"github.com/olekukonko/tablewriter"
	"log"
	"os"
	"strings"
)

var instructionLine = "> Enter bucket to explore (CTRL-X to quit, CTRL-B to go back, ENTER to reset):\n\n"

func main() {
	var file string

	cli.AppHelpTemplate = `NAME:
  {{.Name}} - {{.Usage}}

VERSION:
  {{.Version}}

USAGE:
  {{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}

GLOBAL OPTIONS:
  {{range .VisibleFlags}}{{.}}
  {{end}}
AUTHOR:
  {{range .Authors}}{{ . }}{{end}}
COPYRIGHT:
  {{.Copyright}}
`
	app := cli.NewApp()
	app.Name = "bolter"
	app.Usage = "view boltdb file interactively in your terminal"
	app.Version = "2.0.0-kval-fork"
	app.Author = "Originally by <NAME>. Interactive mode: Ross Spencer"
	app.Copyright = "(c) 2016 <NAME>"
	//app.Email = ""
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:        "file, f",
			Usage:       "boltdb `FILE` to view",
			Destination: &file,
		},
	}
	app.Action = func(c *cli.Context) error {
		if file == "" {
			cli.ShowAppHelp(c)
			return nil
		}

		var i impl
		i = impl{fmt: &tableFormatter{}}
		if _, err := os.Stat(file); os.IsNotExist(err) {
			log.Fatal(err)
			return err
		}
		i.initDB(file)
		defer kval.Disconnect(i.kb)

		i.readInput()

		return nil
	}
	app.Run(os.Args)
}

func (i *impl) readInput() {
	i.listBuckets()
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		bucket := scanner.Text()
		fmt.Fprintln(os.Stdout, "")
		switch bucket {
		case "\x18":
			return
		case "\x02":
			// TODO: Change KVAL to get first record...
			if !strings.Contains(i.loc, "") || !strings.Contains(i.loc, ">>") {
				fmt.Println("> Going back...")
				i.loc = ""
				i.listBuckets()
			} else {
				i.listBucketItems(bucket, true)
			}
		case "":
			i.listBuckets()
		default:
{'fraction_non_alphanumeric': 0.18284960422163588, 'fraction_numerical': 0.005804749340369393, 'mean_word_length': 3.138646288209607, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1235970', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1487, 'n_words': 334}