Create the help scene

This commit is contained in:
Sameer Rahmani 2022-11-25 18:02:02 +00:00
parent 3f94d0fee8
commit 2b1164e0fa
1 changed files with 28 additions and 6 deletions

View File

@ -42,6 +42,18 @@ var highlight,
cursorStyle,
normalArrow tcell.Style
var help [][]string = [][]string{
{"?", "View help"},
{"TAB", "Select an entry"},
{"C-p, Up", "Move up"},
{"C-n, Down", "Move down"},
{"C-space", "Start/Stop muliple-selection"},
{"C-e, End", "Jump to the end of input"},
{"C-e, End", "Jump to the end of input"},
{"q", "Back"},
{"ESC", "Exit"},
}
type Scene struct {
RenderFn func(*State, Items)
KeyHandlerFn func(*State, tcell.EventKey, Items)
@ -84,15 +96,22 @@ func Render(s *State, inputs Items) {
}
func RenderHelp(s *State, inputs Items) {
drawText(*s.Screen, 0, 4, xmax-1, 4+1, normalArrow, "hnthnt")
y := 2
for _, key := range help {
drawText(*s.Screen, 4, y, 25, y+1, tcell.StyleDefault.Bold(true), key[0])
drawText(*s.Screen, 25, y, xmax-1, y+1, tcell.StyleDefault.Bold(true), key[1])
y += 1
}
}
func RenderMain(s *State, inputs Items) {
y := 2
status := fmt.Sprintf("[Line: %d][? For help]", s.Current+1)
//status := fmt.Sprintf("[Line: %d][? For help]: %s", s.Current+1, s.UserInput)
status := fmt.Sprintf("L: %d, U: %d, S: %d [Line: %d][? For help]: %s", s.LowerBound, s.UpperBound, s.SelectionStartLine, s.Current+1, s.UserInput)
//status := fmt.Sprintf("L: %d, U: %d, S: %d [Line: %d][? For help]: %s", s.LowerBound, s.UpperBound, s.SelectionStartLine, s.Current+1, s.UserInput)
drawText(*s.Screen, 0, 0, xmax-1, 1, helpStyle, status)
drawText(*s.Screen, len(status), 0, xmax-1, 1, cursorStyle, "⎥")
//drawText(*s.Screen, len(status), 0, xmax-1, 1, cursorStyle, "⎥")
for i, item := range (*inputs)[s.LowerBound:s.UpperBound] {
style := tcell.StyleDefault
@ -197,10 +216,13 @@ func HandleMain(state *State, ev tcell.EventKey, input Items) {
state.InSelectionMode = !state.InSelectionMode
} else if ev.Key() == tcell.KeyCtrlH {
} else if ev.Rune() == '?' {
state.CurrentScene = 1
} else if ev.Key() == tcell.KeyBackspace {
state.UserInput = string(state.UserInput[:len(state.UserInput)-2])
} else if ev.Key() == tcell.KeyBackspace || ev.Key() == tcell.KeyBackspace2 {
if len(state.UserInput) != 0 {
state.UserInput = string(state.UserInput[:len(state.UserInput)-1])
}
} else {
state.UserInput = state.UserInput + string(ev.Rune())
}