Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Configurable keybinds #117

Closed
wants to merge 3 commits into from
Closed

[WIP] Configurable keybinds #117

wants to merge 3 commits into from

Conversation

glvr182
Copy link

@glvr182 glvr182 commented Jul 7, 2019

fixes #48
Signed-off-by: Glenn Vriesman [email protected]

@codecov-io
Copy link

Codecov Report

Merging #117 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #117   +/-   ##
=======================================
  Coverage   23.41%   23.41%           
=======================================
  Files          13       13           
  Lines        1089     1089           
=======================================
  Hits          255      255           
  Misses        821      821           
  Partials       13       13
Impacted Files Coverage Δ
pkg/config/app_config.go 76.47% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cca69e6...abc54e0. Read the comment docs.

@codecov-io
Copy link

codecov-io commented Jul 7, 2019

Codecov Report

Merging #117 into master will decrease coverage by 2.57%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #117      +/-   ##
==========================================
- Coverage   26.12%   23.55%   -2.58%     
==========================================
  Files          13       13              
  Lines        1129     1091      -38     
==========================================
- Hits          295      257      -38     
  Misses        821      821              
  Partials       13       13
Impacted Files Coverage Δ
pkg/config/app_config.go 76.85% <ø> (-5.54%) ⬇️
pkg/commands/container.go 0% <0%> (ø) ⬆️
pkg/commands/container_stats.go 0% <0%> (ø) ⬆️
pkg/commands/docker.go 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8970352...1b5afd2. Read the comment docs.

@glvr182
Copy link
Author

glvr182 commented Jul 10, 2019

@jesseduffield and anyone interested

I'm in a bit of a pickle, keybindings.ParseAll() returns both the an object(containing the key, the modifier and the tokens), and an error.
How should i go about setting the keybindings in keybinding.go?
I was thinking about a for loop, but that seems like a lot of work for a not so pretty solution.
I'm now thinking of a helper function that panics if it contains an error and having a recovery function to catch that, but even with that i'd have to refactor a lot

@glvr182
Copy link
Author

glvr182 commented Jul 10, 2019

The keybinding struct (now having []interface{} instead of interface{})

type Binding struct {
  ViewName    string
  Handler     func(*gocui.Gui, *gocui.View) error
  Key         []interface{} // FIXME: find out how to get `gocui.Key | rune`
  Modifier    gocui.Modifier
  Description string
}

The recovery

defer func() {
  if r := recover(); r != nil {
    fmt.Println("Recovered in f", r)
  }
}()

The keybinding def

{
  ViewName: "",
  Key:      filterParser(keybinding.ParseAll("ctrl+A, ctrl+B, CTRL+ALT+C")),
  Modifier: gocui.ModNone,
  Handler:  gui.quit,
},

The helper function

func filterParser(binds []keybinding.Key, err error) []gocui.Key {
  var keys []gocui.Key
  if err != nil {
    panic(err)
  }
  for _, bind := range binds {
    keys = append(keys, bind.Value)
  }
  return keys
}

@jesseduffield
Copy link
Owner

@glvr182 I think we should put the default KeyConfig on the UserConfig struct in app_config.go. We can then have our filterParser method in that file and it can handle all of our defaults on startup.

In UserConfig:

Keybindings KeyConfig `yaml:"keybindings,omitempty"`

In GetDefaultConfig

		Keybindings: KeyConfig{
			Quit: []string{"q"},
                         ...
		},

Then in keybindings.go

		{
			ViewName: "",
			Keys:     parsedKeybindings(gui.Config.UserConfig.Keybindings.Quit),
			Modifier: gocui.ModNone,
			Handler:  gui.quit,
		},

and then in the same file:

func parsedKeybindings(binds []string) []gocui.Key {
  var keys []gocui.Key
  for _, bind := range binds {
    keys = append(keys, keybindings.MustParse(bind)) // MustParse panics on failure
  }
  return keys
}

you'll need each keybinding to support an array of keys, so then you'll be doing this in keybindings():

	for _, binding := range bindings {
		for _, key := range binding.keys {
			if err := g.SetKeybinding(binding.ViewName, key, binding.Modifier, binding.Handler); err != nil {
				return err
			}
		}
	}

I think it's worth adding a MustParse() function to the keybindings library, which panics on failure, so that we don't need to worry about the error that could be returned. As you say we can recover from it.

Hopefully the fact we now need to use an []interface{} isn't too bad, though I have had bad experiences with interface{} arrays in the past.

What are your thoughts?

@glvr182
Copy link
Author

glvr182 commented Jul 12, 2019

I think having a must parse function in the lib is a good idea, I shall make that function tomorrow, (or if you have time be my guest).

I'm not the biggest fan of interfaces either, i prefer having an actual type, but maybe we find a way to resolve that along the road. (might try that in this pr).

I think with the MustParse function I'll be able to finish this soon.

Thanks for your input!

@glvr182
Copy link
Author

glvr182 commented Jul 14, 2019

Just finished the mustParse functions, will use them now

@glvr182
Copy link
Author

glvr182 commented Jul 14, 2019

@jesseduffield I'm again in a bit of a pickle, keybinding library uses awesome-gocui/gocui, lazydocker uses jesseduffield/gocui, what do you recon would be the best

@jesseduffield
Copy link
Owner

@glvr182 that is a good question. I would like for the two gocuis to be one-and-the-same, but I haven't really put the effort in to port my stuff over to awesome-gocui/gocui when I add something to my own.

What are your thoughts on defining the gocui keys in the keybindings package and casting them in the consuming package? I'm assuming they are all integers under the hood? Otherwise, if we think that it's going to be too much work to get the two gocuis synced up, I could fork the keybindings package and get it to point at my own gocui.

@glvr182
Copy link
Author

glvr182 commented Jul 22, 2019

@jesseduffield They are as far as i know uint16, I don't really like the idea of casting, for obvious reasons, but as you said we would have to update awesome-gocui/gocui a lot. Maybe we could focus on that, as others might have use for it aswell.

@jesseduffield
Copy link
Owner

agreed

 * Might change this to less code later

Signed-off-by: Glenn Vriesman <[email protected]>
@glvr182
Copy link
Author

glvr182 commented Aug 1, 2019

I'm settings the defaults right now, it's taking longer than i hoped, thanks for the patience

@glvr182
Copy link
Author

glvr182 commented Aug 1, 2019

Rebased from master

@glvr182
Copy link
Author

glvr182 commented Aug 1, 2019

@jesseduffield might it be possible to lock the app_config.go and keybindings files for the time being? Just untill the pr is done

@jesseduffield
Copy link
Owner

sure, how long do you think you'll need?

@glvr182
Copy link
Author

glvr182 commented Aug 3, 2019

Well once i set all the defaults, i can test it. So how about this weekend?

 * Cleaned up some code
 * Added missing configs
 * Added documentation
 * Implemented config referencing to keybindings.go

Signed-off-by: Glenn Vriesman <[email protected]>
@glvr182
Copy link
Author

glvr182 commented Aug 4, 2019

Apart from the errors, i think you can have a look at the keybinding configs @jesseduffield

 * Changed the workings of a view functions to support multiple kb
 * Fixed some errors regarding building

Signed-off-by: Glenn Vriesman <[email protected]>
@glvr182
Copy link
Author

glvr182 commented Aug 5, 2019

Seems to be an issue with parsing characters to keys, will have to do more investigation
Might end up merging keybindings into gocui

@glvr182
Copy link
Author

glvr182 commented Aug 6, 2019

Hit a bug while setting up the parser, hope to get stuff working tomorrow

@glvr182 glvr182 mentioned this pull request Sep 3, 2019
@dawidd6
Copy link
Collaborator

dawidd6 commented Sep 3, 2019

@glvr182 how is it going? Maybe need some halp?

@glvr182
Copy link
Author

glvr182 commented Sep 3, 2019

Yea well I back then hit a bug that had to do with some casting stuff. Haven't been able to fix that, but i was working on merging jesse's gocui with the awesome-gocui/gocui one to fix it. I'll post some errors tonight.

@glvr182 glvr182 closed this Dec 24, 2019
arcticicestudio added a commit to arcticicestudio/igloo that referenced this pull request Jun 22, 2020
Creates a new snowblock for lazydocker [1].
> The lazier way to manage everything Docker.
> A simple terminal UI for both Docker and docker-compose.

I've used it for quite some time and the configurations have now been
tested enough on a day-by-day basis to be persisted in igloo.

Initially this includes the `config.yml` file [2] symlinked to the
corresponding XDG specific [3] and OS dependent path(s) [4].
The keybindings [5] are can not be customized yet, but some initial work
has been done [6] so maybe it'll be possible in later versions.
The colors have been adjusted to match the Nord [7] theme style.

For more details about available configurations see the
`github.com/jesseduffield/lazydocker/pkg/config` package documentation
[8].

[1]: https://github.com/jesseduffield/lazydocker
[2]: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md
[3]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
[4]: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md#locations
[5]: https://github.com/jesseduffield/lazydocker/blob/master/docs/keybindings/Keybindings_en.md
[6]: jesseduffield/lazydocker#117
[7]: https://www.nordtheme.com
[8]: https://pkg.go.dev/github.com/jesseduffield/lazydocker/pkg/config

GH-283

Co-authored-by: Sven Greb <[email protected]>
arcticicestudio added a commit to arcticicestudio/igloo that referenced this pull request Jun 22, 2020
Created a new snowblock for lazydocker [1].
> The lazier way to manage everything Docker.
> A simple terminal UI for both Docker and docker-compose.

I've used it for quite some time and the configurations have now been
tested enough on a day-by-day basis to be persisted in igloo.

Initially this includes the `config.yml` file [2] symlinked to the
corresponding XDG specific [3] and OS dependent path(s) [4].
The keybindings [5] are can not be customized yet, but some initial work
has been done [6] so maybe it'll be possible in later versions.
The colors have been adjusted to match the Nord [7] theme style.

For more details about available configurations see the
`github.com/jesseduffield/lazydocker/pkg/config` package documentation
[8].

[1]: https://github.com/jesseduffield/lazydocker
[2]: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md
[3]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
[4]: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md#locations
[5]: https://github.com/jesseduffield/lazydocker/blob/master/docs/keybindings/Keybindings_en.md
[6]: jesseduffield/lazydocker#117
[7]: https://www.nordtheme.com
[8]: https://pkg.go.dev/github.com/jesseduffield/lazydocker/pkg/config

Resolves GH-283

Co-authored-by: Sven Greb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable keybindings
4 participants