-
Notifications
You must be signed in to change notification settings - Fork 60
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
Enhanced /help command #340
Conversation
Entering /help will now spawn a new "dummy" tab that shows all the possible commands, along with all the currently configured key bindings. Closes osa1#287
Looking for some feedback/suggestions here. |
Here is how the "help" tab currently looks with this patch. You can scroll up and down and /close it. My test config has some duplicate actions. I think this might look better if the action is listed once with the keys separated by commas, but I didn't get around to doing that yet.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's identical. I will update that line, thanks for catching it |
I thought I sent this comment but apparently I didn't.. This looks great but one problem I had is it switches to the help tab, which is fine, but when I close the tab I'm not back in the tab I was before @trevarj WDYT? |
@osa1 seems like that's a general feature of the tui. I can store |
Yeah I think storing the previous tab and switching to it when closing a tab would fix the issue. I'm trying to think if it would be useful in any other case. I just tried this in Firefox and it seems to use a similar idea. If I move left and close the tab the tab on the right is selected. If I move right and close the tab the tab on the left is selected. However, if I jump to a specific tab with |
@osa1 I think it should probably just get logged as another issue since we will need to decide if:
Any way seems easy to implement |
@trevarj another idea:
This seems to solve the problem of losing current tab after |
This way it gets added next to the tab that you are currently on.
@osa1 I made "help" a chan tab instead of a "serv" tab so that it opens next to the current tab you're on. |
It doesn't seem to work correctly. If I do Also, I'm not sure if creating as a channel tab a good idea. I can't move it past groups, as mentioned in my comment above. I wonder if we should make |
Added a new "Misc" tab type that will genericize "mentions" and "help" tab, and what ever else we want to add. This type of tab gets created to the right of the current tab and came move freely around all tabs. Moving a server tab captures a misc tab in its group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @trevarj , this looks great now. I'll make another pass hopefully later today 😅
Removed "errors" misc tab
@osa1 ok, I think we're really close!! hopefully this is the last commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the names show_mentions_tab
and show_help_tab
a bit confusing. To me the name "show..." suggests showing something that already exists, but they also create the tab if they don't exist.
I suggest renaming them to "add_help_tab" or "create_help_tab", and then if we do the switching in the command implementation we don't have to explain (document) to the user that "add_help_tab" will also switch to the tab.
Re: switching to the help tab. I suggest not switching to a misc tab in the tab creating functions, as in general we may not want to switch to a misc tab on creation always (e.g. I think for "errors" tab it's fine to just highlight it with bold red, no need to switch to it). It's specific to the tab.
So I'd completely separate tab creating and switching logic and do switching in command implementation.
@@ -152,6 +153,10 @@ impl KeyMap { | |||
pub(crate) fn load(&mut self, key_map: &KeyMap) { | |||
self.0.extend(key_map.0.iter()) | |||
} | |||
|
|||
pub(crate) fn iter(&self) -> Iter<Key, KeyAction> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter too much for this code, but you could return impl Iterator<Item = (&Key, &KeyAction)>
to avoid referring to the concrete type and leaking details of the type to users.
An example of where this matters: map type is coming from a third-part and users are not part of the project. In that case user crates will have to depend on the map crate.
Since libtiny_tui is only used by tiny and this is std map it's OK in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't think of that. Will keep it in mind when/if I'm creating public crates
crates/libtiny_tui/src/tui.rs
Outdated
@@ -626,6 +643,55 @@ impl TUI { | |||
tab.set_cursor(cursor); | |||
} | |||
|
|||
/// Shows "mentions" tab at the beginning of the tab list | |||
pub(crate) fn show_mentions_tab(&mut self) -> Option<usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you document the return value please? It's a bit unexpected. AFAIU it returns the index if a tab is created. Otherwise returns None
. I'm guessing the index is needed to switch to the tab, but I don't know why we want to switch to the tab only if it's just created but not if it already exists but we add a new message. I think in both cases we either want to switch or we don't, so the return value should be usize
. Am I missing anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is mainly because we can now /close the mentions tab and it can be recreated in maybe_create_tab
when you are mentioned...Now that I think about it, it might just be better to not allow /close for the mentions tab. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried and I cannot close mentions tab in this branch. It seems like it's accidentally working?
I think it makes sense to not allow closing mentions tab because we rely on having at least one tab available in a few places, and changing all those places will require more design (for example, how to enter commands after closing all tabs) and implementation work.
crates/libtiny_tui/src/tui.rs
Outdated
Some(tab_idx) | ||
} | ||
Some(idx) => { | ||
self.select_tab(idx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very confusing. Switching to the help tab happens in two entirely different places.
- Here when tab already exists
- In
show_help_tab
when tab doesn't already exist
Need to refactor this somehow. I have a suggestion in my top-level comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the automatic selection fully. Instead, I made the help tab highlight on creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? If I run /help
I want to see help right now, without any more effort. Why run /help
if you don't want to see it?
Why not switch to the tab in command implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
- Don't select Misc tab automatically - Don't allow closing mentions tab - Added doc comments - Cleanups
- Automatic switching to help tab on /help
@@ -159,6 +158,9 @@ fn close(args: CmdArgs) { | |||
MsgSource::User { serv, nick } => { | |||
ui.close_user_tab(&serv, &nick); | |||
} | |||
// Don't allow closing the mentions tab |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trevarj you disallowed closing mentions tab here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you ok with being able to close it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, see my previous comment.
crates/tiny/src/cmd.rs
Outdated
"/names only supported in chan tabs", | ||
&MsgTarget::CurrentTab, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff should be much smaller if you implement this in the style of previous version:
let serv_name = match src.serv_name() {
None => return,
Some(serv_name) => serv_name,
};
Then the lines starting after let client = ...
should not change at all.
crates/tiny/src/cmd.rs
Outdated
}) | ||
.collect::<Vec<_>>(); | ||
ui.create_help_tab(&msgs); | ||
ui.switch(MiscTab::Help.display()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may break if we have a tab for a user with nick "help".
I suggest changing this a little bit which will avoid problems like having a tab for a user with nick "help" and simplify the design quite a lot.
I know I asked for too many changes already, sorry for that. I think this design will be much better. The key point is handling the help tab is entirely up to the TUI implementation, rest of the program does not need to know about it. We can also easily change how we show help in the future. With this I think only the files in libtiny_tui should change. The PR should not have any other changes. Does this make sense? Why not do the same for the mentions tab? I think maybe we could simplify some of the code by with a similar idea, but what's shown in mentions is decided by tiny (it searches every message for the current nick), so we it needs to know about the tab and manipulate it. |
Switch to tab by source instead of by display name.
Just to clarify my thought process here: showing a "help" dialogue (or a tab in our case) in a UI implementation should happen entirely in the UI implementation, should not effect elsewhere in the program. In our case, updating Looking at me previous message above
I think we could handle |
Perhaps I'm being stubborn (or too tired to take another shot at this), but it might become messy since creating a new tab will require Maybe just keep current functionality (flood current tab with help), and simply the key mappings? 😬 |
There's only 4 uses of
So the idea is most of these functions should just show the error message ("change tab to a server/chan/user") and return.
We shouldn't need to turn
This would be fine too. I don't feel strongly either way. To rephrase, |
I meant that you actually can't create a
|
Thanks @trevarj . If you could submit a PR it will be easier to find. You can create a PR as draft or mark it as draft after creating. |
Entering /help will now spawn a new "dummy" tab that shows all the
possible commands, along with all the currently configured key bindings.
Closes #287