1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

readline: make some functions public

This commit is contained in:
r00ster 2020-03-27 09:55:15 +01:00 committed by GitHub
parent db59c621e8
commit bee8972632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,9 +39,10 @@ fn C.tcsetattr() int
//fn C.ioctl() int //fn C.ioctl() int
fn C.raise() fn C.raise()
// Toggle raw mode of the terminal by changing its attributes // Enable the raw mode of the terminal
// Catches SIGUSER (CTRL+C) Signal to reset tty // In raw mode all keypresses are directly sent to the program and no interpretation is done
fn (r mut Readline) enable_raw_mode() { // Catches the SIGUSER (CTRL+C) Signal
pub fn (r mut Readline) enable_raw_mode() {
if C.tcgetattr(0, &r.orig_termios) == -1 { if C.tcgetattr(0, &r.orig_termios) == -1 {
r.is_tty = false r.is_tty = false
r.is_raw = false r.is_raw = false
@ -58,8 +59,9 @@ fn (r mut Readline) enable_raw_mode() {
r.is_tty = true r.is_tty = true
} }
// Not catching the SIGUSER (CTRL+C) Signal // Enable the raw mode of the terminal
fn (r mut Readline) enable_raw_mode_nosig() { // Does not catch the SIGUSER (CTRL+C) Signal
pub fn (r mut Readline) enable_raw_mode_nosig() {
if ( C.tcgetattr(0, &r.orig_termios) == -1 ) { if ( C.tcgetattr(0, &r.orig_termios) == -1 ) {
r.is_tty = false r.is_tty = false
r.is_raw = false r.is_raw = false
@ -76,16 +78,16 @@ fn (r mut Readline) enable_raw_mode_nosig() {
r.is_tty = true r.is_tty = true
} }
// Reset back the terminal to its default value // Disable the raw mode of the terminal
fn (r mut Readline) disable_raw_mode() { pub fn (r mut Readline) disable_raw_mode() {
if r.is_raw { if r.is_raw {
C.tcsetattr(0, C.TCSADRAIN, &r.orig_termios) C.tcsetattr(0, C.TCSADRAIN, &r.orig_termios)
r.is_raw = false r.is_raw = false
} }
} }
// Read single char // Read a single char
fn (r Readline) read_char() int { pub fn (r Readline) read_char() int {
return utf8_getchar() return utf8_getchar()
} }