Skip to content

Conversation

@TheRustyPickle
Copy link
Contributor

#63 Added auto-completion support (Linux only) for Bash, Zsh, and Fish shells on Tab press. Gets initialized at the start of the program run

Screenshot from 2023-02-28 04-59-30
Screenshot from 2023-02-28 05-00-06
Screenshot from 2023-02-28 05-00-26

@24seconds 24seconds linked an issue Mar 1, 2023 that may be closed by this pull request
@24seconds 24seconds added the enhancement New feature or request label Mar 1, 2023
@24seconds 24seconds self-requested a review March 1, 2023 00:25
@24seconds
Copy link
Owner

24seconds commented Mar 1, 2023

[Question]
I also want to test the auto completion. But.. I have no idea how to do that.
Could you provide some detail guide so that I can reproduce like the image you attach? @TheRustyPickle

@TheRustyPickle
Copy link
Contributor Author

@24seconds running the app once will add autocompletion for the shell which was used.

Copy link
Owner

@24seconds 24seconds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work! I'm still reading some material related to clap_autocomplete and how autocompletion works for the review.

Here is the in the middle of review results. Please take a look 🙇

reqwest = { version = "0.11", features = ["json"] }
colored = "2"
bincode = { version = "2.0.0-rc.1", features = ["alloc"]}
clap_complete = "3.2.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question]
Currently clap_complete's latest version is 4.1.4. (doc link) Is there a reason to use the version 3.2.2? Maybe rust-cli-pomodoro's clap version is 3.2.22 ?

Copy link
Contributor Author

@TheRustyPickle TheRustyPickle Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it's related to the clap's version. If I use the latest version I get some kind of error with generate which I don't understand. Something to do with the clap's main command generation

@24seconds
Copy link
Owner

Thank you for handling the comment and leave comments. I didn't check the comment yet..
This week I'm quite busy. I will take a look on Friday night or Saturday after noon (KST). @TheRustyPickle

Copy link
Owner

@24seconds 24seconds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still understanding the auto completion.. 🙇 . I left some comments.

}

/// Adds auto completion for the shell that is being used
pub fn add_autocomplete() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion]
For the better error message, how about define custom error for auto completion?
rust-cli-pomodoro defines many custom errors in error.rs file.

Link:

use bincode::error::{DecodeError, EncodeError};


/// Returns the current shell
fn get_current_shell() -> Result<Shell, Box<dyn std::error::Error>> {
if cfg!(target_os = "linux") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question]
Is there a reason to target only linux? How about mac or window?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a mac or windows. I don't know if the process would be the same over there.

@24seconds
Copy link
Owner

24seconds commented Mar 5, 2023

How completion works

So far I looked up the tab completion or autocompletion. And how completion works can be summarized below.

Suggestion

I found good example of completion. It's rustup. rustup supoprts completion command. You can run rustup completions --help and see the contents. Or check the installation doc link - https://github.com/rust-lang/rustup/blob/affbdfe0a37d92444e7c3c111043cd336e2f7728/doc/src/installation/index.md?plain=1#L68.

In this PR, the code tries to do two things.

  • create completion script
  • move completion script to proper path

I think we should approach similar to rustup. Let completion be optional. By doing this, user can choose whether installing the completion script or not. rust-cli-pomodoro only provides completion script generation command like rustup. And with the ease of adoption, we can write kind guidance.
Another good example of guidance is nvm I guess. It provides code snippet for shell profile file - link: https://github.com/nvm-sh/nvm/blob/edacf8275e3bef4a80971625ed89df13a9af427c/README.md?plain=1#L240.

To sum up, I suggest

  • provide completions command very similar to rustup
  • write guidance - (I'm not sure which guidance is preferred way - rustup or nvm?)

What do you think? @TheRustyPickle

@TheRustyPickle
Copy link
Contributor Author

Sounds good @24seconds. I liked the rustup's approach better and I think is easier to understand. If I understood you right, the new approach will have a command like this instead of detecting the shell manually:

pomodoro completions fish > path

where generate will return a stdout, reducing most of the complexity. If I have the green light I can try working on this.

@24seconds
Copy link
Owner

You are right. Thank you @TheRustyPickle !

@TheRustyPickle
Copy link
Contributor Author

TheRustyPickle commented Mar 5, 2023

Thank you @24seconds! I'm not very familiar with clap yet but will try to commit the new changes as soon as I am able.

@TheRustyPickle
Copy link
Contributor Author

TheRustyPickle commented Mar 6, 2023

Hello @24seconds, correct me here if I am wrong here.

If I don't enter the pomodoro cli interface by typing pomodoro or cargo run and try to pass args like this pomodoro create -d, it tries to connect to/create UDS.

If we want to use pomodoro completions fish > path or how it was done in rustup and use the stdout, it needs to be done without entering the pomodoro cli interface.

I'm not sure if it was expected or whether this side is incomplete, I'm getting this error:

Error: Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }

Alternatively, I was able to achieve this

  • Get shell name via the cli interface pomodoro completions <shell>
  • Create and move the autocomplete script to the relevant place

or

  • Take a path via pomodoro completions <shell> <path>
  • Create the file at the given path

Kindly advise on how to proceed here. I'm quite confused and not sure how things are working on the UDS side and if the error is exclusive to my device. Thank you for your time.

@24seconds
Copy link
Owner

24seconds commented Mar 6, 2023

I understand the situation.

Ah.. rust-cli-pomodoro architecture is quite unusual. There are two modes.
For more information, check this section -

## Architecture

  1. Single mode: Run rust-cli-pomodoro by typing the pomodoro command. Then the app is running in terminal and you can type some commands in that terminal.
  2. Communication mode: I found that it's burdensome for me - whenever I type, I need to go to that terminal. Usually I opened multiple terminal tabs. That is why ipc is used. If we type command in another terminal, then the already running rust-cli-pomodoro listens and serves command. (It works like client-server)

Therefore, to determine which mode it is, we have a function named detect_command_type.
Link:

async fn detect_command_type() -> Result<CommandType, ConfigurationError> {

Currently there are two command type - StarUP and UdsClient. Now I guess it's time to add one more command type - completion ? autocomplete? something like this (please suggest command naming).

Suggestion

  • refactor detect_command_type so that we can distinguish which command type it is. Currently detect_comamnd_type naively determines command type
  • Write some logic in main.rs depending on detect_command_type result.

Then you can achieve what you wanted I guess. Please ask question @TheRustyPickle if something is unclear 🙇

@TheRustyPickle
Copy link
Contributor Author

Thank you for the kind explanation, @24seconds! It is much clearer for me and I have some ideas on what to work on now🙏

@TheRustyPickle
Copy link
Contributor Author

TheRustyPickle commented Mar 6, 2023

@24seconds when you have the time, please take a look at the new changes and let me know your thoughts. Thank you!

You should be able to do this and it does not make use of the UDS client

pomodoro completion fish > pomodoro.fish.

Copy link
Owner

@24seconds 24seconds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!! Super!

Thank you for the patient and long long communication. Because of you, I can understand this feature and rust-cli-pomodoro now has tab completion!

I will update version soon. Again, thank you!

@24seconds
Copy link
Owner

image

Confirm that it works well in zsh, macOS

@24seconds 24seconds merged commit 7227d36 into 24seconds:main Mar 7, 2023
@24seconds
Copy link
Owner

[next step]
For the general usage, maybe rust-cli-pomodoro needs guidance like rustup. Let me work on it if I'm available.

@TheRustyPickle
Copy link
Contributor Author

Thank you so much for being so helpful and patient throughout the process, @24seconds! 🙏

@TheRustyPickle TheRustyPickle deleted the shell_autocomplete branch March 7, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: command auto complete

2 participants