#linux-terminal #terminal #linux #io #single-line #text-editing

bin+lib term-basics-linux

A simple crate with basic functionality for terminal applications

23 releases (1 stable)

1.0.0 Nov 28, 2023
0.5.8 Nov 18, 2022
0.5.7 Sep 12, 2021
0.5.6 Mar 21, 2021
0.2.0 Jul 12, 2019

#203 in Command-line interface

Download history 1/week @ 2024-02-21 4/week @ 2024-02-28 2/week @ 2024-03-06 44/week @ 2024-03-13 81/week @ 2024-03-20

132 downloads per month

MIT license

24KB
465 lines

term-basics-linux

Rust crate library that provides basic terminal input functionality for Linux. The main feature is the single line input field. It supports editing the text with backspace and delete, as well as navigating using home, end and the arrow keys.

print!("your input: ");
let input = tbl::input_field_simple(true);

It supports a list of predefined inputs for the user to scroll between (up/down arrow):

let mut his = tbl::InputList::new(2);
his.add("one");
his.add("two");
println!("{}", tbl::input_field_scrollable(&mut his, true));

You can also hide/substitute the typed characters. This is handy for password input:

// like doas/sudo
let pass = tbl::input_field(&mut tbl::InputList::new(0), tbl::PrintChar::None, true);
// like websites
let pass = tbl::input_field(&mut tbl::InputList::new(0), tbl::PrintChar::Substitute('*'), true);

Another feature is getch() which returns the characters from stdin without the user having to press enter. It can be useful and is not available by default in rust. All other input fields are using this function.

design

This crate is very minimalistic by design, It does just a few things. It is for Linux only. This keeps it simple and lightweight. For a

keycodes

Sometimes different terminal emulators use different codes for certain keys like delete or end. For example, backspace is 127 on both suckless simple terminal (ST) and the build in terminal emulator in vscode. But delete is 27-91-80 on ST and 27-91-51-126 on vscode. End is 27-91-52-126 on ST and 27-91-70 on vscode. The test_chars function can help look up what key code it is on your platform.

License

Copyright (C) 2023 Cody Bloemhard

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

Dependencies

~0.5–1MB
~23K SLoC