Skip to content

Commit

Permalink
[builtins/read] Implement basic version of read -p
Browse files Browse the repository at this point in the history
We're not handling 'read -e -p' yet, which involves GNU readline

Addresses issue #788
  • Loading branch information
Andy Chu committed Jul 22, 2020
1 parent 655fea5 commit aa3dccf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/flag_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
READ_SPEC.ShortFlag('-n', args.Int)
READ_SPEC.ShortFlag('-a', args.String) # name of array to read into
READ_SPEC.ShortFlag('-d', args.String)
READ_SPEC.ShortFlag('-p', args.String) # prompt


MAPFILE_SPEC = FlagSpec('mapfile')
Expand Down
3 changes: 3 additions & 0 deletions osh/builtin_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def Run(self, cmd_val):
if arg.s: # silent
bits |= pyos.TERM_ECHO

if arg.p is not None: # only if tty
mylib.Stderr().write(arg.p)

if bits == 0:
status = self._Read(arg, names)
else:
Expand Down
15 changes: 15 additions & 0 deletions spec/builtin-io.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,21 @@ fooba
## END
## N-I dash/zsh/ash stdout-json: ""

#### read -p (not fully tested)

# hm DISABLED if we're not going to the terminal
# so we're only testing that it accepts the flag here

case $SH in (dash|mksh|zsh) exit ;; esac

echo hi | { read -p 'P'; echo $REPLY; }
echo hi | { read -p 'P' -n 1; echo $REPLY; }
## STDOUT:
hi
h
## END
## stderr-json: ""
## N-I dash/mksh/zsh stdout-json: ""

#### read usage
read -n -1
Expand Down

0 comments on commit aa3dccf

Please sign in to comment.