Start with creating a cursor for Input

This commit is contained in:
erroneousboat 2016-09-12 22:08:44 +02:00
parent 6cfa55c26e
commit 9cad8953d3

View File

@ -49,32 +49,35 @@ func (i *Input) SetY(y int) {
func (i *Input) Insert(key string) { func (i *Input) Insert(key string) {
i.Block.Text = i.Block.Text + key i.Block.Text = i.Block.Text + key
i.Block.TextBgColor = termui.ColorWhite i.MoveCursorRight()
i.Block.TextFgColor = termui.ColorBlack
i.CursorPosition++
} }
func (i *Input) Remove() { func (i *Input) Remove() {
if i.CursorPosition > 0 { if i.CursorPosition > 0 {
i.Block.Text = i.Block.Text[0:i.CursorPosition-1] + i.Block.Text[i.CursorPosition:len(i.Block.Text)] i.Block.Text = i.Block.Text[0:i.CursorPosition-1] + i.Block.Text[i.CursorPosition:len(i.Block.Text)]
i.MoveCursorLeft()
i.Block.TextBgColor = termui.ColorBlack
i.Block.TextFgColor = termui.ColorWhite
i.CursorPosition--
} }
} }
func (i *Input) MoveCursorRight() { func (i *Input) MoveCursorRight() {
if i.CursorPosition < len(i.Block.Text) { if i.CursorPosition < len(i.Block.Text) {
i.CursorPosition++ i.CursorPosition++
i.Block.Block.Buffer().Set(
i.CursorPosition, // x
i.Block.Block.InnerY(), // y
termui.Cell{Ch: rune('$'), Fg: termui.ColorBlack, Bg: termui.ColorWhite},
)
} }
} }
func (i *Input) MoveCursorLeft() { func (i *Input) MoveCursorLeft() {
if i.CursorPosition > 0 { if i.CursorPosition > 0 {
i.CursorPosition-- i.CursorPosition--
i.Block.Block.Buffer().Set(
i.CursorPosition, // x
i.Block.Block.InnerY(), // y
termui.Cell{Ch: rune('$'), Fg: termui.ColorBlack, Bg: termui.ColorWhite},
)
} }
} }