2023-03-28 23:55:57 +03:00
|
|
|
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
2019-10-15 09:04:22 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
2020-12-30 16:09:13 +03:00
|
|
|
//
|
|
|
|
// Serves as a more advanced input method
|
|
|
|
// based on the work of https://github.com/AmokHuginnsson/replxx
|
|
|
|
//
|
2019-10-15 09:04:22 +03:00
|
|
|
module readline
|
|
|
|
|
2023-03-30 08:58:52 +03:00
|
|
|
import term.termios
|
|
|
|
|
2020-12-30 16:09:13 +03:00
|
|
|
// Winsize stores the screen information on Linux.
|
2019-10-15 09:04:22 +03:00
|
|
|
struct Winsize {
|
2020-12-30 16:09:13 +03:00
|
|
|
ws_row u16
|
|
|
|
ws_col u16
|
|
|
|
ws_xpixel u16
|
|
|
|
ws_ypixel u16
|
2019-10-15 09:04:22 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 16:09:13 +03:00
|
|
|
// Readline is the key struct for reading and holding user input via a terminal.
|
|
|
|
// Example: import readline { Readline }
|
2019-10-31 19:01:04 +03:00
|
|
|
pub struct Readline {
|
2019-10-15 09:04:22 +03:00
|
|
|
mut:
|
2020-12-30 16:09:13 +03:00
|
|
|
is_raw bool
|
2023-03-30 08:58:52 +03:00
|
|
|
orig_termios termios.Termios // Linux
|
|
|
|
current []rune // Line being edited
|
|
|
|
cursor int // Cursor position
|
2020-12-30 16:09:13 +03:00
|
|
|
overwrite bool
|
|
|
|
cursor_row_offset int
|
|
|
|
prompt string
|
|
|
|
prompt_offset int
|
2021-06-30 22:30:28 +03:00
|
|
|
previous_lines [][]rune
|
2022-02-14 01:12:25 +03:00
|
|
|
skip_empty bool // skip the empty lines when calling .history_previous()
|
2020-12-30 16:09:13 +03:00
|
|
|
search_index int
|
|
|
|
is_tty bool
|
|
|
|
}
|