mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 12:17:19 +02:00
Merge pull request #148 from kdheepak/refactor-get-position
This commit is contained in:
commit
f90df0f631
1 changed files with 22 additions and 47 deletions
69
src/app.rs
69
src/app.rs
|
@ -267,6 +267,17 @@ impl TTApp {
|
||||||
tasks_with_styles
|
tasks_with_styles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_position(&self, lb: &LineBuffer) -> usize {
|
||||||
|
let mut position = lb.as_str().graphemes(true).count();
|
||||||
|
for (i, (_i, g)) in lb.as_str().grapheme_indices(true).enumerate() {
|
||||||
|
if _i == lb.pos() {
|
||||||
|
position = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
position
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_task(&mut self, f: &mut Frame<impl Backend>) {
|
pub fn draw_task(&mut self, f: &mut Frame<impl Backend>) {
|
||||||
let tasks_is_empty = self.tasks.lock().unwrap().is_empty();
|
let tasks_is_empty = self.tasks.lock().unwrap().is_empty();
|
||||||
let tasks_len = self.tasks.lock().unwrap().len();
|
let tasks_len = self.tasks.lock().unwrap().len();
|
||||||
|
@ -305,13 +316,7 @@ impl TTApp {
|
||||||
match self.mode {
|
match self.mode {
|
||||||
AppMode::TaskReport => self.draw_command(f, rects[1], self.filter.as_str(), "Filter Tasks"),
|
AppMode::TaskReport => self.draw_command(f, rects[1], self.filter.as_str(), "Filter Tasks"),
|
||||||
AppMode::TaskFilter => {
|
AppMode::TaskFilter => {
|
||||||
let mut position = self.filter.as_str().graphemes(true).count();
|
let position = self.get_position(&self.filter);
|
||||||
for (i, (_i, g)) in self.filter.as_str().grapheme_indices(true).enumerate() {
|
|
||||||
if _i == self.filter.pos() {
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
self.draw_command(
|
self.draw_command(
|
||||||
|
@ -321,34 +326,22 @@ impl TTApp {
|
||||||
Span::styled("Filter Tasks", Style::default().add_modifier(Modifier::BOLD)),
|
Span::styled("Filter Tasks", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AppMode::TaskModify => {
|
AppMode::TaskLog => {
|
||||||
let mut position = self.modify.as_str().graphemes(true).count();
|
let position = self.get_position(&self.command);
|
||||||
for (i, (_i, g)) in self.modify.as_str().grapheme_indices(true).enumerate() {
|
|
||||||
if _i == self.modify.pos() {
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
self.draw_command(
|
self.draw_command(
|
||||||
f,
|
f,
|
||||||
rects[1],
|
rects[1],
|
||||||
self.modify.as_str(),
|
self.command.as_str(),
|
||||||
Span::styled(
|
Span::styled(
|
||||||
format!("Modify Task {}", task_id).as_str(),
|
format!("Modify Task {}", task_id).as_str(),
|
||||||
Style::default().add_modifier(Modifier::BOLD),
|
Style::default().add_modifier(Modifier::BOLD),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AppMode::TaskLog => {
|
AppMode::TaskSubprocess => {
|
||||||
let mut position = self.command.as_str().graphemes(true).count();
|
let position = self.get_position(&self.command);
|
||||||
for (i, (_i, g)) in self.command.as_str().grapheme_indices(true).enumerate() {
|
|
||||||
if _i == self.command.pos() {
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
self.draw_command(
|
self.draw_command(
|
||||||
|
@ -358,31 +351,19 @@ impl TTApp {
|
||||||
Span::styled("Log Tasks", Style::default().add_modifier(Modifier::BOLD)),
|
Span::styled("Log Tasks", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AppMode::TaskSubprocess => {
|
AppMode::TaskModify => {
|
||||||
let mut position = self.command.as_str().graphemes(true).count();
|
let position = self.get_position(&self.modify);
|
||||||
for (i, (_i, g)) in self.command.as_str().grapheme_indices(true).enumerate() {
|
|
||||||
if _i == self.command.pos() {
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
self.draw_command(
|
self.draw_command(
|
||||||
f,
|
f,
|
||||||
rects[1],
|
rects[1],
|
||||||
self.command.as_str(),
|
self.modify.as_str(),
|
||||||
Span::styled("Shell Command", Style::default().add_modifier(Modifier::BOLD)),
|
Span::styled("Shell Command", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AppMode::TaskAnnotate => {
|
AppMode::TaskAnnotate => {
|
||||||
let mut position = self.command.as_str().graphemes(true).count();
|
let position = self.get_position(&self.command);
|
||||||
for (i, (_i, g)) in self.command.as_str().grapheme_indices(true).enumerate() {
|
|
||||||
if _i == self.command.pos() {
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
self.draw_command(
|
self.draw_command(
|
||||||
|
@ -396,13 +377,7 @@ impl TTApp {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AppMode::TaskAdd => {
|
AppMode::TaskAdd => {
|
||||||
let mut position = self.command.as_str().graphemes(true).count();
|
let position = self.get_position(&self.command);
|
||||||
for (i, (_i, g)) in self.command.as_str().grapheme_indices(true).enumerate() {
|
|
||||||
if _i == self.command.pos() {
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
f.set_cursor(rects[1].x + position as u16 + 1, rects[1].y + 1);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
self.draw_command(
|
self.draw_command(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue