@@ -7,10 +7,14 @@ import (
77	"github.com/alex11br/gxhk/common" 
88)
99
10+ // Exec executes the given sh command string. This method is blocking. 
1011func  Exec (command  string ) {
1112	exec .Command ("sh" , "-c" , command ).Run ()
1213}
1314
15+ // MakeDescription handles the logic behind generating a dummy description for the commands 
16+ // which don't come with a description (i.e. it is empty) from the command string, 
17+ // or returning the description if it isn't empty 
1418func  MakeDescription (description  string , command  string ) string  {
1519	if  description  !=  ""  {
1620		return  description 
@@ -19,19 +23,25 @@ func MakeDescription(description string, command string) string {
1923	}
2024}
2125
26+ // AddEventInfo handles the logic behind creating a new line and filling it 
27+ // with the infos necessary for the 'info' command for each bound hotkey 
2228func  AddEventInfo (infos  * string , hotkey  string , eventName  string , description  string ) {
2329	if  * infos  !=  ""  {
2430		* infos  +=  "\n " 
2531	}
2632	* infos  +=  fmt .Sprintf ("On %s %s: %s" , hotkey , eventName , description )
2733}
2834
35+ // Bind does the heavy work of binding a hotkey (plus its eventual sisters) to a command. 
2936func  Bind (bindArgs  common.BindCmd ) error  {
30- 	hotkeys , err  :=  HotkeyFromStr (bindArgs .Hotkey )
37+ 	// First, we find the Hotkey's that correspond to the given hotkey string. 
38+ 	hotkeys , err  :=  HotkeysFromStr (bindArgs .Hotkey )
3139	if  err  !=  nil  {
3240		return  err 
3341	}
3442
43+ 	// Then, grab the matching keys which haven't been grabbed yet (i.e. those without commands). 
44+ 	// If any of these new keys fail to grab, we ungrab what we got to grab before and leave. 
3545	newlyBound  :=  make ([]Hotkey , 0 )
3646	for  _ , hotkey  :=  range  hotkeys  {
3747		if  KeyPressCommands .IsEmpty (hotkey ) &&  KeyReleaseCommands .IsEmpty (hotkey ) {
@@ -47,6 +57,13 @@ func Bind(bindArgs common.BindCmd) error {
4757		}
4858	}
4959
60+ 	// Now we'll set all the appropiate values in the necessary places 
61+ 	// to successfully bind the hotkeys. 
62+ 	// It is worth noting that if there are multiple hotkeys for the same string, 
63+ 	// in the 'info' command only one of them should provide descriptions. As such: 
64+ 	// CONVENTION: Empty description of a Hotkey (description == "") MEANS ignore that Hotkey!!! 
65+ 	// We'll put a non-empty description for the first matching Hotkey (refer to MakeDescription) 
66+ 	// and for any eventual ones an empty description 
5067	for  i , hotkey  :=  range  hotkeys  {
5168		var  description  string 
5269		if  i  ==  0  {
@@ -67,8 +84,10 @@ func Bind(bindArgs common.BindCmd) error {
6784	return  nil 
6885}
6986
87+ // Unbind does the not-so-heavy work of unbinding a hotkey (plus its eventual sisters), 
88+ // which consists in ungrabbing the keys, and deleting the keys in the HotkeyMap's 
7089func  Unbind (unbindArgs  common.UnbindCmd ) error  {
71- 	hotkeys , err  :=  HotkeyFromStr (unbindArgs .Hotkey )
90+ 	hotkeys , err  :=  HotkeysFromStr (unbindArgs .Hotkey )
7291	if  err  !=  nil  {
7392		return  err 
7493	}
@@ -90,8 +109,13 @@ func Unbind(unbindArgs common.UnbindCmd) error {
90109	return  nil 
91110}
92111
112+ // GetInfo returns the information about what is bound to the given hotkeyStr. 
113+ // It returns a Response structure to easily accomodate the need to mention 
114+ // parsing errors if the hotkeyStr is "naughty". 
115+ // The first Hotkey to be parsed should be the main one, 
116+ // which represents our needed description in the description maps. 
93117func  GetInfo (hotkeyStr  string ) (res  common.Response ) {
94- 	hotkeys , err  :=  HotkeyFromStr (hotkeyStr )
118+ 	hotkeys , err  :=  HotkeysFromStr (hotkeyStr )
95119	if  err  !=  nil  {
96120		return  common.Response {
97121			Status :  1 ,
@@ -113,6 +137,8 @@ func GetInfo(hotkeyStr string) (res common.Response) {
113137	return 
114138}
115139
140+ // GetAllInfo creates a string with all the bound hotkeys there are, 
141+ // both those bound on press and those bound on release. 
116142func  GetAllInfo () (info  string ) {
117143	KeyPressDescriptions .ForEach (func (hotkey  Hotkey , description  string ) {
118144		if  description  !=  ""  {
0 commit comments