getc function in fish? #1616

Closed
tannhuber opened this Issue Aug 18, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@tannhuber
Contributor

tannhuber commented Aug 18, 2014

Is it possible to write a getc function as shown in the following link for bash?
http://osr507doc.sco.com/en/OSUserG/_How_to_get_a_character.html
If yes, how?

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Aug 18, 2014

Very easily; stty and dd are commands, not builtins. However, you should note that this is rather inefficient because it forks the shell twice, and I think that it'd be better if maybe read could be configured to only accept one character.

ghost commented Aug 18, 2014

Very easily; stty and dd are commands, not builtins. However, you should note that this is rather inefficient because it forks the shell twice, and I think that it'd be better if maybe read could be configured to only accept one character.

@tannhuber

This comment has been minimized.

Show comment
Hide comment
@tannhuber

tannhuber Aug 19, 2014

Contributor

@Undeterminant Thank you for the answer. However, I think it's not that easy. The set command fires dd into the background:

set tmp (dd bs=1 count=1 ^/dev/null)

doesn't wait for user input. It doesn't matter whether it's raw or cooked mode.

I agree with you that a builtin option for read would be the best solution. At the moment it seems not to be possible at all.

Contributor

tannhuber commented Aug 19, 2014

@Undeterminant Thank you for the answer. However, I think it's not that easy. The set command fires dd into the background:

set tmp (dd bs=1 count=1 ^/dev/null)

doesn't wait for user input. It doesn't matter whether it's raw or cooked mode.

I agree with you that a builtin option for read would be the best solution. At the moment it seems not to be possible at all.

@tannhuber

This comment has been minimized.

Show comment
Hide comment
@tannhuber

tannhuber Aug 19, 2014

Contributor

In bash, there's a -n option (-k in zsh):

-n nchars
                     read  returns  after  reading  nchars  characters rather than waiting for a complete line of
                     input, but honor a delimiter if fewer than nchars characters are read before the delimiter.

Anything like that would be nice for fish as well.

Contributor

tannhuber commented Aug 19, 2014

In bash, there's a -n option (-k in zsh):

-n nchars
                     read  returns  after  reading  nchars  characters rather than waiting for a complete line of
                     input, but honor a delimiter if fewer than nchars characters are read before the delimiter.

Anything like that would be nice for fish as well.

@zanchey zanchey added the enhancement label Sep 15, 2014

@zanchey zanchey added this to the next-minor milestone Sep 15, 2014

@zanchey

This comment has been minimized.

Show comment
Hide comment
@zanchey

zanchey Sep 15, 2014

Member

Closed through #1618!

Member

zanchey commented Sep 15, 2014

Closed through #1618!

@zanchey zanchey closed this Sep 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment