mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-28 01:40:19 +09:00
Reorganize info bar
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/zyedidia/clipboard"
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
"github.com/zyedidia/micro/cmd/micro/info"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/micro/cmd/micro/util"
|
||||
"github.com/zyedidia/tcell"
|
||||
@@ -299,7 +298,7 @@ func (h *BufHandler) InsertSpace() bool {
|
||||
// InsertNewline inserts a newline plus possible some whitespace if autoindent is on
|
||||
func (h *BufHandler) InsertNewline() bool {
|
||||
if h.Buf.Type == buffer.BTInfo {
|
||||
info.MainBar.DonePrompt(false)
|
||||
InfoBar.DonePrompt(false)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -557,7 +556,7 @@ func (h *BufHandler) CutLine() bool {
|
||||
h.lastCutTime = time.Now()
|
||||
h.Cursor.DeleteSelection()
|
||||
h.Cursor.ResetSelection()
|
||||
info.MainBar.Message("Cut line")
|
||||
InfoBar.Message("Cut line")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -568,7 +567,7 @@ func (h *BufHandler) Cut() bool {
|
||||
h.Cursor.DeleteSelection()
|
||||
h.Cursor.ResetSelection()
|
||||
h.freshClip = true
|
||||
info.MainBar.Message("Cut selection")
|
||||
InfoBar.Message("Cut selection")
|
||||
|
||||
return true
|
||||
} else {
|
||||
@@ -586,7 +585,7 @@ func (h *BufHandler) DuplicateLine() bool {
|
||||
// h.Cursor.Right()
|
||||
}
|
||||
|
||||
info.MainBar.Message("Duplicated line")
|
||||
InfoBar.Message("Duplicated line")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -598,7 +597,7 @@ func (h *BufHandler) DeleteLine() bool {
|
||||
}
|
||||
h.Cursor.DeleteSelection()
|
||||
h.Cursor.ResetSelection()
|
||||
info.MainBar.Message("Deleted line")
|
||||
InfoBar.Message("Deleted line")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -643,12 +642,12 @@ func (h *BufHandler) SelectAll() bool {
|
||||
func (h *BufHandler) OpenFile() bool {
|
||||
cb := func(resp string, canceled bool) {
|
||||
if !canceled {
|
||||
info.MainBar.Message("Opening", resp)
|
||||
InfoBar.Message("Opening", resp)
|
||||
} else {
|
||||
info.MainBar.Error("Canceled")
|
||||
InfoBar.Error("Canceled")
|
||||
}
|
||||
}
|
||||
info.MainBar.Prompt("Open file: ", cb)
|
||||
InfoBar.Prompt("Open file: ", cb)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -717,10 +716,10 @@ func (h *BufHandler) HalfPageDown() bool {
|
||||
func (h *BufHandler) ToggleRuler() bool {
|
||||
if !h.Buf.Settings["ruler"].(bool) {
|
||||
h.Buf.Settings["ruler"] = true
|
||||
info.MainBar.Message("Enabled ruler")
|
||||
InfoBar.Message("Enabled ruler")
|
||||
} else {
|
||||
h.Buf.Settings["ruler"] = false
|
||||
info.MainBar.Message("Disabled ruler")
|
||||
InfoBar.Message("Disabled ruler")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package main
|
||||
package action
|
||||
|
||||
import (
|
||||
"github.com/zyedidia/micro/cmd/micro/action"
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
"github.com/zyedidia/micro/cmd/micro/display"
|
||||
"github.com/zyedidia/micro/cmd/micro/info"
|
||||
)
|
||||
|
||||
type EditPane struct {
|
||||
display.Window
|
||||
action.Handler
|
||||
Handler
|
||||
}
|
||||
|
||||
type InfoPane struct {
|
||||
display.Window
|
||||
Handler
|
||||
*info.InfoBuf
|
||||
}
|
||||
|
||||
func NewBufEditPane(x, y, width, height int, b *buffer.Buffer) *EditPane {
|
||||
@@ -16,7 +22,18 @@ func NewBufEditPane(x, y, width, height int, b *buffer.Buffer) *EditPane {
|
||||
// TODO: can probably replace editpane with bufhandler entirely
|
||||
w := display.NewBufWindow(x, y, width, height, b)
|
||||
e.Window = w
|
||||
e.Handler = action.NewBufHandler(b, w)
|
||||
e.Handler = NewBufHandler(b, w)
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func NewInfoBar() *InfoPane {
|
||||
e := new(InfoPane)
|
||||
ib := info.NewBuffer()
|
||||
w := display.NewInfoWindow(ib)
|
||||
e.Window = w
|
||||
e.Handler = NewBufHandler(ib.Buffer, w)
|
||||
e.InfoBuf = ib
|
||||
|
||||
return e
|
||||
}
|
||||
7
cmd/micro/action/globals.go
Normal file
7
cmd/micro/action/globals.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package action
|
||||
|
||||
var InfoBar *InfoPane
|
||||
|
||||
func InitGlobals() {
|
||||
InfoBar = NewInfoBar()
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type InfoWindow struct {
|
||||
*info.Bar
|
||||
*info.InfoBuf
|
||||
*View
|
||||
|
||||
defStyle tcell.Style
|
||||
@@ -23,9 +23,9 @@ type InfoWindow struct {
|
||||
y int
|
||||
}
|
||||
|
||||
func NewInfoWindow(b *info.Bar) *InfoWindow {
|
||||
func NewInfoWindow(b *info.InfoBuf) *InfoWindow {
|
||||
iw := new(InfoWindow)
|
||||
iw.Bar = b
|
||||
iw.InfoBuf = b
|
||||
iw.View = new(View)
|
||||
|
||||
iw.defStyle = config.DefStyle
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
// LoadHistory attempts to load user history from configDir/buffers/history
|
||||
// into the history map
|
||||
// The savehistory option must be on
|
||||
func (i *Bar) LoadHistory() {
|
||||
func (i *InfoBuf) LoadHistory() {
|
||||
if config.GetGlobalOption("savehistory").(bool) {
|
||||
file, err := os.Open(config.ConfigDir + "/buffers/history")
|
||||
defer file.Close()
|
||||
@@ -37,7 +37,7 @@ func (i *Bar) LoadHistory() {
|
||||
|
||||
// SaveHistory saves the user's command history to configDir/buffers/history
|
||||
// only if the savehistory option is on
|
||||
func (i *Bar) SaveHistory() {
|
||||
func (i *InfoBuf) SaveHistory() {
|
||||
if config.GetGlobalOption("savehistory").(bool) {
|
||||
// Don't save history past 100
|
||||
for k, v := range i.History {
|
||||
|
||||
@@ -7,15 +7,9 @@ import (
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
)
|
||||
|
||||
var MainBar *Bar
|
||||
|
||||
func InitInfoBar() {
|
||||
MainBar = NewBar()
|
||||
}
|
||||
|
||||
// The Bar displays messages and other info at the bottom of the screen.
|
||||
// The InfoBuf displays messages and other info at the bottom of the screen.
|
||||
// It is respresented as a buffer and a message with a style.
|
||||
type Bar struct {
|
||||
type InfoBuf struct {
|
||||
*buffer.Buffer
|
||||
|
||||
HasPrompt bool
|
||||
@@ -35,8 +29,8 @@ type Bar struct {
|
||||
PromptCallback func(resp string, canceled bool)
|
||||
}
|
||||
|
||||
func NewBar() *Bar {
|
||||
ib := new(Bar)
|
||||
func NewBuffer() *InfoBuf {
|
||||
ib := new(InfoBuf)
|
||||
ib.History = make(map[string][]string)
|
||||
|
||||
ib.Buffer = buffer.NewBufferFromString("", "infobar", buffer.BTInfo)
|
||||
@@ -45,7 +39,7 @@ func NewBar() *Bar {
|
||||
}
|
||||
|
||||
// Message sends a message to the user
|
||||
func (i *Bar) Message(msg ...interface{}) {
|
||||
func (i *InfoBuf) Message(msg ...interface{}) {
|
||||
// only display a new message if there isn't an active prompt
|
||||
// this is to prevent overwriting an existing prompt to the user
|
||||
if i.HasPrompt == false {
|
||||
@@ -57,7 +51,7 @@ func (i *Bar) Message(msg ...interface{}) {
|
||||
}
|
||||
|
||||
// Error sends an error message to the user
|
||||
func (i *Bar) Error(msg ...interface{}) {
|
||||
func (i *InfoBuf) Error(msg ...interface{}) {
|
||||
// only display a new message if there isn't an active prompt
|
||||
// this is to prevent overwriting an existing prompt to the user
|
||||
if i.HasPrompt == false {
|
||||
@@ -68,7 +62,7 @@ func (i *Bar) Error(msg ...interface{}) {
|
||||
// TODO: add to log?
|
||||
}
|
||||
|
||||
func (i *Bar) Prompt(msg string, callback func(string, bool)) {
|
||||
func (i *InfoBuf) Prompt(msg string, callback func(string, bool)) {
|
||||
// If we get another prompt mid-prompt we cancel the one getting overwritten
|
||||
if i.HasPrompt {
|
||||
i.DonePrompt(true)
|
||||
@@ -80,7 +74,7 @@ func (i *Bar) Prompt(msg string, callback func(string, bool)) {
|
||||
i.PromptCallback = callback
|
||||
}
|
||||
|
||||
func (i *Bar) DonePrompt(canceled bool) {
|
||||
func (i *InfoBuf) DonePrompt(canceled bool) {
|
||||
i.HasPrompt = false
|
||||
if canceled {
|
||||
i.PromptCallback("", true)
|
||||
@@ -91,7 +85,7 @@ func (i *Bar) DonePrompt(canceled bool) {
|
||||
}
|
||||
|
||||
// Reset resets the messenger's cursor, message and response
|
||||
func (i *Bar) Reset() {
|
||||
func (i *InfoBuf) Reset() {
|
||||
i.Msg = ""
|
||||
i.HasPrompt, i.HasMessage, i.HasError = false, false, false
|
||||
}
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"github.com/zyedidia/micro/cmd/micro/action"
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
"github.com/zyedidia/micro/cmd/micro/config"
|
||||
"github.com/zyedidia/micro/cmd/micro/display"
|
||||
"github.com/zyedidia/micro/cmd/micro/info"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/micro/cmd/micro/util"
|
||||
"github.com/zyedidia/tcell"
|
||||
@@ -193,11 +191,9 @@ func main() {
|
||||
|
||||
b := LoadInput()[0]
|
||||
width, height := screen.Screen.Size()
|
||||
ep := NewBufEditPane(0, 0, width, height-1, b)
|
||||
ep := action.NewBufEditPane(0, 0, width, height-1, b)
|
||||
|
||||
info.InitInfoBar()
|
||||
infowindow := display.NewInfoWindow(info.MainBar)
|
||||
infobar := action.NewBufHandler(info.MainBar.Buffer, infowindow)
|
||||
action.InitGlobals()
|
||||
|
||||
// Here is the event loop which runs in a separate thread
|
||||
go func() {
|
||||
@@ -214,7 +210,7 @@ func main() {
|
||||
screen.Screen.Fill(' ', config.DefStyle)
|
||||
screen.Screen.HideCursor()
|
||||
ep.Display()
|
||||
infowindow.Display()
|
||||
action.InfoBar.Display()
|
||||
screen.Screen.Show()
|
||||
|
||||
var event tcell.Event
|
||||
@@ -225,8 +221,8 @@ func main() {
|
||||
}
|
||||
|
||||
if event != nil {
|
||||
if info.MainBar.HasPrompt {
|
||||
infobar.HandleEvent(event)
|
||||
if action.InfoBar.HasPrompt {
|
||||
action.InfoBar.HandleEvent(event)
|
||||
} else {
|
||||
ep.HandleEvent(event)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user