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

Allow user defined key bindings (refactor replxx_impl.cxx). #6

Closed
ajg opened this issue Feb 17, 2018 · 11 comments
Closed

Allow user defined key bindings (refactor replxx_impl.cxx). #6

ajg opened this issue Feb 17, 2018 · 11 comments

Comments

@ajg
Copy link
Contributor

ajg commented Feb 17, 2018

It'd be nice to have the option to auto-complete a line/command with the first available hint when pressing enter/return, rather than have to do it explicitly by tabbing. This would allow emulating the code completion behavior of typical IDEs (and search engine input boxes.)

It doesn't look like this is currently possible, or is it?

Thanks.

@AmokHuginnsson
Copy link
Owner

Hello.
I think that could be a nice feature if optional. There is one thing I would like to do before such feature would be implemented. Currently all "function" keys are handled in one big switch, This code looks awful. I was thinking about splitting this switch into separate functions, one per case and do dispatching through (runtime) registered handlers rather then through switch, the implementation is C++11 after all. That way we would have cleaner code and ability to support custom (user defined) keybindings.

What do you think?

@ajg
Copy link
Contributor Author

ajg commented Feb 18, 2018

That sounds reasonable to me—let me know if I can help.

@AmokHuginnsson
Copy link
Owner

I have been busy with other things, but I had time to think about the best approach. It seems to me that dynamic key binding implementation would add more global static state and we would add new mess in one place while we would clean up the other. @georgi-d has opened another issue (#2) for this and it looks like to do it right we would have to start with global state removal. I see that this project gets cloned so my resistance to adding code smells gets stronger. I do not know if there is any feasible way to split the work but I am open to suggestion. Anyway I will look into #2 for now.

@yury
Copy link
Contributor

yury commented May 13, 2018

@ajg hmm, it is interesting, I can't tab to cycle completion list. It is just shown above. But actually I need tabbing through behavior. I think something changed recently.

@AmokHuginnsson
Copy link
Owner

@yury To access next/prev hist one has to use CTRL+<up arrow>/CTRL+<down arrow>.
When desired hint is selected one use <TAB> key to complete given selection.

@yury
Copy link
Contributor

yury commented May 13, 2018

Yep, found that shortcut in code. But on iOS kb it is very unconvineient shortcut ;(

Zsh style tabbing would awesome.

@AmokHuginnsson AmokHuginnsson changed the title Option to auto-complete first hint on enter/return Allow user defined key bindings. Sep 25, 2018
@AmokHuginnsson AmokHuginnsson changed the title Allow user defined key bindings. Allow user defined key bindings (refactor inputbuffer.cxx). Sep 25, 2018
@AmokHuginnsson AmokHuginnsson changed the title Allow user defined key bindings (refactor inputbuffer.cxx). Allow user defined key bindings (refactor replxx_impl.cxx). Dec 11, 2018
@AmokHuginnsson AmokHuginnsson pinned this issue Feb 1, 2019
@AmokHuginnsson
Copy link
Owner

@ajg

I finally started key binding rewrite. But now I am afraid that custom key bindings are not actually related to your original problem. At least I am not entirely sure what API to expose to the client application so the user can request/implement the behavior you are after.

I think new issue should be opened for "Enter to accept current hint" enhancement because I already referenced this issue (#6) as top priority refactoring in many places.

I am sorry that I hijacked your enhancement request.

@AmokHuginnsson
Copy link
Owner

@yury

I think it would be best if you open new issue for "Cycling through hints with Tab key.".
That way your request won't be lost, as this issue is about something entirely else now :(

@AmokHuginnsson AmokHuginnsson self-assigned this Mar 17, 2019
@AmokHuginnsson
Copy link
Owner

AmokHuginnsson commented Jun 2, 2019

@ajg

Can you explain more what do you mean in the original issue?
I understand that you want to use Enter key to accept current hint.
What about automatic hint selection?
You referenced IDEs, some of the IDEs have first hint "selected" by default, e.g.:

In IDE (C++ code):

std::string s;
s.

here, after user enters . the first hint is append() method,
pressing Enter inserts append(...) into the editor.

Would you like to have the same behavior in replxx,
I mean, to have first available hint selected by default and used when user presses Enter key?

@AmokHuginnsson
Copy link
Owner

@yury

You can now achieve tab cycle completion through binding
Replxx::ACTION::COMPLETE_NEXT to <tab> key via Replxx::bind_key() and Replxx::invoke()

@yury
Copy link
Contributor

yury commented Aug 19, 2019

Thanks, man.

I did heavy changes. Can check right away. But, I hope, will check that.
Thanks

@AmokHuginnsson AmokHuginnsson unpinned this issue Sep 22, 2019
amosbird pushed a commit to amosbird/replxx that referenced this issue Dec 11, 2020
…-custom-colors

Support for intense and custom colors
GerHobbelt pushed a commit to GerHobbelt/replxx that referenced this issue Sep 14, 2022
You may get uncaugh exception (in case of i.e. broken pipe):

    terminating with uncaught exception of type std::runtime_error: write failed

On destroy:

    (lldb) target create "clickhouse-22.8-release" --core "core.clickhouse-clie.402986-642410"
    bt
    Core file '/wrk/core.clickhouse-clie.402986-642410' (x86_64) was loaded.
    (lldb) bt
    * thread AmokHuginnsson#1, name = 'clickhouse-clie', stop reason = signal SIGABRT
      * frame #0: 0x00007f03fb5c900b libc.so.6`raise + 203
        frame AmokHuginnsson#1: 0x00007f03fb5a8859 libc.so.6`abort + 299
        frame AmokHuginnsson#2: 0x000000001b703f44 clickhouse-22.8-release`::abort_message(format=<unavailable>) at abort_message.cpp:78:5
        frame AmokHuginnsson#3: 0x000000001b703dd4 clickhouse-22.8-release`demangling_terminate_handler() at cxa_default_handlers.cpp:67:21
        frame AmokHuginnsson#4: 0x000000001b721063 clickhouse-22.8-release`std::__terminate(func=<unavailable>)()) at cxa_handlers.cpp:59:9
        frame AmokHuginnsson#5: 0x000000001b720fce clickhouse-22.8-release`std::terminate() at cxa_handlers.cpp:88:17
        frame AmokHuginnsson#6: 0x000000000a3b21db clickhouse-22.8-release`__clang_call_terminate + 11
        frame AmokHuginnsson#7: 0x00000000189b1bfc clickhouse-22.8-release`replxx::Replxx::ReplxxImpl::~ReplxxImpl(this=0x00007f03fa945308) at replxx_impl.cxx:336:1
        frame AmokHuginnsson#8: 0x00000000189b1ce9 clickhouse-22.8-release`replxx::Replxx::ReplxxImpl::~ReplxxImpl(this=0x00007f03fa945300) at replxx_impl.cxx:334:41
        frame AmokHuginnsson#9: 0x00000000188b0644 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader() [inlined] std::__1::unique_ptr<replxx::Replxx::ReplxxImpl, void (*)(replxx::Replxx::ReplxxImpl*)>::reset(this=<unavailable>, __p=<unavailable>) at unique_ptr.h:315:7
        frame AmokHuginnsson#10: 0x00000000188b0626 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader() [inlined] std::__1::unique_ptr<replxx::Replxx::ReplxxImpl, void (*)(replxx::Replxx::ReplxxImpl*)>::~unique_ptr(this=<unavailable>) at unique_ptr.h:269
        frame AmokHuginnsson#11: 0x00000000188b0626 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader() [inlined] replxx::Replxx::~Replxx(this=<unavailable>) at replxx.hxx:76
        frame AmokHuginnsson#12: 0x00000000188b0626 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader(this=0x00007ffd10038440) at ReplxxLineReader.cpp:229
        frame AmokHuginnsson#13: 0x00000000158b2100 clickhouse-22.8-release`DB::ClientBase::runInteractive(this=0x00007ffd10038620) at ClientBase.cpp:2067:1
        frame AmokHuginnsson#14: 0x000000000a4de372 clickhouse-22.8-release`DB::Client::main(this=0x00007ffd10038620, (null)=<unavailable>) at Client.cpp:261:9
        frame AmokHuginnsson#15: 0x0000000018923a86 clickhouse-22.8-release`Poco::Util::Application::run(this=0x00007ffd10038620) at Application.cpp:334:8
        frame AmokHuginnsson#16: 0x000000000a4ed341 clickhouse-22.8-release`mainEntryClickHouseClient(argc=39, argv=0x00007f03fa8201c0) at Client.cpp:1220:23
        frame AmokHuginnsson#17: 0x000000000a3b17ab clickhouse-22.8-release`main(argc_=<unavailable>, argv_=<unavailable>) at main.cpp:449:12
        frame AmokHuginnsson#18: 0x00007f03fb5aa083 libc.so.6`__libc_start_main + 243
        frame AmokHuginnsson#19: 0x000000000a17032e clickhouse-22.8-release`_start + 46
GerHobbelt pushed a commit to GerHobbelt/replxx that referenced this issue Sep 14, 2022
You may get uncaugh exception (in case of i.e. broken pipe):

    terminating with uncaught exception of type std::runtime_error: write failed

On destroy:

    (lldb) target create "clickhouse-22.8-release" --core "core.clickhouse-clie.402986-642410"
    bt
    Core file '/wrk/core.clickhouse-clie.402986-642410' (x86_64) was loaded.
    (lldb) bt
    * thread AmokHuginnsson#1, name = 'clickhouse-clie', stop reason = signal SIGABRT
      * frame #0: 0x00007f03fb5c900b libc.so.6`raise + 203
        frame AmokHuginnsson#1: 0x00007f03fb5a8859 libc.so.6`abort + 299
        frame AmokHuginnsson#2: 0x000000001b703f44 clickhouse-22.8-release`::abort_message(format=<unavailable>) at abort_message.cpp:78:5
        frame AmokHuginnsson#3: 0x000000001b703dd4 clickhouse-22.8-release`demangling_terminate_handler() at cxa_default_handlers.cpp:67:21
        frame AmokHuginnsson#4: 0x000000001b721063 clickhouse-22.8-release`std::__terminate(func=<unavailable>)()) at cxa_handlers.cpp:59:9
        frame AmokHuginnsson#5: 0x000000001b720fce clickhouse-22.8-release`std::terminate() at cxa_handlers.cpp:88:17
        frame AmokHuginnsson#6: 0x000000000a3b21db clickhouse-22.8-release`__clang_call_terminate + 11
        frame AmokHuginnsson#7: 0x00000000189b1bfc clickhouse-22.8-release`replxx::Replxx::ReplxxImpl::~ReplxxImpl(this=0x00007f03fa945308) at replxx_impl.cxx:336:1
        frame AmokHuginnsson#8: 0x00000000189b1ce9 clickhouse-22.8-release`replxx::Replxx::ReplxxImpl::~ReplxxImpl(this=0x00007f03fa945300) at replxx_impl.cxx:334:41
        frame AmokHuginnsson#9: 0x00000000188b0644 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader() [inlined] std::__1::unique_ptr<replxx::Replxx::ReplxxImpl, void (*)(replxx::Replxx::ReplxxImpl*)>::reset(this=<unavailable>, __p=<unavailable>) at unique_ptr.h:315:7
        frame AmokHuginnsson#10: 0x00000000188b0626 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader() [inlined] std::__1::unique_ptr<replxx::Replxx::ReplxxImpl, void (*)(replxx::Replxx::ReplxxImpl*)>::~unique_ptr(this=<unavailable>) at unique_ptr.h:269
        frame AmokHuginnsson#11: 0x00000000188b0626 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader() [inlined] replxx::Replxx::~Replxx(this=<unavailable>) at replxx.hxx:76
        frame AmokHuginnsson#12: 0x00000000188b0626 clickhouse-22.8-release`ReplxxLineReader::~ReplxxLineReader(this=0x00007ffd10038440) at ReplxxLineReader.cpp:229
        frame AmokHuginnsson#13: 0x00000000158b2100 clickhouse-22.8-release`DB::ClientBase::runInteractive(this=0x00007ffd10038620) at ClientBase.cpp:2067:1
        frame AmokHuginnsson#14: 0x000000000a4de372 clickhouse-22.8-release`DB::Client::main(this=0x00007ffd10038620, (null)=<unavailable>) at Client.cpp:261:9
        frame AmokHuginnsson#15: 0x0000000018923a86 clickhouse-22.8-release`Poco::Util::Application::run(this=0x00007ffd10038620) at Application.cpp:334:8
        frame AmokHuginnsson#16: 0x000000000a4ed341 clickhouse-22.8-release`mainEntryClickHouseClient(argc=39, argv=0x00007f03fa8201c0) at Client.cpp:1220:23
        frame AmokHuginnsson#17: 0x000000000a3b17ab clickhouse-22.8-release`main(argc_=<unavailable>, argv_=<unavailable>) at main.cpp:449:12
        frame AmokHuginnsson#18: 0x00007f03fb5aa083 libc.so.6`__libc_start_main + 243
        frame AmokHuginnsson#19: 0x000000000a17032e clickhouse-22.8-release`_start + 46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants