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

readline: add missing documentation, fix documentation format, add README.md (#7683)

This commit is contained in:
Larpon
2020-12-30 14:09:13 +01:00
committed by GitHub
parent eef73edb57
commit b1f16533b1
5 changed files with 248 additions and 159 deletions

View File

@@ -1,43 +1,57 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
// Will serve as more advanced input method
// Based on the work of https://github.com/AmokHuginnsson/replxx
//
// Serves as a more advanced input method
// based on the work of https://github.com/AmokHuginnsson/replxx
//
module readline
// Linux
// Used to change the terminal options
// Termios stores the terminal options on Linux.
struct Termios {
mut:
c_iflag int
c_oflag int
c_cflag int
c_lflag int
c_cc [12]int //NCCS == 12. Cant use the defined value here
c_iflag int
c_oflag int
c_cflag int
c_lflag int
c_cc [12]int // NCCS == 12. Can't use the defined value here
}
// Linux
// Used to collect the screen information
// Winsize stores the screen information on Linux.
struct Winsize {
ws_row u16
ws_col u16
ws_xpixel u16
ws_ypixel u16
ws_row u16
ws_col u16
ws_xpixel u16
ws_ypixel u16
}
// Readline is the key struct for reading and holding user input via a terminal.
// Example: import readline { Readline }
pub struct Readline {
mut:
is_raw bool
orig_termios Termios // Linux
current ustring // Line being edited
cursor int // Cursor position
overwrite bool
cursor_row_offset int
prompt string
prompt_offset int
previous_lines []ustring
search_index int
is_tty bool
is_raw bool
orig_termios Termios // Linux
current ustring // Line being edited
cursor int // Cursor position
overwrite bool
cursor_row_offset int
prompt string
prompt_offset int
previous_lines []ustring
search_index int
is_tty bool
}
// get_prompt_offset computes the length of the `prompt` `string` argument.
fn get_prompt_offset(prompt string) int {
mut len := 0
for i := 0; i < prompt.len; i++ {
if prompt[i] == `\e` {
for ; i < prompt.len && prompt[i] != `m`; i++ {
}
} else {
len = len + 1
}
}
return prompt.len - len
}