mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-28 22:08:12 +09:00
Infobar prompts
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
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/info"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/micro/cmd/micro/util"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
@@ -56,19 +58,99 @@ func (i *InfoWindow) Clear() {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InfoWindow) displayBuffer() {
|
||||
b := i.Buffer
|
||||
line := b.LineBytes(0)
|
||||
activeC := b.GetActiveCursor()
|
||||
|
||||
blocX := 0
|
||||
vlocX := utf8.RuneCountInString(i.Msg)
|
||||
|
||||
tabsize := 4
|
||||
line, nColsBeforeStart := util.SliceVisualEnd(line, blocX, tabsize)
|
||||
|
||||
draw := func(r rune, style tcell.Style) {
|
||||
if nColsBeforeStart <= 0 {
|
||||
bloc := buffer.Loc{X: blocX, Y: 0}
|
||||
if activeC.HasSelection() &&
|
||||
(bloc.GreaterEqual(activeC.CurSelection[0]) && bloc.LessThan(activeC.CurSelection[1]) ||
|
||||
bloc.LessThan(activeC.CurSelection[0]) && bloc.GreaterEqual(activeC.CurSelection[1])) {
|
||||
// The current character is selected
|
||||
style = config.DefStyle.Reverse(true)
|
||||
|
||||
if s, ok := config.Colorscheme["selection"]; ok {
|
||||
style = s
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
screen.Screen.SetContent(vlocX, i.y, r, nil, style)
|
||||
vlocX++
|
||||
}
|
||||
nColsBeforeStart--
|
||||
}
|
||||
|
||||
totalwidth := blocX - nColsBeforeStart
|
||||
for len(line) > 0 {
|
||||
if activeC.X == blocX {
|
||||
screen.Screen.ShowCursor(vlocX, i.y)
|
||||
}
|
||||
|
||||
r, size := utf8.DecodeRune(line)
|
||||
|
||||
draw(r, i.defStyle)
|
||||
|
||||
width := 0
|
||||
|
||||
char := ' '
|
||||
switch r {
|
||||
case '\t':
|
||||
ts := tabsize - (totalwidth % tabsize)
|
||||
width = ts
|
||||
default:
|
||||
width = runewidth.RuneWidth(r)
|
||||
char = '@'
|
||||
}
|
||||
|
||||
blocX++
|
||||
line = line[size:]
|
||||
|
||||
// Draw any extra characters either spaces for tabs or @ for incomplete wide runes
|
||||
if width > 1 {
|
||||
for j := 1; j < width; j++ {
|
||||
draw(char, i.defStyle)
|
||||
}
|
||||
}
|
||||
totalwidth += width
|
||||
if vlocX >= i.width {
|
||||
break
|
||||
}
|
||||
}
|
||||
if activeC.X == blocX {
|
||||
screen.Screen.ShowCursor(vlocX, i.y)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InfoWindow) Display() {
|
||||
x := 0
|
||||
if i.HasPrompt || config.GlobalSettings["infobar"].(bool) {
|
||||
if !i.HasPrompt && !i.HasMessage && !i.HasError {
|
||||
return
|
||||
}
|
||||
style := i.defStyle
|
||||
|
||||
if i.HasError {
|
||||
style = i.errStyle
|
||||
}
|
||||
|
||||
display := i.Msg + strings.TrimSpace(string(i.Bytes()))
|
||||
display := i.Msg
|
||||
for _, c := range display {
|
||||
screen.Screen.SetContent(x, i.y, c, nil, style)
|
||||
x += runewidth.RuneWidth(c)
|
||||
}
|
||||
|
||||
if i.HasPrompt {
|
||||
i.displayBuffer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -81,9 +80,8 @@ func (w *BufWindow) Bottomline() int {
|
||||
// }
|
||||
|
||||
prev := 0
|
||||
for i, l := range w.lineHeight {
|
||||
for _, l := range w.lineHeight {
|
||||
if l >= prev {
|
||||
log.Println("lineHeight[", i, "] = ", l)
|
||||
prev = l
|
||||
} else {
|
||||
break
|
||||
@@ -98,7 +96,6 @@ func (w *BufWindow) Bottomline() int {
|
||||
func (w *BufWindow) Relocate() bool {
|
||||
b := w.Buf
|
||||
height := w.Bottomline() + 1 - w.StartLine
|
||||
log.Println("Height: ", height)
|
||||
ret := false
|
||||
activeC := w.Buf.GetActiveCursor()
|
||||
cy := activeC.Y
|
||||
@@ -115,7 +112,6 @@ func (w *BufWindow) Relocate() bool {
|
||||
ret = true
|
||||
} else if cy >= b.LinesNum()-scrollmargin && cy >= height {
|
||||
w.StartLine = b.LinesNum() - height
|
||||
log.Println(w.StartLine)
|
||||
ret = true
|
||||
}
|
||||
|
||||
@@ -217,7 +213,7 @@ func (w *BufWindow) displayBuffer() {
|
||||
// this represents the current draw position in the buffer (char positions)
|
||||
bloc := buffer.Loc{X: w.StartCol, Y: w.StartLine}
|
||||
|
||||
activeC := w.Buf.GetActiveCursor()
|
||||
activeC := b.GetActiveCursor()
|
||||
|
||||
curStyle := config.DefStyle
|
||||
for vloc.Y = 0; vloc.Y < bufHeight; vloc.Y++ {
|
||||
|
||||
Reference in New Issue
Block a user