mirror of
https://github.com/EnumeratedDev/typer.git
synced 2026-10-31 11:31:48 +00:00
Add input bar and implement File->Open dropdown option
This commit is contained in:
1 parent
3f924f7e38
commit
bde4eeb070
4 files changed
+159
-38
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
type TyperInputRequest struct {
|
||||
Text string
|
||||
input string
|
||||
cursorPos int
|
||||
inputChannel chan string
|
||||
}
|
||||
|
||||
var currentInputRequest *TyperInputRequest
|
||||
|
||||
func RequestInput(window *Window, text string) chan string {
|
||||
request := &TyperInputRequest{
|
||||
Text: text,
|
||||
input: "",
|
||||
cursorPos: 0,
|
||||
inputChannel: make(chan string),
|
||||
}
|
||||
|
||||
currentInputRequest = request
|
||||
|
||||
window.CursorMode = CursorModeInputBar
|
||||
|
||||
return request.inputChannel
|
||||
}
|
||||
|
||||
func IsRequestingInput() bool {
|
||||
return currentInputRequest != nil
|
||||
}
|
||||
|
||||
func drawInputBar(window *Window) {
|
||||
if currentInputRequest == nil {
|
||||
return
|
||||
}
|
||||
|
||||
screen := window.screen
|
||||
|
||||
inputBarStyle := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite)
|
||||
|
||||
sizeX, sizeY := screen.Size()
|
||||
|
||||
// Draw bar
|
||||
for x := 0; x < sizeX; x++ {
|
||||
char := ' '
|
||||
screen.SetContent(x, sizeY-1, char, nil, inputBarStyle)
|
||||
}
|
||||
|
||||
// Write text
|
||||
for x := 0; x < len(currentInputRequest.Text); x++ {
|
||||
screen.SetContent(x, sizeY-1, rune(currentInputRequest.Text[x]), nil, inputBarStyle)
|
||||
}
|
||||
for x := 0; x < len(currentInputRequest.input); x++ {
|
||||
screen.SetContent(x+len(currentInputRequest.Text)+1, sizeY-1, rune(currentInputRequest.input[x]), nil, inputBarStyle)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user