ํฐ๋ฏธ๋์์ ctrl-z
๋ฅผ ๋๋ฅด๋ฉด(SIGSTOP ์ ์ก) ์
๋ ฅ ๋ผ์ธ์ โค
๊ฐ ์
๋ ฅ๋ฉ๋๋ค. ์ด์ ์ ๋ฐฉ๋ฒ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง ํ๋ก๊ทธ๋จ์ด ์ค์ง๋๊ณ ์๋ก ๋์๊ฐ์ผ ํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ fg
๋ช
๋ น์ ์ฌ์ฉํ์ฌ ํ๋ก์ธ์ค๋ก ๋์๊ฐ ์ ์์ด์ผ ํฉ๋๋ค.
โฌโ[arne@arne-thinkpad:~/proj/c++/linenoise]โ[18:05:53]
โฐโ>$ ./linenoise_example
hello> foo
echo: 'foo'
hello>
echo: ''
hello>
โฌโ[arne@arne-thinkpad:~/proj/c++/linenoise]โ[18:05:54]
โฐโ>$ python
Python 3.6.1 (default, Mar 27 2017, 00:27:06)
[GCC 6.3.1 20170306] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = 17
'python' has gestoppt
โฌโ[arne@arne-thinkpad:~/proj/c++/linenoise]โ[18:06:07]
โ 1 28968 0% gestoppt python
โฐโ>$ fg
Job 1, 'python' in den Vordergrund schicken
>>> print(foo)
17
ur ํ๋กฌํํธ๋ฅผ 0.0์ฒ๋ผ ๋ณด์ด๊ฒ ๋ง๋๋ ๋ฐฉ๋ฒ
@krux02 ๋๋ ๋น์ ์ด C++๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๋ ๊ฒ์ ์์์ต๋๋ค. @yhirose ์๋ c++๋ก ์ด์๋ linenoise๊ฐ ์์ต๋๋ค: https://github.com/yhirose/cpp-linenoise. ๋ํ UTF8์ด ํ์ฑํ๋ฉ๋๋ค.
linenoise_example ์ฝ๋์ ์์ง๋ฅผ ๊ณต์ ํ ์ ์์ต๋๊น?
์ฌ์ค ์ ๋ C++๋ฅผ ์ฌ์ฉํ์ง ์์ต๋๋ค. ๋๋ ๋ง์ C++๋ฅผ ํ๋ก๊ทธ๋๋ฐํ์ง๋ง ์ง๊ธ์ Nim์ ํ๊ณ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ด ๋ฌธ์ ๊ฐ Nim๊ณผ ๊ด๋ จ๋ ์ด๋ค ๊ฒ์์๋ ๋ฐ์ํ์ง ์์๋์ง ํ์ธํ๊ณ ์ถ์๊ธฐ ๋๋ฌธ์ C++ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์์ต๋๋ค.
๋ด ๊ฒฝํ์ ๋ฐ๋ฅด๋ฉด C API๋ ๊ด์ฐฎ์ต๋๋ค. C++ ๋ฒ์ ์ ํ์ํ์ง ์์ต๋๋ค. ๋ํ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ utf8์ ์ฌ์ฉํ๋ ๋ฐ ์ ํ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค. ๋ด๊ฐ ๋์น ๊ฒ์ ์ด๋ฏธ readline์์ ๋งค์ฐ ์น์ํ ๋ง์ ํค๋ณด๋ ๋ช ๋ น์ ๋๋ค.
๋๋ linenoise์ ๋ํ๋ ๋ฒ์ ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๊ทธ๊ฒ์ด ์ ๋ง๋ก ๋น์ ์๊ฒ ๋ง์ ๊ฐ์น๊ฐ ์๋์ง ํ์ ํ ์ ์์ง๋ง ์ด๊ฒ์ ๋ด๊ฐ ์ฌ์ฉํ๋ ์์ด๋ฉฐ linenoise ์งํฅ์ ์ด์ง ์์ต๋๋ค: https://github.com/krux02/opengl -sandbox/blob/master/examples/console.nim
๊ทธ ํ์ผ์ ์์ด๋์ด๋ Nim์ ๋งคํฌ๋ก ์์คํ ์ ์ฌ์ฉํ์ฌ ๋ช ๋ น ์ธํฐํ๋ฆฌํฐ์์ ์ฌ์ฉํ ์ ์๋ ์์์ ๊ธฐ๋ฅ์ ๋ง๋๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ๋ด๋ถ์ ์ผ๋ก ๋ช ๋ น ์ธํฐํ๋ฆฌํฐ๋ linenoise์ ๋๋ค.
@krux02
๊ธ์์, ์ ๋ ์ ๋ฌธ์ ์ผ๋ก ์ธ์ด์ ๊ตฌ์ ๋ฐ์ง ์์ง๋ง ๊ฐ์ธ์ ์ผ๋ก ์ ๋ C ์๋ฌผ์ ๋๋ค. ํ๋น๋ฌด: ์ ๋ C๋ฅผ ์ฌ๋ํฉ๋๋ค.
Linenoise๋ ๋์์ธ ๋ชฉํ์ธ ๊ตฐ๋๋๊ธฐ ์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ผ๋ ์ฌ์ค์ ๊ธฐ์ตํ์ญ์์ค.
๋ถํํ๋ ์ด๊ฒ์ ์กฐ์ฌํ๊ณ ์ถ์ต๋๋ค. ์ด๋ฒ ์ฃผ๋ง๊น์ง ์๊ฐ์ด ์์ ๊ฒ์ ๋๋ค. ๋๊ตฐ๊ฐ ํด๊ฒฐํด ์ฃผ์ง ์๋ ํ ์ด์ด ๋์ญ์์ค.
์ผ! ๋น์ ์ ๋์ ์ฒซ ํ์ด์ง์ ์์ต๋๋ค! ์ํ์ด ์๋ฅด๋ค!
@krux02
์ข์, ์ด C ํ๋ก์ ํธ๋ ๋น์ ์ด ์ค๋ช ํ๋ ๋์์ ๋ณด์ฌ์ค๋๋ค:
https://github.com/Sonophoto/shellnoise
๊ทธ๋ฌ๋ Ctrl-C ๋ฐ Ctrl-D๋ ์ ์์ ์ผ๋ก ์๋ํฉ๋๋ค.
Linenoise๋ Ctrl-Z๋ฅผ ์๋ก ์ ๋ฌํ๋ ๋์ ์ ๋ ฅ์ผ๋ก ์บก์ฒํ๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค(์ด ์์์๋ ๋จ์ํ ํฐ๋ฏธ๋์ ๋ฌธ์์ด๋ก ์์ฝ๋ฉ๋๋ค).
์ ๊ทธ๋ฆฌ๊ณ ์ด ํ๋ก์ ํธ๋ linenoise ๋ค์ค ๋ผ์ธ ์ ๋ ฅ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
@krux02
์ฝ๊ฐ์ ํ๊ณ ๋ฅผ ํตํด ๊ฐ์ฅ ์ข์ ์ถ์ธก์ linenoise๊ฐ ํฐ๋ฏธ๋์ ์์ ๋ชจ๋๋ก ์ ํํ๊ณ ๊ทธ ์ค์ ์ผ๋ก ์ธํด ASCII ์ ์ด ์ฝ๋ ๋์ ๋ฌธ์๋ก Ctrl-Z๋ฅผ ์บก์ฒํ๊ฒ ๋๋ค๋ ๊ฒ์ ๋๋ค.
https://github.com/antirez/linenoise/blob/master/linenoise.c#L217 -L251
U+001A๋ UTF8๋ก ์ธ์ํ ๋ Ctrl-Z ์ฝ๋์ ๋๋ค.
@hoelzro ๊ฐ ์ด ํจ์น๋ฅผ
https://github.com/hoelzro/p6-linenoise/commit/7d0bb83cab34ca58f7a487b5df30736d058112cf
Steve Bennett๊ฐ linenoise ํฌํฌ์์ ๋ณด์ฌ์ค ๊ฒ์ฒ๋ผ CTRL+Z ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋งค์ฐ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. https://github.com/msteveb/linenoise/commit/29aedbd22b5e3529aff1f85ec1b3164118b83291
ํ์ฌ ๋ง์คํฐ(https://github.com/antirez/linenoise/commit/4a961c0108720741e2683868eb10495f015ee422) ์์ ์ ์ฉ๋๋๋ก ํจ์น๋ฅผ ์ ์ฉํ์ผ๋ฉฐ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
commit d9400774549967cda04cfa04f56ed956cd79147c
Author: Steve Bennett <[email protected]>
Date: Mon Jan 1 13:11:16 2018 +1000
Enable ^Z (SUSP) support
Allows the current process to be backgrounded and then resumed.
Signed-off-by: Steve Bennett <[email protected]>
(adaptations)
Signed-off-by: Alexander F. Mayer <[email protected]>
diff --git a/linenoise.c b/linenoise.c
index 10ffd71..d861505 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -109,6 +109,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <signal.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
@@ -168,6 +169,7 @@ enum KEY_ACTION{
CTRL_T = 20, /* Ctrl-t */
CTRL_U = 21, /* Ctrl+u */
CTRL_W = 23, /* Ctrl+w */
+ CTRL_Z = 26, /* Ctrl+z */
ESC = 27, /* Escape */
BACKSPACE = 127 /* Backspace */
};
@@ -830,6 +832,16 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen,
case CTRL_C: /* ctrl-c */
errno = EAGAIN;
return -1;
+ case CTRL_Z: /* ctrl-z */
+#ifdef SIGTSTP
+ /* send ourselves SIGSUSP */
+ disableRawMode(STDIN_FILENO);
+ raise(SIGTSTP);
+ /* and resume */
+ enableRawMode(STDIN_FILENO);
+ refreshLine(&l);
+#endif
+ continue;
case BACKSPACE: /* backspace */
case 8: /* ctrl-h */
linenoiseEditBackspace(&l);
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
Steve Bennett๊ฐ linenoise ํฌํฌ์์ ๋ณด์ฌ์ค ๊ฒ์ฒ๋ผ CTRL+Z ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋งค์ฐ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. https://github.com/msteveb/linenoise/commit/29aedbd22b5e3529aff1f85ec1b3164118b83291
ํ์ฌ ๋ง์คํฐ(https://github.com/antirez/linenoise/commit/4a961c0108720741e2683868eb10495f015ee422) ์์ ์ ์ฉ๋๋๋ก ํจ์น๋ฅผ ์ ์ฉํ์ผ๋ฉฐ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.