mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
possibility to show a log view
This commit is contained in:
@@ -711,7 +711,7 @@ func (v *View) Save(usePlugin bool) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Help {
|
if v.Type == vtHelp {
|
||||||
// We can't save the help text
|
// We can't save the help text
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -1258,7 +1258,7 @@ func (v *View) ToggleHelp(usePlugin bool) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !v.Help {
|
if v.Type != vtHelp {
|
||||||
// Open the default help
|
// Open the default help
|
||||||
v.openHelp("help")
|
v.openHelp("help")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,19 +26,20 @@ type StrCommand struct {
|
|||||||
var commands map[string]Command
|
var commands map[string]Command
|
||||||
|
|
||||||
var commandActions = map[string]func([]string){
|
var commandActions = map[string]func([]string){
|
||||||
"Set": Set,
|
"Set": Set,
|
||||||
"SetLocal": SetLocal,
|
"SetLocal": SetLocal,
|
||||||
"Show": Show,
|
"Show": Show,
|
||||||
"Run": Run,
|
"Run": Run,
|
||||||
"Bind": Bind,
|
"Bind": Bind,
|
||||||
"Quit": Quit,
|
"Quit": Quit,
|
||||||
"Save": Save,
|
"Save": Save,
|
||||||
"Replace": Replace,
|
"Replace": Replace,
|
||||||
"VSplit": VSplit,
|
"VSplit": VSplit,
|
||||||
"HSplit": HSplit,
|
"HSplit": HSplit,
|
||||||
"Tab": NewTab,
|
"Tab": NewTab,
|
||||||
"Help": Help,
|
"Help": Help,
|
||||||
"Eval": Eval,
|
"Eval": Eval,
|
||||||
|
"ToggleLog": ToggleLog,
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitCommands initializes the default commands
|
// InitCommands initializes the default commands
|
||||||
@@ -84,6 +85,17 @@ func DefaultCommands() map[string]StrCommand {
|
|||||||
"tab": {"Tab", []Completion{FileCompletion, NoCompletion}},
|
"tab": {"Tab", []Completion{FileCompletion, NoCompletion}},
|
||||||
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
|
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
|
||||||
"eval": {"Eval", []Completion{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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// Messenger is an object that makes it easy to send messages to the user
|
||||||
// and get input from the user
|
// and get input from the user
|
||||||
type Messenger struct {
|
type Messenger struct {
|
||||||
|
log *Buffer
|
||||||
// Are we currently prompting the user?
|
// Are we currently prompting the user?
|
||||||
hasPrompt bool
|
hasPrompt bool
|
||||||
// Is there a message to print
|
// Is there a message to print
|
||||||
@@ -67,6 +68,19 @@ type Messenger struct {
|
|||||||
gutterMessage bool
|
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
|
// Message sends a message to the user
|
||||||
func (m *Messenger) Message(msg ...interface{}) {
|
func (m *Messenger) Message(msg ...interface{}) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@@ -77,6 +91,7 @@ func (m *Messenger) Message(msg ...interface{}) {
|
|||||||
if _, ok := colorscheme["message"]; ok {
|
if _, ok := colorscheme["message"]; ok {
|
||||||
m.style = colorscheme["message"]
|
m.style = colorscheme["message"]
|
||||||
}
|
}
|
||||||
|
m.addLog(m.message)
|
||||||
m.hasMessage = true
|
m.hasMessage = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +107,7 @@ func (m *Messenger) Error(msg ...interface{}) {
|
|||||||
if _, ok := colorscheme["error-message"]; ok {
|
if _, ok := colorscheme["error-message"]; ok {
|
||||||
m.style = colorscheme["error-message"]
|
m.style = colorscheme["error-message"]
|
||||||
}
|
}
|
||||||
|
m.addLog(m.message)
|
||||||
m.hasMessage = true
|
m.hasMessage = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,13 +129,16 @@ func (m *Messenger) YesNoPrompt(prompt string) (bool, bool) {
|
|||||||
switch e.Key() {
|
switch e.Key() {
|
||||||
case tcell.KeyRune:
|
case tcell.KeyRune:
|
||||||
if e.Rune() == 'y' {
|
if e.Rune() == 'y' {
|
||||||
|
m.addLog("\t--> y")
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
return true, false
|
return true, false
|
||||||
} else if e.Rune() == 'n' {
|
} else if e.Rune() == 'n' {
|
||||||
|
m.addLog("\t--> n")
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
|
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
|
||||||
|
m.addLog("\t--> (cancel)")
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
return false, true
|
return false, true
|
||||||
}
|
}
|
||||||
@@ -146,6 +165,7 @@ func (m *Messenger) LetterPrompt(prompt string, responses ...rune) (rune, bool)
|
|||||||
case tcell.KeyRune:
|
case tcell.KeyRune:
|
||||||
for _, r := range responses {
|
for _, r := range responses {
|
||||||
if e.Rune() == r {
|
if e.Rune() == r {
|
||||||
|
m.addLog("\t--> " + string(r))
|
||||||
m.Clear()
|
m.Clear()
|
||||||
m.Reset()
|
m.Reset()
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
@@ -153,6 +173,7 @@ func (m *Messenger) LetterPrompt(prompt string, responses ...rune) (rune, bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
|
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
|
||||||
|
m.addLog("\t--> (cancel)")
|
||||||
m.Clear()
|
m.Clear()
|
||||||
m.Reset()
|
m.Reset()
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
@@ -198,9 +219,11 @@ func (m *Messenger) Prompt(prompt, historyType string, completionTypes ...Comple
|
|||||||
switch e.Key() {
|
switch e.Key() {
|
||||||
case tcell.KeyCtrlQ, tcell.KeyCtrlC, tcell.KeyEscape:
|
case tcell.KeyCtrlQ, tcell.KeyCtrlC, tcell.KeyEscape:
|
||||||
// Cancel
|
// Cancel
|
||||||
|
m.addLog("\t--> (cancel)")
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
case tcell.KeyEnter:
|
case tcell.KeyEnter:
|
||||||
// User is done entering their response
|
// User is done entering their response
|
||||||
|
m.addLog("\t--> " + m.response)
|
||||||
m.hasPrompt = false
|
m.hasPrompt = false
|
||||||
response, canceled = m.response, false
|
response, canceled = m.response, false
|
||||||
m.history[historyType][len(m.history[historyType])-1] = response
|
m.history[historyType][len(m.history[historyType])-1] = response
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (sline *Statusline) Display() {
|
|||||||
file += " " + sline.view.Buf.FileType()
|
file += " " + sline.view.Buf.FileType()
|
||||||
|
|
||||||
rightText := helpBinding + " for help "
|
rightText := helpBinding + " for help "
|
||||||
if sline.view.Help {
|
if sline.view.Type == vtHelp {
|
||||||
rightText = helpBinding + " to close help "
|
rightText = helpBinding + " to close help "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ import (
|
|||||||
"github.com/zyedidia/tcell"
|
"github.com/zyedidia/tcell"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ViewType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
vtDefault ViewType = iota
|
||||||
|
vtHelp
|
||||||
|
vtLog
|
||||||
|
)
|
||||||
|
|
||||||
// The View struct stores information about a view into a buffer.
|
// The View struct stores information about a view into a buffer.
|
||||||
// It stores information about the cursor, and the viewport
|
// It stores information about the cursor, and the viewport
|
||||||
// that the user sees the buffer from.
|
// that the user sees the buffer from.
|
||||||
@@ -28,7 +36,7 @@ type View struct {
|
|||||||
heightPercent int
|
heightPercent int
|
||||||
|
|
||||||
// Specifies whether or not this view holds a help buffer
|
// Specifies whether or not this view holds a help buffer
|
||||||
Help bool
|
Type ViewType
|
||||||
|
|
||||||
// Actual with and height
|
// Actual with and height
|
||||||
width int
|
width int
|
||||||
@@ -536,11 +544,11 @@ func (v *View) openHelp(helpPage string) {
|
|||||||
helpBuffer := NewBuffer(data, helpPage+".md")
|
helpBuffer := NewBuffer(data, helpPage+".md")
|
||||||
helpBuffer.Name = "Help"
|
helpBuffer.Name = "Help"
|
||||||
|
|
||||||
if v.Help {
|
if v.Type == vtHelp {
|
||||||
v.OpenBuffer(helpBuffer)
|
v.OpenBuffer(helpBuffer)
|
||||||
} else {
|
} else {
|
||||||
v.HSplit(helpBuffer)
|
v.HSplit(helpBuffer)
|
||||||
CurView().Help = true
|
CurView().Type = vtHelp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user