From 4305c71f6ac8af782364bdc2a3475a7057f43c7d Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 19 Apr 2016 13:58:02 -0400 Subject: [PATCH] Use a buffer for help screen Fixes #24 --- cmd/micro/help.go | 2 +- cmd/micro/micro.go | 30 +++++++++++++++++++++++------- cmd/micro/statusline.go | 5 ++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cmd/micro/help.go b/cmd/micro/help.go index 5af3cc98..2a25fafb 100644 --- a/cmd/micro/help.go +++ b/cmd/micro/help.go @@ -5,7 +5,7 @@ import ( "strings" ) -const helpTxt = `Press Ctrl-q to quit help +const helpTxt = `Press Ctrl-g to close help Micro keybindings: diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 69c7352a..56831112 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -38,6 +38,9 @@ var ( // Version is the version number. // This should be set by the linker Version = "Unknown" + + // Is the help screen open + helpOpen = false ) // LoadInput loads the file input for the editor @@ -130,6 +133,8 @@ func main() { // Load the syntax files, including the colorscheme LoadSyntaxFiles() + buf := NewBuffer(string(input), filename) + // Should we enable true color? truecolor := os.Getenv("MICRO_TRUECOLOR") == "1" @@ -182,7 +187,7 @@ func main() { screen.EnableMouse() messenger = new(Messenger) - view := NewView(NewBuffer(string(input), filename)) + view := NewView(buf) for { // Display everything @@ -205,9 +210,14 @@ func main() { switch e.Key() { case tcell.KeyCtrlQ: // Make sure not to quit if there are unsaved changes - if view.CanClose("Quit anyway? (yes, no, save) ") { - screen.Fini() - os.Exit(0) + if helpOpen { + view.buf = buf + helpOpen = false + } else { + if view.CanClose("Quit anyway? (yes, no, save) ") { + screen.Fini() + os.Exit(0) + } } case tcell.KeyCtrlE: input, canceled := messenger.Prompt("> ") @@ -220,9 +230,15 @@ func main() { HandleShellCommand(input, view) } case tcell.KeyCtrlG: - DisplayHelp() - // Make sure to resize the view if the user resized the terminal while looking at the help text - view.Resize(screen.Size()) + if !helpOpen { + helpBuffer := NewBuffer(helpTxt, "") + helpBuffer.name = "Help" + helpOpen = true + view.buf = helpBuffer + } else { + view.buf = buf + helpOpen = false + } } } diff --git a/cmd/micro/statusline.go b/cmd/micro/statusline.go index df554e04..37bd222c 100644 --- a/cmd/micro/statusline.go +++ b/cmd/micro/statusline.go @@ -40,7 +40,10 @@ func (sline *Statusline) Display() { // Add the filetype file += " " + sline.view.buf.filetype - centerText := "Press Ctrl-g for help" + centerText := "Press Ctrl-g to open help" + if helpOpen { + centerText = "Press Ctrl-g to close help" + } statusLineStyle := defStyle.Reverse(true) if style, ok := colorscheme["statusline"]; ok {