mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
Merge pull request #451 from peco/topic/set-cursor
Call SetCursor when drawing the prompt
This commit is contained in:
commit
9385f4ec68
8
caret.go
8
caret.go
|
|
@ -6,14 +6,18 @@ func (c *Caret) Pos() int {
|
|||
return c.pos
|
||||
}
|
||||
|
||||
func (c *Caret) setPos_nolock(p int) {
|
||||
c.pos = p
|
||||
}
|
||||
|
||||
func (c *Caret) SetPos(p int) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
c.pos = p
|
||||
c.setPos_nolock(p)
|
||||
}
|
||||
|
||||
func (c *Caret) Move(diff int) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
c.pos = c.pos + diff
|
||||
c.setPos_nolock(c.pos + diff)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ type Screen interface {
|
|||
Print(PrintArgs) int
|
||||
Resume()
|
||||
SetCell(int, int, rune, termbox.Attribute, termbox.Attribute)
|
||||
SetCursor(int, int)
|
||||
Size() (int, int)
|
||||
SendEvent(termbox.Event)
|
||||
Suspend()
|
||||
|
|
|
|||
11
layout.go
11
layout.go
|
|
@ -111,6 +111,10 @@ func (u UserPrompt) Draw(state *Peco) {
|
|||
|
||||
fg := u.styles.Query.fg
|
||||
bg := u.styles.Query.bg
|
||||
|
||||
// Used to notify termbox where our cursor is
|
||||
var posX int
|
||||
|
||||
switch ql {
|
||||
case 0:
|
||||
u.screen.Print(PrintArgs{
|
||||
|
|
@ -120,6 +124,7 @@ func (u UserPrompt) Draw(state *Peco) {
|
|||
Bg: bg,
|
||||
Fill: true,
|
||||
})
|
||||
posX = u.promptLen + 1
|
||||
u.screen.Print(PrintArgs{
|
||||
X: u.promptLen + 1,
|
||||
Y: location,
|
||||
|
|
@ -145,8 +150,9 @@ func (u UserPrompt) Draw(state *Peco) {
|
|||
Msg: qs,
|
||||
Fill: false,
|
||||
})
|
||||
posX = u.promptLen + 1 + int(runewidth.StringWidth(qs))
|
||||
u.screen.Print(PrintArgs{
|
||||
X: u.promptLen + 1 + int(runewidth.StringWidth(qs)),
|
||||
X: posX,
|
||||
Y: location,
|
||||
Fg: fg | termbox.AttrReverse,
|
||||
Bg: bg | termbox.AttrReverse,
|
||||
|
|
@ -154,6 +160,7 @@ func (u UserPrompt) Draw(state *Peco) {
|
|||
Fill: false,
|
||||
})
|
||||
default:
|
||||
posX = c.Pos()
|
||||
// the caret is in the middle of the string
|
||||
prev := int(0)
|
||||
var i int
|
||||
|
|
@ -179,6 +186,8 @@ func (u UserPrompt) Draw(state *Peco) {
|
|||
})
|
||||
}
|
||||
|
||||
u.screen.SetCursor(posX, location)
|
||||
|
||||
width, _ := u.screen.Size()
|
||||
|
||||
loc := state.Location()
|
||||
|
|
|
|||
|
|
@ -101,6 +101,9 @@ func NewDummyScreen() *dummyScreen {
|
|||
}
|
||||
}
|
||||
|
||||
func (d dummyScreen) SetCursor(_, _ int) {
|
||||
}
|
||||
|
||||
func (d dummyScreen) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ func (t *Termbox) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *Termbox) SetCursor(x, y int) {
|
||||
termbox.SetCursor(x, y)
|
||||
}
|
||||
|
||||
// SendEvent is used to allow programmers generate random
|
||||
// events, but it's only useful for testing purposes.
|
||||
// When interactiving with termbox-go, this method is a noop
|
||||
|
|
|
|||
Loading…
Reference in a new issue