mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
Add infobar
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
"github.com/zyedidia/micro/cmd/micro/config"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
// The InfoBar displays messages and other info at the bottom of the screen.
|
||||
// It is respresented as a buffer and a message with a style.
|
||||
type InfoBar struct {
|
||||
*buffer.Buffer
|
||||
|
||||
hasPrompt bool
|
||||
hasMessage bool
|
||||
|
||||
message string
|
||||
// style to use when drawing the message
|
||||
style tcell.Style
|
||||
|
||||
width int
|
||||
y int
|
||||
|
||||
// This map stores the history for all the different kinds of uses Prompt has
|
||||
// It's a map of history type -> history array
|
||||
history map[string][]string
|
||||
historyNum int
|
||||
|
||||
// Is the current message a message from the gutter
|
||||
gutterMessage bool
|
||||
}
|
||||
|
||||
func NewInfoBar() *InfoBar {
|
||||
ib := new(InfoBar)
|
||||
ib.style = config.DefStyle
|
||||
ib.history = make(map[string][]string)
|
||||
|
||||
ib.Buffer = buffer.NewBufferFromString("", "infobar")
|
||||
ib.Type = buffer.BTScratch
|
||||
|
||||
ib.width, ib.y = screen.Screen.Size()
|
||||
|
||||
return ib
|
||||
}
|
||||
|
||||
func (i *InfoBar) Clear() {
|
||||
for x := 0; x < i.width; x++ {
|
||||
screen.Screen.SetContent(x, i.y, ' ', nil, config.DefStyle)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InfoBar) Display() {
|
||||
x := 0
|
||||
if i.hasPrompt || config.GlobalSettings["infobar"].(bool) {
|
||||
display := i.message + strings.TrimSpace(string(i.Bytes()))
|
||||
for _, c := range display {
|
||||
screen.Screen.SetContent(x, i.y, c, nil, i.style)
|
||||
x += runewidth.RuneWidth(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Message sends a message to the user
|
||||
func (i *InfoBar) Message(msg ...interface{}) {
|
||||
displayMessage := fmt.Sprint(msg...)
|
||||
// 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 {
|
||||
// if there is no active prompt then style and display the message as normal
|
||||
i.message = displayMessage
|
||||
i.style = config.DefStyle
|
||||
|
||||
if _, ok := config.Colorscheme["message"]; ok {
|
||||
i.style = config.Colorscheme["message"]
|
||||
}
|
||||
|
||||
i.hasMessage = true
|
||||
}
|
||||
}
|
||||
74
cmd/micro/display/infowindow.go
Normal file
74
cmd/micro/display/infowindow.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/zyedidia/micro/cmd/micro/config"
|
||||
"github.com/zyedidia/micro/cmd/micro/info"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
type InfoWindow struct {
|
||||
*info.Bar
|
||||
*View
|
||||
|
||||
defStyle tcell.Style
|
||||
errStyle tcell.Style
|
||||
|
||||
width int
|
||||
y int
|
||||
}
|
||||
|
||||
func NewInfoWindow(b *info.Bar) *InfoWindow {
|
||||
iw := new(InfoWindow)
|
||||
iw.Bar = b
|
||||
iw.View = new(View)
|
||||
|
||||
iw.defStyle = config.DefStyle
|
||||
|
||||
if _, ok := config.Colorscheme["message"]; ok {
|
||||
iw.defStyle = config.Colorscheme["message"]
|
||||
}
|
||||
|
||||
iw.errStyle = config.DefStyle.
|
||||
Foreground(tcell.ColorBlack).
|
||||
Background(tcell.ColorMaroon)
|
||||
|
||||
if _, ok := config.Colorscheme["error-message"]; ok {
|
||||
iw.errStyle = config.Colorscheme["error-message"]
|
||||
}
|
||||
|
||||
iw.width, iw.y = screen.Screen.Size()
|
||||
iw.y--
|
||||
|
||||
return iw
|
||||
}
|
||||
|
||||
func (i *InfoWindow) Relocate() bool { return false }
|
||||
func (i *InfoWindow) GetView() *View { return i.View }
|
||||
func (i *InfoWindow) SetView(v *View) {}
|
||||
|
||||
func (i *InfoWindow) Clear() {
|
||||
for x := 0; x < i.width; x++ {
|
||||
screen.Screen.SetContent(x, i.y, ' ', nil, config.DefStyle)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InfoWindow) Display() {
|
||||
x := 0
|
||||
if i.HasPrompt || config.GlobalSettings["infobar"].(bool) {
|
||||
style := i.defStyle
|
||||
|
||||
if i.HasError {
|
||||
style = i.errStyle
|
||||
}
|
||||
|
||||
display := i.Msg + strings.TrimSpace(string(i.Bytes()))
|
||||
for _, c := range display {
|
||||
screen.Screen.SetContent(x, i.y, c, nil, style)
|
||||
x += runewidth.RuneWidth(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,26 +13,24 @@ import (
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
type View struct {
|
||||
X, Y int // X,Y location of the view
|
||||
Width, Height int // Width and height of the view
|
||||
StartLine, StartCol int // Start line and start column of the view (vertical/horizontal scroll)
|
||||
}
|
||||
|
||||
type Window interface {
|
||||
Display()
|
||||
Clear()
|
||||
Relocate() bool
|
||||
GetView() *View
|
||||
SetView(v *View)
|
||||
}
|
||||
|
||||
// The BufWindow provides a way of displaying a certain section
|
||||
// of a buffer
|
||||
type BufWindow struct {
|
||||
// X and Y coordinates for the top left of the window
|
||||
X int
|
||||
Y int
|
||||
|
||||
// Width and Height for the window
|
||||
Width int
|
||||
Height int
|
||||
|
||||
// Which line in the buffer to start displaying at (vertical scroll)
|
||||
StartLine int
|
||||
// Which visual column in the to start displaying at (horizontal scroll)
|
||||
StartCol int
|
||||
*View
|
||||
|
||||
// Buffer being shown in this window
|
||||
Buf *buffer.Buffer
|
||||
@@ -45,6 +43,7 @@ type BufWindow struct {
|
||||
// NewBufWindow creates a new window at a location in the screen with a width and height
|
||||
func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
|
||||
w := new(BufWindow)
|
||||
w.View = new(View)
|
||||
w.X, w.Y, w.Width, w.Height, w.Buf = x, y, width, height, buf
|
||||
w.lineHeight = make([]int, height)
|
||||
|
||||
@@ -53,6 +52,14 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
|
||||
return w
|
||||
}
|
||||
|
||||
func (v *View) GetView() *View {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *View) SetView(view *View) {
|
||||
v = view
|
||||
}
|
||||
|
||||
// Clear resets all cells in this window to the default style
|
||||
func (w *BufWindow) Clear() {
|
||||
for y := 0; y < w.Height; y++ {
|
||||
|
||||
Reference in New Issue
Block a user