Skip to content

Key aliasing, or perhaps just a few more sensible defaults. #8

Open
@collidedscope

Description

Hello, Fancyliners! Thanks for bringing such a great library into the world.

I recently incorporated history into my toy language's REPL (made an absolute breeze by Fancyline, of course), but was dismayed to discover that Ctrl+P and Ctrl+N couldn't be used to seek up and down, respectively. These particular keybinds are a staple in many line editors, and I'm long past the point of shaking them out of muscle memory. I briefly considered hard-coding them in the history widget's handler, but of course that wouldn't do.

Thankfully, and as a testament to the library's excellent design, I found it fairly straightforward to enable the old habits:

include Fancyline::Key

fancy = Fancyline.new
history_widget = Fancyline::Widget::History.new

fancy.actions.set Control::CtrlP do |ctx|
  if history_widget.@history
    history_widget.show_entry ctx, -1
  else
    ctx.start_widget history_widget
  end
end

fancy.actions.set Control::CtrlN do |ctx|
  if history_widget.@history
    history_widget.show_entry ctx, +1
  else
    # Do nothing.
  end
end

This works and I'm content with it, but I was thinking it'd be pretty nice if instead one could simply say something like the following:

fancy.actions.alias Control::CtrlP, Control::Up
fancy.actions.alias Control::CtrlN, Control::Down

A mere @mapping[to] = @mapping[from] goes a surprisingly long way, but this aliasing wouldn't get picked up in widgets, where the action keys are hard-coded at the moment. I appreciate the disinclination to make Fancyline too configurable, but the structure is all there to make this creature comfort possible, insofar as ctx.fancyline.actions.mapping should suffice for getting hold of any aliases from within a Widget.

Would you be interested in having this functionality in the library? As long as it's limited to just global aliases (as opposed to something crazy like per-context), it seems to me that it wouldn't come with too much mess.

Thanks again for this excellent utility! Looking forward to your thoughts.

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions