var argv = require('minimist')(process.argv.slice(2))
var dat = require('dat-core')
var prompt = require('prompt')

var visualdiff = require('./')

if (argv._.length < 2) return usage()

var db = dat(argv.db)
var branch1 = argv._[0]
var branch1 = argv._[1]

var differ = new visualdiff(db, branch1, branch2, function (table1, table2, output, next) {
  repl(table1, table2, output, next)
})

// TODO: add atom-shell app view option

function repl (table1, tabel2, output, next) {
  var self = this
  console.log(output)

  function doprompt ()
    prompt('Keep this chunk? [y,n,s,e,q,?]', function (val) {
      if (val === 's' || val === 'skip') {
        next()
      }
      if (val === 'y' || val === 'yes') {
        differ.merge() // TODO: choose newer version
        next()
      }
      if (val === 'n' || val === 'no') {
        differ.decline() // TODO: choose older version
        next()
      }
      if (val === 'r' || val === 'rows') {
        // remake differ
      }
      if (val === 'c' || val === 'cols') {
        // remake differ
      }
      if (val === '?' || val === 'help') {
        help()
      }
      if (val === 'q' || val === 'quit') {
        return process.exit()
      }
      else help()
    })
  }
}

function help () {
  console.log('skip (s), yes (y), no (n), cols (c), rows (r), quit (q)')
}

function usage () {
  console.log("dat-VisualDiff <head1> <head2> --db <dat-db> [--limit <num>]")
}
@@ -140,17 +140,16 @@
 e('./')%0A
-%0A
 if (argv
@@ -183,30 +183,8 @@
 ()%0A%0A
-var db = dat(argv.db)%0A
 var 
@@ -236,53 +236,98 @@
 var 
-differ = new visualdiff(db, branch1, branch2,
+opts = %7B%0A  db: dat(argv.db),%0A  limit: argv.limit %7C%7C 20,%0A  strategy: 'page'%0A%7D%0A%0Avar onDiff =
  fun
@@ -406,16 +406,73 @@
 xt)%0A%7D)%0A%0A
+var differ = visualdiff(branch1, branch2, opts, onDiff)%0A%0A
 // TODO:
@@ -1058,77 +1058,234 @@
     
-%7D%0A      if (val === 'c' %7C%7C val === 'cols') %7B%0A        // remake differ
+  opts.strategy = 'rows'%0A        differ = visualdiff(branch1, branch2, opts, onDiff)%0A      %7D%0A      if (val === 'c' %7C%7C val === 'cols') %7B%0A        opts.strategy = 'cols'%0A        differ = visualdiff(branch1, branch2, opts, onDiff)
 %0A   

add strategy changes