Refactoring and color improvements
This commit is contained in:
75
app/cli.go
75
app/cli.go
@@ -40,44 +40,28 @@ func main() {
|
||||
}()
|
||||
|
||||
if len(os.Args) > 1 && os.Args[1] == "migrate" {
|
||||
migrate()
|
||||
migrate(db)
|
||||
} else {
|
||||
projectRepo = repo.NewProjectRepository(db)
|
||||
taskRepo = repo.NewTaskRepository(db)
|
||||
|
||||
layout = tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(makeTitleBar(), 2, 1, false).
|
||||
AddItem(prepareContentPages(), 0, 2, true).
|
||||
AddItem(prepareStatusBar(app), 1, 1, false)
|
||||
|
||||
setKeyboardShortcuts()
|
||||
|
||||
if err := app.SetRoot(layout, true).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
projectRepo = repo.NewProjectRepository(db)
|
||||
taskRepo = repo.NewTaskRepository(db)
|
||||
|
||||
titleText := tview.NewTextView().SetText("[lime::b]Geek-life [::-]- Task Manager for geeks!").SetDynamicColors(true)
|
||||
cloudStatus := tview.NewTextView().SetText("[::d]Version: 0.1.0").SetTextAlign(tview.AlignRight).SetDynamicColors(true)
|
||||
|
||||
titleBar := tview.NewFlex().
|
||||
AddItem(titleText, 0, 2, false).
|
||||
AddItem(cloudStatus, 0, 1, false)
|
||||
|
||||
statusBar = makeStatusBar(app)
|
||||
projectPane = NewProjectPane(projectRepo)
|
||||
taskPane = NewTaskPane(projectRepo, taskRepo)
|
||||
projectDetailPane = NewProjectDetailPane()
|
||||
taskDetailPane = NewTaskDetailPane(taskRepo)
|
||||
|
||||
contents = tview.NewFlex().
|
||||
AddItem(projectPane, 25, 1, true).
|
||||
AddItem(taskPane, 0, 2, false)
|
||||
|
||||
layout = tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(titleBar, 2, 1, false).
|
||||
AddItem(contents, 0, 2, true).
|
||||
AddItem(statusBar, 1, 1, false)
|
||||
|
||||
setKeyboardShortcuts()
|
||||
|
||||
if err := app.SetRoot(layout, true).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func migrate() {
|
||||
util.FatalIfError(db.ReIndex(&model.Project{}), "Error in migrating Projects")
|
||||
util.FatalIfError(db.ReIndex(&model.Task{}), "Error in migrating Tasks")
|
||||
func migrate(database *storm.DB) {
|
||||
util.FatalIfError(database.ReIndex(&model.Project{}), "Error in migrating Projects")
|
||||
util.FatalIfError(database.ReIndex(&model.Task{}), "Error in migrating Tasks")
|
||||
|
||||
fmt.Println("Migration completed. Start geek-life normally.")
|
||||
os.Exit(0)
|
||||
@@ -112,3 +96,26 @@ func setKeyboardShortcuts() *tview.Application {
|
||||
return event
|
||||
})
|
||||
}
|
||||
|
||||
func prepareContentPages() *tview.Flex {
|
||||
projectPane = NewProjectPane(projectRepo)
|
||||
taskPane = NewTaskPane(projectRepo, taskRepo)
|
||||
projectDetailPane = NewProjectDetailPane()
|
||||
taskDetailPane = NewTaskDetailPane(taskRepo)
|
||||
|
||||
contents = tview.NewFlex().
|
||||
AddItem(projectPane, 25, 1, true).
|
||||
AddItem(taskPane, 0, 2, false)
|
||||
|
||||
return contents
|
||||
|
||||
}
|
||||
|
||||
func makeTitleBar() *tview.Flex {
|
||||
titleText := tview.NewTextView().SetText("[lime::b]Geek-life [::-]- Task Manager for geeks!").SetDynamicColors(true)
|
||||
versionInfo := tview.NewTextView().SetText("[::d]Version: 0.1.1").SetTextAlign(tview.AlignRight).SetDynamicColors(true)
|
||||
|
||||
return tview.NewFlex().
|
||||
AddItem(titleText, 0, 2, false).
|
||||
AddItem(versionInfo, 0, 1, false)
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ const (
|
||||
messagePage = "message"
|
||||
)
|
||||
|
||||
func makeStatusBar(app *tview.Application) *StatusBar {
|
||||
statusBar := StatusBar{
|
||||
func prepareStatusBar(app *tview.Application) *StatusBar {
|
||||
statusBar = &StatusBar{
|
||||
Pages: tview.NewPages(),
|
||||
message: tview.NewTextView().SetDynamicColors(true).SetText("Loading..."),
|
||||
container: app,
|
||||
@@ -39,7 +39,7 @@ func makeStatusBar(app *tview.Application) *StatusBar {
|
||||
true,
|
||||
)
|
||||
|
||||
return &statusBar
|
||||
return statusBar
|
||||
}
|
||||
|
||||
func (bar *StatusBar) showForSeconds(message string, timeout int) {
|
||||
|
||||
@@ -37,6 +37,7 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
|
||||
hint: tview.NewTextView().SetTextColor(tcell.ColorYellow).SetTextAlign(tview.AlignCenter),
|
||||
}
|
||||
|
||||
pane.list.SetSelectedBackgroundColor(tcell.ColorDarkBlue)
|
||||
pane.list.SetDoneFunc(func() {
|
||||
app.SetFocus(projectPane)
|
||||
})
|
||||
|
||||
19
app/util.go
19
app/util.go
@@ -34,9 +34,9 @@ func makeHorizontalLine(lineChar rune, color tcell.Color) *tview.TextView {
|
||||
func makeLightTextInput(placeholder string) *tview.InputField {
|
||||
return tview.NewInputField().
|
||||
SetPlaceholder(placeholder).
|
||||
SetPlaceholderTextColor(tcell.ColorYellow).
|
||||
SetPlaceholderTextColor(tcell.ColorDarkSlateBlue).
|
||||
SetFieldTextColor(tcell.ColorBlack).
|
||||
SetFieldBackgroundColor(tcell.ColorGray)
|
||||
SetFieldBackgroundColor(tcell.ColorLightBlue)
|
||||
}
|
||||
|
||||
// If input text is a valid date, parse it. Or get current date
|
||||
@@ -78,11 +78,18 @@ func removeThirdCol() {
|
||||
}
|
||||
|
||||
func getTaskTitleColor(task model.Task) string {
|
||||
colorName := "olive"
|
||||
colorName := "smokewhite"
|
||||
|
||||
if task.Completed {
|
||||
colorName = "lime"
|
||||
} else if task.DueDate != 0 && task.DueDate < time.Now().Truncate(24*time.Hour).Unix() {
|
||||
colorName = "red"
|
||||
colorName = "green"
|
||||
} else if task.DueDate != 0 {
|
||||
dayDiff := int(time.Unix(task.DueDate, 0).Sub(time.Now()).Hours() / 24)
|
||||
|
||||
if dayDiff == 0 {
|
||||
colorName = "orange"
|
||||
} else if dayDiff < 0 {
|
||||
colorName = "red"
|
||||
}
|
||||
}
|
||||
|
||||
return colorName
|
||||
|
||||
Reference in New Issue
Block a user