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