~abyxcos/hatemail

308841ae4d5258a99b932ae2fc85db98748dd683 — abyxcos a month ago f7d0971
Let go fmt clean up that massive nested case.
1 files changed, 50 insertions(+), 50 deletions(-)

M hatemail.go
M hatemail.go => hatemail.go +50 -50
@@ 2,20 2,20 @@ package main

import (
	"log"
	"strings"
	"strconv"
	"strings"

	"github.com/gdamore/tcell"
	"github.com/rivo/tview"
)

var (
	app 		*tview.Application
	pages		*tview.Pages
	folderList 	*tview.List
	messageList 	*tview.List
	emailHeader	*tview.Box
	emailBody	*tview.TextView
	app         *tview.Application
	pages       *tview.Pages
	folderList  *tview.List
	messageList *tview.List
	emailHeader *tview.Box
	emailBody   *tview.TextView
)

func eventHandler(ev *tcell.EventKey) *tcell.EventKey {


@@ 26,48 26,48 @@ func eventHandler(ev *tcell.EventKey) *tcell.EventKey {
		return nil
	}

	frontPage,_ := pages.GetFrontPage()
	frontPage, _ := pages.GetFrontPage()
	switch frontPage {
		case "index":
			switch {
			case ev.Rune() == 'q':
				app.Stop()
			case ev.Rune() == '?':
				pages.ShowPage("help")
	
			// List navigation
			case ev.Rune() == 'g':
				app.GetFocus().(*tview.List).SetCurrentItem(0)
			case ev.Rune() == 'G':
				app.GetFocus().(*tview.List).SetCurrentItem(-1)
			case ev.Rune() == 'j':
				app.GetFocus().(*tview.List).SetCurrentItem(app.GetFocus().(*tview.List).GetCurrentItem() + 1)
			case ev.Rune() == 'k':
				app.GetFocus().(*tview.List).SetCurrentItem(app.GetFocus().(*tview.List).GetCurrentItem() - 1)
		
			case ev.Rune() == 'h':
				app.SetFocus(folderList)
			case ev.Rune() == 'l':
				app.SetFocus(messageList)
		
			case ev.Rune() == 'o':
				emailHeader.SetTitle(strconv.Itoa(messageList.GetCurrentItem()) + "/" + strconv.Itoa(messageList.GetItemCount()))
				body,_ := messageList.GetItemText(0)
				emailBody.SetText(body)
				pages.ShowPage("email")
			}
		case "email":
			switch {
			case ev.Key() == tcell.KeyEsc:
				pages.HidePage("email")
			case ev.Rune() == '?':
				pages.ShowPage("help")
			}
		case "help":
			switch {
			case ev.Key() == tcell.KeyEsc:
				pages.HidePage("help")
			}
	case "index":
		switch {
		case ev.Rune() == 'q':
			app.Stop()
		case ev.Rune() == '?':
			pages.ShowPage("help")

		// List navigation
		case ev.Rune() == 'g':
			app.GetFocus().(*tview.List).SetCurrentItem(0)
		case ev.Rune() == 'G':
			app.GetFocus().(*tview.List).SetCurrentItem(-1)
		case ev.Rune() == 'j':
			app.GetFocus().(*tview.List).SetCurrentItem(app.GetFocus().(*tview.List).GetCurrentItem() + 1)
		case ev.Rune() == 'k':
			app.GetFocus().(*tview.List).SetCurrentItem(app.GetFocus().(*tview.List).GetCurrentItem() - 1)

		case ev.Rune() == 'h':
			app.SetFocus(folderList)
		case ev.Rune() == 'l':
			app.SetFocus(messageList)

		case ev.Rune() == 'o':
			emailHeader.SetTitle(strconv.Itoa(messageList.GetCurrentItem()) + "/" + strconv.Itoa(messageList.GetItemCount()))
			body, _ := messageList.GetItemText(0)
			emailBody.SetText(body)
			pages.ShowPage("email")
		}
	case "email":
		switch {
		case ev.Key() == tcell.KeyEsc:
			pages.HidePage("email")
		case ev.Rune() == '?':
			pages.ShowPage("help")
		}
	case "help":
		switch {
		case ev.Key() == tcell.KeyEsc:
			pages.HidePage("help")
		}
	}

	return nil


@@ 93,7 93,7 @@ func main() {
		SetHighlightFullLine(true).
		SetWrapAround(false)
	grid.AddItem(folderList, 0, 0, 1, 1, 0, 0, false)
	for _,folder := range folders {
	for _, folder := range folders {
		folderList.AddItem(folder, "", 0, nil)
	}



@@ 103,7 103,7 @@ func main() {
		SetWrapAround(false)
	grid.AddItem(messageList, 0, 1, 1, 1, 0, 0, true)
	for i := 0; i < 50; i++ {
		messageList.AddItem(strconv.Itoa(i) + " " + ipsum, "", 0, nil)
		messageList.AddItem(strconv.Itoa(i)+" "+ipsum, "", 0, nil)
	}

	// Email view