added base col width

pull/4/head
Jan Hrastnik 4 years ago
parent 28a1e11fda
commit c9e9fcf7c5

@ -34,6 +34,8 @@ type Terminal = tui::Terminal<CrosstermBackend<std::io::Stdout>>;
static EX: smol::Executor = smol::Executor::new(); static EX: smol::Executor = smol::Executor::new();
const BASE_WIDTH: u16 = 30;
pub struct Application { pub struct Application {
editor: Editor, editor: Editor,
prompt: Option<Prompt>, prompt: Option<Prompt>,
@ -253,9 +255,10 @@ impl Renderer {
); );
let mut row = 0; let mut row = 0;
let mut col = 0; let mut col = 0;
let max_row: u16 = self.size.0 / BASE_WIDTH;
// TODO: this will crash if there are too many cols added // TODO: this will crash if there are too many cols added
// TODO: set char limit // TODO: set char limit
for i in (0..completion.len()) { for (i, command) in completion.iter().enumerate() {
let color = if prompt.completion_selection_index.is_some() let color = if prompt.completion_selection_index.is_some()
&& i == prompt.completion_selection_index.unwrap() && i == prompt.completion_selection_index.unwrap()
{ {
@ -263,16 +266,20 @@ impl Renderer {
} else { } else {
self.text_color self.text_color
}; };
self.surface.set_string( self.surface.set_stringn(
1 + col * 10, 1 + row * BASE_WIDTH,
self.size.1 - 6 + row as u16, self.size.1 - 6 + col as u16,
&completion[i], &command,
BASE_WIDTH as usize - 1,
color, color,
); );
row += 1; col += 1;
if row > 3 { if col > 3 {
row = 0; col = 0;
col += 1; row += 1;
}
if row > max_row {
break;
} }
} }
} }
@ -436,6 +443,31 @@ impl Application {
String::from("ccc"), String::from("ccc"),
String::from("ddd"), String::from("ddd"),
String::from("eee"), String::from("eee"),
String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"),
String::from("q"),
String::from("aaa"),
String::from("bbb"),
String::from("ccc"),
String::from("ddd"),
String::from("eee"),
String::from("q"),
String::from("aaa"),
String::from("bbb"),
String::from("ccc"),
String::from("ddd"),
String::from("eee"),
String::from("q"),
String::from("aaa"),
String::from("bbb"),
String::from("ccc"),
String::from("ddd"),
String::from("eee"),
String::from("q"),
String::from("aaa"),
String::from("bbb"),
String::from("ccc"),
String::from("ddd"),
String::from("eee"),
]; ];
for command in command_list { for command in command_list {
if command.contains(_input) { if command.contains(_input) {

@ -39,7 +39,7 @@ impl Prompt {
} }
pub fn move_char_left(&mut self) { pub fn move_char_left(&mut self) {
if self.cursor > 1 { if self.cursor > 0 {
self.cursor -= 1; self.cursor -= 1;
} }
} }
@ -68,23 +68,25 @@ impl Prompt {
} }
pub fn change_completion_selection(&mut self) { pub fn change_completion_selection(&mut self) {
self.completion_selection_index = self if self.completion.is_some() {
.completion_selection_index self.completion_selection_index = self
.map(|i| { .completion_selection_index
if i == self.completion.as_ref().unwrap().len() - 1 { .map(|i| {
0 if i == self.completion.as_ref().unwrap().len() - 1 {
} else { 0
i + 1 } else {
} i + 1
}) }
.or(Some(0)); })
self.line = String::from( .or(Some(0));
self.completion self.line = String::from(
.as_ref() self.completion
.unwrap() .as_ref()
.get(self.completion_selection_index.unwrap()) .unwrap()
.unwrap(), .get(self.completion_selection_index.unwrap())
); .unwrap(),
);
}
} }
pub fn exit_selection(&mut self) { pub fn exit_selection(&mut self) {

Loading…
Cancel
Save