Skip to content

Commit

Permalink
refactor term width getter, leave breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinw committed Feb 2, 2025
1 parent 066da5f commit e5df1c9
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions core/comp_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
DEFAULT_MATCH_LINE_LIMIT = 10


def _GetTerminalWidth():
# type: () -> int
try:
return libc.get_terminal_width()
except (IOError, OSError):
# 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.
return DEFAULT_TERM_WIDTH


def _PromptLen(prompt_str):
# type: (str) -> int
"""Ignore all characters between \x01 and \x02 and handle unicode
Expand Down Expand Up @@ -95,24 +106,13 @@ def __init__(self, comp_state, prompt_state, num_lines_cap, f, debug_f, signal_s
self.num_lines_cap = num_lines_cap
self.f = f
self.debug_f = debug_f
self.term_width = DEFAULT_TERM_WIDTH
try:
self.term_width = libc.get_terminal_width()
except (IOError, OSError): # stdin not a terminal
pass

self.term_width = _GetTerminalWidth()
self.signal_safe = signal_safe

def _GetTerminalWidth(self):
# type: () -> int
if self.signal_safe.PollSigWinch(): # is our value dirty?
try:
self.term_width = libc.get_terminal_width()
except (IOError, OSError):
# 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 = DEFAULT_TERM_WIDTH
self.term_width = _GetTerminalWidth()

return self.term_width

Expand Down Expand Up @@ -356,6 +356,8 @@ def __init__(

def ReadlineInitCommands(self):
# type: () -> List[str]
# NOTE: This setting prevents line-wrapping from clobbering completion
# output. See https://github.com/oils-for-unix/oils/issues/257
return ['set horizontal-scroll-mode on']

def Reset(self):
Expand Down

0 comments on commit e5df1c9

Please # to comment.