Skip to content

Commit

Permalink
Use a buffer for help screen
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
zyedidia committed Apr 19, 2016
1 parent 2355f2f commit 4305c71
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/micro/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
)

const helpTxt = `Press Ctrl-q to quit help
const helpTxt = `Press Ctrl-g to close help
Micro keybindings:
Expand Down
30 changes: 23 additions & 7 deletions cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -182,7 +187,7 @@ func main() {
screen.EnableMouse()

messenger = new(Messenger)
view := NewView(NewBuffer(string(input), filename))
view := NewView(buf)

for {
// Display everything
Expand All @@ -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("> ")
Expand All @@ -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
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/micro/statusline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4305c71

Please sign in to comment.