ソースを参照

Updating with BBS changes.

Steve Thielemann 2 年 前
コミット
9fe213985d
6 ファイル変更119 行追加38 行削除
  1. 47 19
      door/door.go
  2. 1 1
      door/go.mod
  3. 51 4
      door/input.go
  4. 14 11
      door/menu.go
  5. 1 1
      testdoor/go.mod
  6. 5 2
      testdoor/testdoor.go

+ 47 - 19
door/door.go

@@ -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),
 that uses door32.sys, understand CP437 and unicode (if available),
 detects screen size, and supports TheDraw Fonts.
 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
 package door
 
 
@@ -48,13 +48,15 @@ var Height int             // Screen height detected
 var Width int              // Screen width detected
 var Width int              // Screen width detected
 var Inactivity int64 = 120 // Inactivity timeout
 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:
 door32.sys:
@@ -121,6 +123,30 @@ func (d *Door) WriterIsClosed() bool {
 	return d.WriterClosed
 	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)
+}
+
 // Return the amount of time left as time.Duration
 // Return the amount of time left as time.Duration
 func (d *Door) TimeLeft() time.Duration {
 func (d *Door) TimeLeft() time.Duration {
 	return time.Until(d.TimeOut)
 	return time.Until(d.TimeOut)
@@ -208,6 +234,7 @@ func (d *Door) detect() {
 	d.Write("\x03\x04\x1b[6n")                                     // hearts and diamonds does CP437 work?
 	d.Write("\x03\x04\x1b[6n")                                     // hearts and diamonds does CP437 work?
 	d.Write(CRNL + "\u2615\x1b[6n")                                // hot beverage
 	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
 	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)
 	time.Sleep(250 * time.Millisecond)
 
 
 	// read everything
 	// read everything
@@ -349,7 +376,8 @@ func (d *Door) Close() {
 // Goto X, Y - Position the cursor using ANSI Escape Codes
 // Goto X, Y - Position the cursor using ANSI Escape Codes
 //
 //
 // Example:
 // 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 {
 func Goto(x int, y int) string {
 	return fmt.Sprintf("\x1b[%d;%dH", y, x)
 	return fmt.Sprintf("\x1b[%d;%dH", y, x)
 }
 }

+ 1 - 1
door/go.mod

@@ -1,3 +1,3 @@
 module red-green/door
 module red-green/door
 
 
-go 1.17
+go 1.19

+ 51 - 4
door/input.go

@@ -8,6 +8,52 @@ import (
 	"unicode"
 	"unicode"
 )
 )
 
 
+// This is neat, would be neater if it WORKED! go:generate stringer -type=Extended
+type Extended int8
+
+const (
+	NOP Extended = iota
+	UP_ARROW
+	DOWN_ARROW
+	RIGHT_ARROW
+	LEFT_ARROW
+	HOME
+	END
+	PAGE_UP
+	PAGE_DOWN
+	INSERT
+	DELETE
+	F1
+	F2
+	F3
+	F4
+	F5
+	F6
+	F7
+	F8
+	F9
+	F10
+	F11
+	F12
+	MOUSE
+	CURSOR
+	UNKNOWN
+)
+
+// To rebuild this, copy the above into it's own file and generate.
+// Then, copy the generated code to below:
+
+const _Extended_name = "NOPUP_ARROWDOWN_ARROWRIGHT_ARROWLEFT_ARROWHOMEENDPAGE_UPPAGE_DOWNINSERTDELETEF1F2F3F4F5F6F7F8F9F10F11F12MOUSECURSORUNKNOWN"
+
+var _Extended_index = [...]uint8{0, 3, 11, 21, 32, 42, 46, 49, 56, 65, 71, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 98, 101, 104, 109, 115, 122}
+
+func (i Extended) String() string {
+	if i < 0 || i >= Extended(len(_Extended_index)-1) {
+		return "Extended(" + strconv.FormatInt(int64(i), 10) + ")"
+	}
+	return _Extended_name[_Extended_index[i]:_Extended_index[i+1]]
+}
+
 // This is the current list of Extended keys we support:
 // This is the current list of Extended keys we support:
 const (
 const (
 	XKEY_UP_ARROW    = 0x1001
 	XKEY_UP_ARROW    = 0x1001
@@ -231,11 +277,12 @@ func (d *Door) GetKey() int {
 
 
 		if strings.HasPrefix(string(extended), "[M") && len(extended) == 5 {
 		if strings.HasPrefix(string(extended), "[M") && len(extended) == 5 {
 			// log.Printf("MOUSE Extended %#v\n", extended)
 			// log.Printf("MOUSE Extended %#v\n", extended)
-			Mouse.Button = int(extended[2]) - 0x20 + 1
-			Mouse.X = int(extended[3]) - 0x21 + 1
-			Mouse.Y = int(extended[4]) - 0x21 + 1
+			var mouse Mouse = Mouse{Button: int8(extended[2]) - ' ' + 1,
+				X: int8(extended[3]) - '!' + 1,
+				Y: int8(extended[4]) - '!' + 1}
+			d.AddMouse(mouse)
+			log.Printf("MOUSE %d (%d,%d)\n", mouse.Button, mouse.X, mouse.Y)
 			return XKEY_MOUSE
 			return XKEY_MOUSE
-			// log.Printf("MOUSE %d (%d,%d)\n", mouse_button, mouse_x, mouse_y)
 		}
 		}
 
 
 		log.Printf("ERROR Extended %#v\n", extended)
 		log.Printf("ERROR Extended %#v\n", extended)

+ 14 - 11
door/menu.go

@@ -156,17 +156,20 @@ func (m *Menu) Choose(d *Door) int {
 		}
 		}
 
 
 		if event == XKEY_MOUSE {
 		if event == XKEY_MOUSE {
-			if Mouse.Button == 65 {
-				// Translate Mouse Wheel Up
-				event = XKEY_UP_ARROW
-			}
-			if Mouse.Button == 66 {
-				// Translate Mouse Wheel Down
-				event = XKEY_DOWN_ARROW
-			}
-			// Look at Mouse X/Y to determine where they clicked
-			if Mouse.Button == 1 || Mouse.Button == 2 {
-				log.Println("Mouse (", Mouse.X, ",", Mouse.Y, ")")
+			mouse, ok := d.GetMouse()
+			if ok {
+				if mouse.Button == 65 {
+					// Translate Mouse Wheel Up
+					event = XKEY_UP_ARROW
+				}
+				if mouse.Button == 66 {
+					// Translate Mouse Wheel Down
+					event = XKEY_DOWN_ARROW
+				}
+				// Look at Mouse X/Y to determine where they clicked
+				if mouse.Button == 1 || mouse.Button == 2 {
+					log.Println("Mouse (", mouse.X, ",", mouse.Y, ")")
+				}
 			}
 			}
 		}
 		}
 
 

+ 1 - 1
testdoor/go.mod

@@ -1,6 +1,6 @@
 module red-green/testdoor
 module red-green/testdoor
 
 
-go 1.17
+go 1.19
 
 
 replace red-green/door => ../door
 replace red-green/door => ../door
 
 

+ 5 - 2
testdoor/testdoor.go

@@ -35,8 +35,11 @@ func press_keys(d *door.Door) {
 	for k != 0x0d {
 	for k != 0x0d {
 		k = d.Key()
 		k = d.Key()
 		if k == door.XKEY_MOUSE {
 		if k == door.XKEY_MOUSE {
-			var m door.MouseInfo = door.Mouse
-			d.Write(fmt.Sprintf("M %d (%d,%d) ", m.Button, m.X, m.Y))
+			m, ok := d.GetMouse()
+			if ok {
+				// var m door.MouseInfo = door.Mouse
+				d.Write(fmt.Sprintf("M %d (%d,%d) ", m.Button, m.X, m.Y))
+			}
 		} else {
 		} else {
 			d.Write(fmt.Sprintf("%d (%x) ", k, k))
 			d.Write(fmt.Sprintf("%d (%x) ", k, k))
 		}
 		}