Skip to content

Commit

Permalink
continue to work on tui
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jun 19, 2020
1 parent b289a8b commit 0e57544
Show file tree
Hide file tree
Showing 164 changed files with 17,103 additions and 91,154 deletions.
37 changes: 20 additions & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions asset/tui/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,11 @@ func (l *CsList) Draw(screen tcell.Screen) {

// Secondary text.
if l.showSecondaryText {
tview.Print(screen, item.SecondaryText, x, y, width, tview.AlignLeft, l.secondaryTextColor)
y++

for _, s := range strings.Split(item.SecondaryText, "\n") {
tview.Print(screen, s, x, y, width, tview.AlignLeft, l.secondaryTextColor)
y++
}
}
}
}
Expand Down
163 changes: 90 additions & 73 deletions asset/tui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,122 @@ import (
"fmt"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"strings"
)

type CodeResult struct {
Title *tview.TextView
Body *tview.TextView
BodyHeight int
}

func main() {
app := tview.NewApplication()

var dropdown *tview.DropDown
var inputField *tview.InputField
var extInputField *tview.InputField

textView = tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
SetScrollable(true).
ScrollToBeginning()

list := NewCsList().
AddItem("csperf/main.go (0.003)", "Some explanatory text", '1', func() {
app.Stop()
fmt.Println("csperf/main.go")
}).
AddItem("corpus/1080-0.txt", `var textView *tview.TextView
var dropdown *tview.DropDown
var inputField *tview.InputField
var extInputField *tview.InputField
textView = tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
SetScrollable(true).
ScrollToBeginning()`, '2', nil).
AddItem("corpus/pg16328.txt", "Some explanatory text", '3', nil).
AddItem("corpus/84-0.txt", "Some explanatory text", '4', nil).
AddItem("corpus/pg2542.txt", "Some explanatory text", '5', nil).
AddItem("corpus/snippet/chinese_war_and_peace.txt", "Some explanatory text", '6', nil).
AddItem("corpus/844.txt.utf-8", "Some explanatory text", '7', nil).
AddItem("corpus/46-0.txt", "Some explanatory text Some explanatory\n text Some explanatory text Some explanatory text\n Some explanatory text Some explanatory text Some explanatory text Some\n explanatory text Some explanatory text ", 'h', nil).
AddItem("corpus/prideandprejudice.txt", "Some explanatory text", '8', nil).
AddItem("corpus/2701-0.txt", "Some explanatory text", '9', nil).
AddItem("Quit", "Press to exit", 'q', func() {
app.Stop()
})
var queryFlex *tview.Flex
var resultsFlex *tview.Flex
var overallFlex *tview.Flex

dropdown = tview.NewDropDown().
SetOptions([]string{"50", "100", "200", "300", "400", "500", "600", "700", "800", "900"}, nil).
SetCurrentOption(3).
SetLabelColor(tcell.ColorWhite).
SetFieldBackgroundColor(tcell.Color16).
SetSelectedFunc(func(text string, index int) {
app.SetFocus(inputField)
}).
SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyTab:
app.SetFocus(inputField)
}
})

extInputField = tview.NewInputField().
SetFieldBackgroundColor(tcell.Color16).
SetLabel("> ").
SetLabelColor(tcell.ColorWhite).
SetFieldWidth(10).
SetChangedFunc(func(text string) {
var codeResults []CodeResult

}).
SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyTab:
app.SetFocus(dropdown)
}
for i:=1;i<100;i++ {
var textViewTitle *tview.TextView
var textViewBody *tview.TextView

textViewTitle = tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
ScrollToBeginning()
textViewTitle.SetText(fmt.Sprintf(`[purple]main%d.go (0.0%d)[white]`, i, i))

textViewBody = tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
ScrollToBeginning()

textViewBody.SetText(`import (
"fmt"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
)
type CodeResult struct {
Title *tview.TextView
Body *tview.TextView
}`)

codeResults = append(codeResults, CodeResult{
Title: textViewTitle,
Body: textViewBody,
BodyHeight: len(strings.Split(textViewBody.GetText(false), "\n")),
})
}

selected := 0

inputField = tview.NewInputField().
SetFieldBackgroundColor(tcell.Color16).
SetLabel("> ").
SetLabelColor(tcell.ColorWhite).
SetFieldWidth(0).
SetChangedFunc(func(text string) {

}).
SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyTab:
app.SetFocus(extInputField)
//app.SetFocus(textView) need to change focus to the others but not the text itself
case tcell.KeyUp:
if selected != 0 {
selected--
}

resultsFlex.Clear()
for i, t := range codeResults {
if i >= selected {
resultsFlex.AddItem(nil, 1, 0, false)
resultsFlex.AddItem(t.Title, 1, 0, false)
resultsFlex.AddItem(nil, 1, 0, false)
resultsFlex.AddItem(t.Body, t.BodyHeight, 1, false)
}
}
case tcell.KeyDown:
if selected != len(codeResults) -1 {
selected++
}

resultsFlex.Clear()
for i, t := range codeResults {
if i >= selected {
resultsFlex.AddItem(nil, 1, 0, false)
resultsFlex.AddItem(t.Title, 1, 0, false)
resultsFlex.AddItem(nil, 1, 0, false)
resultsFlex.AddItem(t.Body, t.BodyHeight, 1, false)
}
}
}
})

queryFlex := tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(inputField, 0, 8, false).
AddItem(extInputField, 10, 0, false).
AddItem(dropdown, 4, 1, false)

flex := tview.NewFlex().SetDirection(tview.FlexRow).
queryFlex = tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(inputField, 0, 8, false)

resultsFlex = tview.NewFlex().SetDirection(tview.FlexRow)

overallFlex = tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(queryFlex, 1, 0, false).
//AddItem(textView, 0, 3, false)
AddItem(list, 0, 3, false)
AddItem(resultsFlex, 0, 1, false)


if err := app.SetRoot(flex, true).SetFocus(list).Run(); err != nil {
for i, t := range codeResults {
if i >= selected {
resultsFlex.AddItem(nil, 1, 0, false)
resultsFlex.AddItem(t.Title, 1, 0, false)
resultsFlex.AddItem(nil, 1, 0, false)
resultsFlex.AddItem(t.Body, t.BodyHeight, 1, false)
}
}

if err := app.SetRoot(overallFlex, true).SetFocus(inputField).Run(); err != nil {
panic(err)
}
}
Loading

0 comments on commit 0e57544

Please sign in to comment.