@@ -95,10 +95,10 @@ function setup(c) {}
9595function draw (c ) {}
9696```
9797
98- You can add extra methods ` onKey ` and ` onMouse ` to catch keyboard and mouse events:
98+ You can add extra methods ` onKey ` and ` onMouseClick ` to catch keyboard or mouse events (check [ events documentation ] ( #events ) ) :
9999``` js
100100function onKey (c , e ) {}
101- function onMouse (c , e ) {}
101+ function onMouseClick (c , e ) {}
102102````
103103
104104And you can then execute the file with:
@@ -136,16 +136,17 @@ import (
136136)
137137
138138func main() {
139- runal.Run(context.Background(), setup, draw, onKey, onMouse )
139+ runal.Run(context.Background(), setup, draw, runal.WithOnKey( onKey), runal.WithOnMouseClick(onMouseClick) )
140140}
141141
142142func setup(c *runal.Canvas) {}
143143
144144func draw(c *runal.Canvas) {}
145145
146- // You can add extra methods ` onKey` and ` onMouse` to catch keyboard and mouse events
146+ // You can add extra methods ` onKey` and ` onMouseClick` to catch keyboard and mouse events.
147+ // Ensure to register them in the runal.Run() function.
147148func onKey(c *runal.Canvas, e runal.KeyEvent) {}
148- func onMouse (c *runal.Canvas, e runal.MouseEvent) {}
149+ func onMouseClick (c *runal.Canvas, e runal.MouseEvent) {}
149150` ` `
150151
151152And you can then execute the file with:
@@ -617,6 +618,16 @@ function onKey(c, event) {
617618}
618619` ` `
619620
621+ In go you need to register the event through the ` Run ()` method using the functional option ` WithOnKey` .
622+ ` ` ` go
623+ func main () {
624+ runal .Run (context .Background (), setup, draw, runal .WithOnKey (onKey))
625+ }
626+ func setup (c * runal .Canvas ) {}
627+ func draw (c * runal .Canvas ) {}
628+ func onKey (c * runal .Canvas , e runal .KeyEvent ) {}
629+ ` ` `
630+
620631Event is an object with the following attributes:
621632 - **key**: the string representation of the key pressed (` a` , ` b` , ` c` , ` 1 ` , ` 2 ` , ` 3 ` etc...)
622633 - **code**: the numerical value of the key pressed (97, 98, 99, 49, 50, 51 etc...)
@@ -644,6 +655,17 @@ function onMouseClick(c, event) {
644655 }
645656}
646657` ` `
658+
659+ In Go you need to register the event through the ` Run ()` method using the functional option ` WithOnMouseClick` .
660+ ` ` ` go
661+ func main () {
662+ runal .Run (context .Background (), setup, draw, runal .WithOnMouseClick (onMouseClick))
663+ }
664+ func setup (c * runal .Canvas ) {}
665+ func draw (c * runal .Canvas ) {}
666+ func onMouseClick (c * runal .Canvas , e runal .MouseEvent ) {}
667+ ` ` `
668+
647669Event is an object with the following attributes:
648670 - **x**: the horizontal mouse position relative to the terminal window
649671 - **y**: the vertical mouse position relative to the terminal window
@@ -667,6 +689,17 @@ function onMouseRelease(c, event) {
667689 }
668690}
669691` ` `
692+
693+ In Go you need to register the event through the ` Run ()` method using the functional option ` WithOnMouseRelease` .
694+ ` ` ` go
695+ func main () {
696+ runal .Run (context .Background (), setup, draw, runal .WithOnMouseRelease (onMouseRelease))
697+ }
698+ func setup (c * runal .Canvas ) {}
699+ func draw (c * runal .Canvas ) {}
700+ func onMouseRelease (c * runal .Canvas , e runal .MouseEvent ) {}
701+ ` ` `
702+
670703Event is an object with the following attributes:
671704 - **x**: the horizontal mouse position relative to the terminal window
672705 - **y**: the vertical mouse position relative to the terminal window
@@ -698,6 +731,17 @@ function onMouseWheel(c, event) {
698731 }
699732}
700733` ` `
734+
735+ In Go you need to register the event through the ` Run ()` method using the functional option ` WithOnMouseWheel` .
736+ ` ` ` go
737+ func main () {
738+ runal .Run (context .Background (), setup, draw, runal .WithOnMouseWheel (onMouseWheel))
739+ }
740+ func setup (c * runal .Canvas ) {}
741+ func draw (c * runal .Canvas ) {}
742+ func onMouseWheel (c * runal .Canvas , e runal .MouseEvent ) {}
743+ ` ` `
744+
701745Event is an object with the following attributes:
702746 - **x**: the horizontal mouse position relative to the terminal window
703747 - **y**: the vertical mouse position relative to the terminal window
@@ -721,6 +765,17 @@ function onMouseMove(c, event) {
721765 c .backgroundBg (color);
722766}
723767` ` `
768+
769+ In Go you need to register the event through the ` Run ()` method using the functional option ` WithOnMouseMove` .
770+ ` ` ` go
771+ func main () {
772+ runal .Run (context .Background (), setup, draw, runal .WithOnMouseMove (onMouseMove))
773+ }
774+ func setup (c * runal .Canvas ) {}
775+ func draw (c * runal .Canvas ) {}
776+ func onMouseMove (c * runal .Canvas , e runal .MouseEvent ) {}
777+ ` ` `
778+
724779Event is an object with the following attributes:
725780 - **x**: the horizontal mouse position relative to the terminal window
726781 - **y**: the vertical mouse position relative to the terminal window
0 commit comments