-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
make minimal completion display more bash-like #2241
Conversation
Here are some screencasts of how the new minimal mode behaves. Line wrapping: https://asciinema.org/a/0kltGyy5yse6oYavHwRkite2y Packed match printing and search: https://asciinema.org/a/iWcwC8m0XOa7lpnB2sRtKmzCy |
This commit changes the display style of the minimal completion display. Instead of only printing a subset of matches in a single column and saying that there are more, we now just print them all in the packed format. This behavior will be more similar to what bash users are familiar with and just generally more useful.
1e490f5
to
10ae484
Compare
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.
OK great, I looked at the code
Let me try out the behavior a bit
core/comp_ui.py
Outdated
def _RedrawPrompt(self): | ||
# type: () -> None | ||
# NOTE: This has to reprint the prompt and the command line! | ||
# Like bash, we SAVE the prompt and print it, rather than re-evaluating it. | ||
self.f.write(self.prompt_state.last_prompt_str) | ||
self.f.write(self.comp_state.line_until_tab) | ||
|
||
def _GetTerminalWidth(self): |
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 we can move this _GetTerminalWidth method up to the base class _IDisplay?
core/comp_ui.py
Outdated
# This shouldn't raise IOError because we did it at startup! Under | ||
# rare circumstances stdin can change, e.g. if you do exec <& | ||
# input.txt. So we have a fallback. | ||
self.term_width = 80 |
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.
We can change this 80 to DEFAULT_TERMINAL_WIDTH I guess
core/shell.py
Outdated
try: | ||
term_width = libc.get_terminal_width() | ||
except (IOError, OSError): # stdin not a terminal | ||
pass |
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 we should set term_width to DEFAULT_TERM_WIDTH here, for BOTH 'nice' and 'minimal'
Then the logic below will be cleaner
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.
We can also get rid of term_width = 0
then, since it will be initialized in both cases
core/shell.py
Outdated
@@ -1106,7 +1111,8 @@ def Main( | |||
|
|||
else: # Without readline module | |||
display = comp_ui.MinimalDisplay(comp_ui_state, prompt_state, | |||
debug_f) | |||
debug_f, DEFAULT_TERM_WIDTH, |
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.
without GNU readline, I think we can still use the real term width?
I tried it out -- the main thing is if I hit TAB with nothing on the prompt, it writes over the entire screen in an undesirable way, with thousands of candidates for the first word / executable Can we set max_lines to maybe 5 or 8 ? That could be overridden with some user setting, but I think the "out of the box" / "zero config" experience should be at least decent I don't like the bash behavior of "show 1888 possibilities?" |
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, looks good!
@@ -340,6 +354,10 @@ def __init__( | |||
# hash of matches -> count. Has exactly ONE entry at a time. | |||
self.dupes = {} # type: Dict[int, int] | |||
|
|||
def ReadlineInitCommands(self): | |||
# type: () -> List[str] | |||
return ['set horizontal-scroll-mode on'] |
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.
Please add a comment with this link, so we remember what it's for!
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.
Nice catch! Added a comment
core/comp_ui.py
Outdated
self.comp_state = comp_state | ||
self.prompt_state = prompt_state | ||
self.num_lines_cap = num_lines_cap | ||
self.f = f | ||
self.debug_f = debug_f | ||
self.term_width = DEFAULT_TERM_WIDTH |
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 we should have a free function _GetTermWidth()
that does the try/except, and that will be called in __init__
here
And then we will have a method self._MaybeGetTermWidth()
that does the SIGWINCH thing
that will have a bit less duplication with DEFAULT_TERM_WIDTH
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.
Good idea. Pulled that logic out of the method. I left the method name alone, though. "Maybe" suggests that it might fail or something and return None/-1, which I thought was more confusing than the name collision (the "self." disambiguates this enough IMO)
Thanks, code looks good I was about to merge and then I saw this failure! http://mb.oilshell.org/uuu/github-jobs/9044/ That's a little scary, but I think it is a mycpp bug. I think we need a different name for the method and function? Because in C++ you can call a method like I am not sure that is the cause but I think so ... we are doing a naive syntactic translation Also I was wondering if it is weird to call a function in the constructor, in
|
Oh weird... Pushed a fix to rename the method |
Also, it should be safe to call |
Huh. Looks like the translation bug is fixed, but there's still this other failure in
https://mb.oilshell.org/uuu/github-jobs/9045/cpp-spec.wwz/_tmp/soil/logs/osh-all.txt |
I think the error might be because some of the members aren't initialized yet or something ... ASAN is catching it But in any case we are lucky that it caught it It looks like this test is failing in Python only, not sure why: http://mb.oilshell.org/uuu/github-jobs/9045/cpp-spec.wwz/_tmp/spec/osh-cpp/builtin-trap.html hmmmm |
Hm I restarted the job, and it passed ... that is annoying, I haven't seen this flaky test before Anyway it's merged now - thanks! |
There are three commits here. One makes it so only the nice completion display sets
horizontal-scroll-mode
. This should help with #2081. The other changes the display style of the minimal completion display. Instead of only printing a subset of matches in a single column and saying that there are more, we now just print them all in the packed format. This behavior will be more similar to what bash users are familiar with and just generally more useful. The last change makes the minimal completion display the default. This should minimize friction for newcomers.