1 | // Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved. |
2 | // Use of this source code is governed by an MIT license |
3 | // that can be found in the LICENSE file. |
4 | // |
5 | // Serves as a more advanced input method |
6 | // based on the work of https://github.com/AmokHuginnsson/replxx |
7 | // |
8 | module readline |
9 | |
10 | import term.termios |
11 | |
12 | // Winsize stores the screen information on Linux. |
13 | struct Winsize { |
14 | ws_row u16 |
15 | ws_col u16 |
16 | ws_xpixel u16 |
17 | ws_ypixel u16 |
18 | } |
19 | |
20 | // Readline is the key struct for reading and holding user input via a terminal. |
21 | // Example: import readline { Readline } |
22 | pub struct Readline { |
23 | mut: |
24 | is_raw bool |
25 | orig_termios termios.Termios // Linux |
26 | current []rune // Line being edited |
27 | cursor int // Cursor position |
28 | overwrite bool |
29 | cursor_row_offset int |
30 | prompt string |
31 | prompt_offset int |
32 | previous_lines [][]rune |
33 | skip_empty bool // skip the empty lines when calling .history_previous() |
34 | search_index int |
35 | is_tty bool |
36 | } |