2021-01-18 13:20:06 +01:00
|
|
|
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
|
2019-10-15 08:04:22 +02:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
2020-12-30 14:09:13 +01:00
|
|
|
//
|
|
|
|
// Serves as a more advanced input method
|
|
|
|
// based on the work of https://github.com/AmokHuginnsson/replxx
|
|
|
|
//
|
2019-10-15 08:04:22 +02:00
|
|
|
module readline
|
|
|
|
|
2020-12-30 14:09:13 +01:00
|
|
|
// Termios stores the terminal options on Linux.
|
2021-04-14 11:47:24 +02:00
|
|
|
struct C.termios {}
|
|
|
|
|
2019-10-15 08:04:22 +02:00
|
|
|
struct Termios {
|
|
|
|
mut:
|
2020-12-30 14:09:13 +01:00
|
|
|
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
|
2019-10-15 08:04:22 +02:00
|
|
|
}
|
|
|
|
|
2020-12-30 14:09:13 +01:00
|
|
|
// Winsize stores the screen information on Linux.
|
2019-10-15 08:04:22 +02:00
|
|
|
struct Winsize {
|
2020-12-30 14:09:13 +01:00
|
|
|
ws_row u16
|
|
|
|
ws_col u16
|
|
|
|
ws_xpixel u16
|
|
|
|
ws_ypixel u16
|
2019-10-15 08:04:22 +02:00
|
|
|
}
|
|
|
|
|
2020-12-30 14:09:13 +01:00
|
|
|
// Readline is the key struct for reading and holding user input via a terminal.
|
|
|
|
// Example: import readline { Readline }
|
2019-10-31 17:01:04 +01:00
|
|
|
pub struct Readline {
|
2019-10-15 08:04:22 +02:00
|
|
|
mut:
|
2020-12-30 14:09:13 +01:00
|
|
|
is_raw bool
|
|
|
|
orig_termios Termios // Linux
|
2021-06-30 21:30:28 +02:00
|
|
|
current []rune // Line being edited
|
2021-04-14 11:47:24 +02:00
|
|
|
cursor int // Cursor position
|
2020-12-30 14:09:13 +01:00
|
|
|
overwrite bool
|
|
|
|
cursor_row_offset int
|
|
|
|
prompt string
|
|
|
|
prompt_offset int
|
2021-06-30 21:30:28 +02:00
|
|
|
previous_lines [][]rune
|
2020-12-30 14:09:13 +01:00
|
|
|
search_index int
|
|
|
|
is_tty bool
|
|
|
|
}
|