mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
trying to make cursor not blink while typing which doesn't work on edit.js
This commit is contained in:
115
assets/disk0/tvdos/bin/telcom.js
Normal file
115
assets/disk0/tvdos/bin/telcom.js
Normal file
@@ -0,0 +1,115 @@
|
||||
let port = Number.parseInt(exec_args[1])
|
||||
|
||||
let [scrh, scrw] = con.getmaxyx()
|
||||
let status = 0
|
||||
let focus = 0
|
||||
let statusStr = ["Not Connected", "Idle", "Sending", "Receiving"]
|
||||
let getFocusStr = [()=>"CMD", ()=>`COM${port}`]
|
||||
|
||||
if (Number.isNaN(port)) {
|
||||
port = undefined
|
||||
}
|
||||
else {
|
||||
focus = 1
|
||||
}
|
||||
|
||||
|
||||
function greet() {
|
||||
if (!port) {
|
||||
println("COM port not specified; please run 'listen [1|2|3|4]' to open a port first.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function drawStatusBar() {
|
||||
let [oy, ox] = con.getyx()
|
||||
|
||||
con.curs_set(0)
|
||||
con.move(scrh, 0)
|
||||
con.video_reverse()
|
||||
|
||||
print(` ${getFocusStr[focus]()} ${statusStr[0]} `)
|
||||
|
||||
con.video_reverse()
|
||||
con.move(oy, ox)
|
||||
con.curs_set(1)
|
||||
}
|
||||
|
||||
function sendMessage(line) {
|
||||
if (0 == line.size) return;
|
||||
var tokens = _G.shell.parse(line);
|
||||
var cmd = tokens[0];
|
||||
if (cmd === undefined || cmd === '') return 0;
|
||||
|
||||
// handle Ctrl-C
|
||||
if (con.hitterminate()) {
|
||||
cmdExit = true
|
||||
}
|
||||
|
||||
if (focus == 0) {
|
||||
if ("exit" == cmd || "quit" == cmd) cmdExit = true
|
||||
else if ("listen" == cmd) {
|
||||
port = Number.parseInt(tokens[1])
|
||||
if (Number.isNaN(port)) {
|
||||
port = undefined
|
||||
}
|
||||
else {
|
||||
focus = 1
|
||||
}
|
||||
}
|
||||
else if ("pull" == cmd && port) {
|
||||
println(com.pullMessage(port - 1))
|
||||
}
|
||||
}
|
||||
else {
|
||||
com.sendMessage(port - 1, line + "\x17")
|
||||
println(com.fetchResponse(port - 1))
|
||||
}
|
||||
}
|
||||
|
||||
function print_prompt_text() {
|
||||
print(`${getFocusStr[focus]()}> `)
|
||||
}
|
||||
|
||||
con.curs_set(1)
|
||||
greet()
|
||||
let cmdExit = false
|
||||
while (!cmdExit) {
|
||||
// drawStatusBar()
|
||||
print_prompt_text()
|
||||
|
||||
let cmdbuf = ""
|
||||
|
||||
while (true) {
|
||||
// TODO event-ify key in and serial in so that they can run simultaneously
|
||||
|
||||
let key = con.getch()
|
||||
|
||||
// printable chars
|
||||
if (key == 1) { // Ctrl+A
|
||||
println()
|
||||
focus = 0
|
||||
break
|
||||
}
|
||||
else if (key >= 32 && key <= 126) {
|
||||
let s = String.fromCharCode(key)
|
||||
cmdbuf += s
|
||||
print(s)
|
||||
}
|
||||
// backspace
|
||||
else if (key === con.KEY_BACKSPACE && cmdbuf.length > 0) {
|
||||
cmdbuf = cmdbuf.substring(0, cmdbuf.length - 1)
|
||||
print(String.fromCharCode(key))
|
||||
}
|
||||
// enter
|
||||
else if (key === 10 || key === con.KEY_RETURN) {
|
||||
println()
|
||||
|
||||
sendMessage(cmdbuf)
|
||||
|
||||
con.curs_set(1)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1083,6 +1083,10 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
||||
textCursorIsOn = !textCursorIsOn
|
||||
}
|
||||
|
||||
// force light cursor up while typing
|
||||
textCursorIsOn = textCursorIsOn || ((1..254).any { Gdx.input.isKeyPressed(it) })
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun blendNormal(batch: SpriteBatch) {
|
||||
|
||||
Reference in New Issue
Block a user