Skip to content

Commit

Permalink
Merge branch 'master' into dev/andy-14
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jul 7, 2019
2 parents ce31115 + c864743 commit cc20fb4
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 9 deletions.
3 changes: 0 additions & 3 deletions Python-2.7.13/pyconfig.h
Expand Up @@ -259,9 +259,6 @@
/* Define to 1 if you have the `ftello' function. */
#define HAVE_FTELLO 1

/* Define to 1 if you have the `ftime' function. */
#define HAVE_FTIME 1

/* Define to 1 if you have the `ftruncate' function. */
#define HAVE_FTRUNCATE 1

Expand Down
3 changes: 2 additions & 1 deletion build/cpython_defs.py
Expand Up @@ -305,8 +305,9 @@ def __call__(self, rel_path, def_name, method_name):

# Auto-filtering gave false-positives here.
# We don't need top-level next(). The method should be good enough.
# iter is a field name
if (basename == 'bltinmodule.c' and
method_name in ('compile', 'format', 'next', 'vars')):
method_name in ('compile', 'format', 'next', 'vars', 'iter')):
return False
if basename == 'bltinmodule.c':
# Get "bootstrapping error" without this.
Expand Down
1 change: 1 addition & 0 deletions build/oil-defs/native/libc.c/methods.def
Expand Up @@ -9,5 +9,6 @@ static PyMethodDef methods[] = {
{"print_time", func_print_time, METH_VARARGS},
{"gethostname", socket_gethostname, METH_NOARGS},
{"get_terminal_width", func_get_terminal_width, METH_NOARGS},
{"wcswidth", func_wcswidth, METH_VARARGS},
{0},
};
9 changes: 7 additions & 2 deletions core/comp_ui.py
Expand Up @@ -32,7 +32,8 @@
def _PromptLen(prompt_str):
"""Ignore all characters between \x01 and \x02 and handle unicode characters.
In particular, the display width of a string may be different from either the
number of bytes or the number of unicode characters."""
number of bytes or the number of unicode characters.
Additionally, if there are multiple lines in the prompt, only give the length of the last line."""
escaped = False
display_str = ""
for c in prompt_str:
Expand All @@ -42,11 +43,15 @@ def _PromptLen(prompt_str):
escaped = False
elif not escaped:
display_str += c
last_line = display_str.split('\n')[-1]
try:
return libc.wcswidth(display_str)
width = libc.wcswidth(last_line)
# en_US.UTF-8 locale missing, just return the number of bytes
except (SystemError, UnicodeError):
return len(display_str)
if width == -1:
return len(display_str)
return width


class PromptState(object):
Expand Down
8 changes: 8 additions & 0 deletions core/comp_ui_test.py
Expand Up @@ -165,6 +165,14 @@ def testValidEscapes(self):
comp_ui._PromptLen("\x01\x02 hi \x01hi\x02 \x01\x02 hello"),
len(" hi hello"))

def testNewline(self):
self.assertEqual(comp_ui._PromptLen("\n"), 0)
self.assertEqual(comp_ui._PromptLen("abc\ndef"), 3)
self.assertEqual(comp_ui._PromptLen(""), 0)

def testControlCharacters(self):
self.assertEqual(comp_ui._PromptLen("\xef"), 1)
self.assertEqual(comp_ui._PromptLen("\x03\x05"), 2)

if __name__ == '__main__':
unittest.main()
16 changes: 16 additions & 0 deletions core/property_tests.py
@@ -0,0 +1,16 @@
#!/usr/bin/env python2

import unittest

from hypothesis import given
from hypothesis.strategies import text

from comp_ui import _PromptLen

class PromptTest(unittest.TestCase):
@given(text())
def testNeverPanics(self, s):
self.assertIs(_PromptLen(s) >= 0, True)

if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions native/libc_test.py
Expand Up @@ -193,6 +193,7 @@ def testGetTerminalWidth(self):
def testWcsWidth(self):
self.assertEqual(1, libc.wcswidth("▶️"))
self.assertEqual(28, libc.wcswidth("(osh) ~/.../unchanged/oil ▶️ "))
self.assertEqual(2, libc.wcswidth("→ "))
self.assertRaises(UnicodeError, libc.wcswidth, "\xfe")

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion osh/word.py
Expand Up @@ -155,7 +155,7 @@ def LeftMostSpanForPart(part):
return part.spids[0]

elif isinstance(part, word_part__TildeSubPart):
return const.NO_INTEGER
return part.token.span_id

elif isinstance(part, word_part__ArithSubPart):
# begin, end
Expand Down
3 changes: 1 addition & 2 deletions test/lint.sh
Expand Up @@ -90,8 +90,7 @@ bin-flake8() {
if test -f "$ubuntu_flake8"; then
$ubuntu_flake8 "$@"
else
# Assume it's in $PATH, like on Travis.
flake8 "$@"
python2 -m flake8 "$@"
fi
}

Expand Down
3 changes: 3 additions & 0 deletions vendor/typing.py
Expand Up @@ -10,6 +10,9 @@
# if TYPE_CHECKING:
# NullFunc = Callable[[int, int], int]

TypingMeta = None
TypeVar = None
_ForwardRef = None
List = None
Tuple = None
Optional = None
Expand Down

0 comments on commit cc20fb4

Please sign in to comment.