| 1 | // Copyright (c) 2019-2024 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 | pub struct Readline { |
| 22 | pub mut: |
| 23 | is_raw bool |
| 24 | orig_termios termios.Termios // Linux |
| 25 | current []rune // Line being edited |
| 26 | cursor int // Cursor position |
| 27 | overwrite bool |
| 28 | cursor_row_offset int |
| 29 | prompt string |
| 30 | prompt_offset int |
| 31 | previous_lines [][]rune |
| 32 | skip_empty bool // skip the empty lines when calling .history_previous() |
| 33 | search_index int |
| 34 | is_tty bool |
| 35 | last_prefix_completion []rune |
| 36 | last_completion_offset int |
| 37 | completion_list []string |
| 38 | completion_callback fn (string) []string = unsafe { nil } |
| 39 | mut: |
| 40 | orig_stdin_mode u32 // Windows |
| 41 | } |
| 42 | |