|
@@ -3,19 +3,19 @@ Package door: a go implementation of a BBS door for linux and Windows
|
|
|
that uses door32.sys, understand CP437 and unicode (if available),
|
|
|
detects screen size, and supports TheDraw Fonts.
|
|
|
|
|
|
- import (
|
|
|
- "door"
|
|
|
- )
|
|
|
-
|
|
|
- int main() {
|
|
|
- d = door.Door{}
|
|
|
- d.Init() // Process commandline switches, initialize door, detect screen size.
|
|
|
-
|
|
|
- d.Write("Welcome to my awesome door, written in "+door.ColorText("BLINK BOLD WHITE")+"go"+door.Reset+"."+door.CRNL)
|
|
|
- d.Write("Press a key...")
|
|
|
- d.Key()
|
|
|
- d.Write(door.CRNL)
|
|
|
- }
|
|
|
+ import (
|
|
|
+ "door"
|
|
|
+ )
|
|
|
+
|
|
|
+ int main() {
|
|
|
+ d = door.Door{}
|
|
|
+ d.Init() // Process commandline switches, initialize door, detect screen size.
|
|
|
+
|
|
|
+ d.Write("Welcome to my awesome door, written in "+door.ColorText("BLINK BOLD WHITE")+"go"+door.Reset+"."+door.CRNL)
|
|
|
+ d.Write("Press a key...")
|
|
|
+ d.Key()
|
|
|
+ d.Write(door.CRNL)
|
|
|
+ }
|
|
|
*/
|
|
|
package door
|
|
|
|
|
@@ -48,13 +48,15 @@ var Height int // Screen height detected
|
|
|
var Width int // Screen width detected
|
|
|
var Inactivity int64 = 120 // Inactivity timeout
|
|
|
|
|
|
-type MouseInfo struct {
|
|
|
- Button int
|
|
|
- X int
|
|
|
- Y int
|
|
|
+type CursorPos struct {
|
|
|
+ X, Y int
|
|
|
}
|
|
|
|
|
|
-var Mouse MouseInfo
|
|
|
+type Mouse struct {
|
|
|
+ Button int8
|
|
|
+ X int8
|
|
|
+ Y int8
|
|
|
+}
|
|
|
|
|
|
/*
|
|
|
door32.sys:
|
|
@@ -121,6 +123,54 @@ func (d *Door) WriterIsClosed() bool {
|
|
|
return d.WriterClosed
|
|
|
}
|
|
|
|
|
|
+func (d *Door) AddMouse(mouse Mouse) {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ d.LastMouse = append(d.LastMouse, mouse)
|
|
|
+}
|
|
|
+func (d *Door) GetMouse() (Mouse, bool) {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ return ArrayDelete(&d.LastMouse, 0)
|
|
|
+}
|
|
|
+
|
|
|
+func (d *Door) GetCursorPos() (CursorPos, bool) {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ return ArrayDelete(&d.LastCursor, 0)
|
|
|
+}
|
|
|
+
|
|
|
+func (d *Door) ClearMouseCursor() {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ d.LastMouse = make([]Mouse, 0, 2)
|
|
|
+ d.LastCursor = make([]CursorPos, 0, 3)
|
|
|
+}
|
|
|
+
|
|
|
+func (d *Door) AddMouse(mouse Mouse) {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ d.LastMouse = append(d.LastMouse, mouse)
|
|
|
+}
|
|
|
+func (d *Door) GetMouse() (Mouse, bool) {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ return ArrayDelete(&d.LastMouse, 0)
|
|
|
+}
|
|
|
+
|
|
|
+func (d *Door) GetCursorPos() (CursorPos, bool) {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ return ArrayDelete(&d.LastCursor, 0)
|
|
|
+}
|
|
|
+
|
|
|
+func (d *Door) ClearMouseCursor() {
|
|
|
+ d.mcMutex.Lock()
|
|
|
+ defer d.mcMutex.Unlock()
|
|
|
+ d.LastMouse = make([]Mouse, 0, 2)
|
|
|
+ d.LastCursor = make([]CursorPos, 0, 3)
|
|
|
+}
|
|
|
+
|
|
|
// Return the amount of time left as time.Duration
|
|
|
func (d *Door) TimeLeft() time.Duration {
|
|
|
return time.Until(d.TimeOut)
|
|
@@ -208,6 +258,7 @@ func (d *Door) detect() {
|
|
|
d.Write("\x03\x04\x1b[6n") // hearts and diamonds does CP437 work?
|
|
|
d.Write(CRNL + "\u2615\x1b[6n") // hot beverage
|
|
|
d.Write("\x1b[999C\x1b[999B\x1b[6n" + Reset + "\x1b[2J\x1b[H") // goto end of screen + cursor pos
|
|
|
+ // Yuck!
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
|
|
// read everything
|
|
@@ -349,7 +400,8 @@ func (d *Door) Close() {
|
|
|
// Goto X, Y - Position the cursor using ANSI Escape Codes
|
|
|
//
|
|
|
// Example:
|
|
|
-// d.Write(door.Goto(1, 5) + "Now at X=1, Y=5.")
|
|
|
+//
|
|
|
+// d.Write(door.Goto(1, 5) + "Now at X=1, Y=5.")
|
|
|
func Goto(x int, y int) string {
|
|
|
return fmt.Sprintf("\x1b[%d;%dH", y, x)
|
|
|
}
|