possibility to show a log view

This commit is contained in:
boombuler
2016-09-26 19:08:37 +02:00
parent c1d08a6dc0
commit c1a3ee1706
5 changed files with 62 additions and 19 deletions

View File

@@ -711,7 +711,7 @@ func (v *View) Save(usePlugin bool) bool {
return false
}
if v.Help {
if v.Type == vtHelp {
// We can't save the help text
return false
}
@@ -1258,7 +1258,7 @@ func (v *View) ToggleHelp(usePlugin bool) bool {
return false
}
if !v.Help {
if v.Type != vtHelp {
// Open the default help
v.openHelp("help")
} else {

View File

@@ -26,19 +26,20 @@ type StrCommand struct {
var commands map[string]Command
var commandActions = map[string]func([]string){
"Set": Set,
"SetLocal": SetLocal,
"Show": Show,
"Run": Run,
"Bind": Bind,
"Quit": Quit,
"Save": Save,
"Replace": Replace,
"VSplit": VSplit,
"HSplit": HSplit,
"Tab": NewTab,
"Help": Help,
"Eval": Eval,
"Set": Set,
"SetLocal": SetLocal,
"Show": Show,
"Run": Run,
"Bind": Bind,
"Quit": Quit,
"Save": Save,
"Replace": Replace,
"VSplit": VSplit,
"HSplit": HSplit,
"Tab": NewTab,
"Help": Help,
"Eval": Eval,
"ToggleLog": ToggleLog,
}
// InitCommands initializes the default commands
@@ -84,6 +85,17 @@ func DefaultCommands() map[string]StrCommand {
"tab": {"Tab", []Completion{FileCompletion, NoCompletion}},
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
"eval": {"Eval", []Completion{NoCompletion}},
"log": {"ToggleLog", []Completion{NoCompletion}},
}
}
func ToggleLog(args []string) {
buffer := messenger.getBuffer()
if CurView().Type != vtLog {
CurView().VSplit(buffer)
CurView().Type = vtLog
} else {
CurView().Quit(true)
}
}

View File

@@ -43,6 +43,7 @@ func TermError(filename string, lineNum int, err string) {
// Messenger is an object that makes it easy to send messages to the user
// and get input from the user
type Messenger struct {
log *Buffer
// Are we currently prompting the user?
hasPrompt bool
// Is there a message to print
@@ -67,6 +68,19 @@ type Messenger struct {
gutterMessage bool
}
func (m *Messenger) addLog(msg string) {
buffer := m.getBuffer()
buffer.Insert(buffer.End(), msg+"\n")
}
func (m *Messenger) getBuffer() *Buffer {
if m.log == nil {
m.log = NewBuffer([]byte{}, "")
m.log.Name = "Log"
}
return m.log
}
// Message sends a message to the user
func (m *Messenger) Message(msg ...interface{}) {
buf := new(bytes.Buffer)
@@ -77,6 +91,7 @@ func (m *Messenger) Message(msg ...interface{}) {
if _, ok := colorscheme["message"]; ok {
m.style = colorscheme["message"]
}
m.addLog(m.message)
m.hasMessage = true
}
@@ -92,6 +107,7 @@ func (m *Messenger) Error(msg ...interface{}) {
if _, ok := colorscheme["error-message"]; ok {
m.style = colorscheme["error-message"]
}
m.addLog(m.message)
m.hasMessage = true
}
@@ -113,13 +129,16 @@ func (m *Messenger) YesNoPrompt(prompt string) (bool, bool) {
switch e.Key() {
case tcell.KeyRune:
if e.Rune() == 'y' {
m.addLog("\t--> y")
m.hasPrompt = false
return true, false
} else if e.Rune() == 'n' {
m.addLog("\t--> n")
m.hasPrompt = false
return false, false
}
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
m.addLog("\t--> (cancel)")
m.hasPrompt = false
return false, true
}
@@ -146,6 +165,7 @@ func (m *Messenger) LetterPrompt(prompt string, responses ...rune) (rune, bool)
case tcell.KeyRune:
for _, r := range responses {
if e.Rune() == r {
m.addLog("\t--> " + string(r))
m.Clear()
m.Reset()
m.hasPrompt = false
@@ -153,6 +173,7 @@ func (m *Messenger) LetterPrompt(prompt string, responses ...rune) (rune, bool)
}
}
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
m.addLog("\t--> (cancel)")
m.Clear()
m.Reset()
m.hasPrompt = false
@@ -198,9 +219,11 @@ func (m *Messenger) Prompt(prompt, historyType string, completionTypes ...Comple
switch e.Key() {
case tcell.KeyCtrlQ, tcell.KeyCtrlC, tcell.KeyEscape:
// Cancel
m.addLog("\t--> (cancel)")
m.hasPrompt = false
case tcell.KeyEnter:
// User is done entering their response
m.addLog("\t--> " + m.response)
m.hasPrompt = false
response, canceled = m.response, false
m.history[historyType][len(m.history[historyType])-1] = response

View File

@@ -37,7 +37,7 @@ func (sline *Statusline) Display() {
file += " " + sline.view.Buf.FileType()
rightText := helpBinding + " for help "
if sline.view.Help {
if sline.view.Type == vtHelp {
rightText = helpBinding + " to close help "
}

View File

@@ -11,6 +11,14 @@ import (
"github.com/zyedidia/tcell"
)
type ViewType int
const (
vtDefault ViewType = iota
vtHelp
vtLog
)
// The View struct stores information about a view into a buffer.
// It stores information about the cursor, and the viewport
// that the user sees the buffer from.
@@ -28,7 +36,7 @@ type View struct {
heightPercent int
// Specifies whether or not this view holds a help buffer
Help bool
Type ViewType
// Actual with and height
width int
@@ -536,11 +544,11 @@ func (v *View) openHelp(helpPage string) {
helpBuffer := NewBuffer(data, helpPage+".md")
helpBuffer.Name = "Help"
if v.Help {
if v.Type == vtHelp {
v.OpenBuffer(helpBuffer)
} else {
v.HSplit(helpBuffer)
CurView().Help = true
CurView().Type = vtHelp
}
}
}