|
|
@ -6,7 +6,7 @@ use ratatui::{
|
|
|
|
prelude::CrosstermBackend,
|
|
|
|
prelude::CrosstermBackend,
|
|
|
|
style::{Color, Style},
|
|
|
|
style::{Color, Style},
|
|
|
|
widgets::{Block, Borders, List, ListItem, Paragraph, Wrap},
|
|
|
|
widgets::{Block, Borders, List, ListItem, Paragraph, Wrap},
|
|
|
|
Terminal,
|
|
|
|
DefaultTerminal, Terminal,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
@ -15,17 +15,11 @@ use crate::{
|
|
|
|
widgets::blocks::{basic_block, highlighted_border_block, highlighted_item_block},
|
|
|
|
widgets::blocks::{basic_block, highlighted_border_block, highlighted_item_block},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
pub fn run(app_state: &mut ApplicationState) -> Result<(), Box<dyn Error>> {
|
|
|
|
/// Main running function for the application that sets up the interaction loop
|
|
|
|
// Set up terminal
|
|
|
|
pub fn run(
|
|
|
|
let mut stdout = io::stdout();
|
|
|
|
mut terminal: DefaultTerminal,
|
|
|
|
terminal::enable_raw_mode()?;
|
|
|
|
app_state: &mut ApplicationState,
|
|
|
|
stdout.execute(terminal::Clear(terminal::ClearType::All))?;
|
|
|
|
) -> Result<(), Box<dyn Error>> {
|
|
|
|
stdout.execute(terminal::EnterAlternateScreen)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the terminal with the Crossterm backend
|
|
|
|
|
|
|
|
let backend = CrosstermBackend::new(stdout);
|
|
|
|
|
|
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start the main loop for rendering
|
|
|
|
// Start the main loop for rendering
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
terminal.draw(|f| {
|
|
|
|
terminal.draw(|f| {
|
|
|
@ -41,8 +35,8 @@ pub fn run(app_state: &mut ApplicationState) -> Result<(), Box<dyn Error>> {
|
|
|
|
.constraints::<&Vec<Constraint>>(constraints.as_ref())
|
|
|
|
.constraints::<&Vec<Constraint>>(constraints.as_ref())
|
|
|
|
.split(size);
|
|
|
|
.split(size);
|
|
|
|
|
|
|
|
|
|
|
|
// Render a item blocks in each column
|
|
|
|
|
|
|
|
for (i, chunk) in chunks.iter().enumerate() {
|
|
|
|
for (i, chunk) in chunks.iter().enumerate() {
|
|
|
|
|
|
|
|
// Create columns and apply styling based on wehter the column is selected or not
|
|
|
|
let block = if i == app_state.selected_col {
|
|
|
|
let block = if i == app_state.selected_col {
|
|
|
|
highlighted_border_block(i)
|
|
|
|
highlighted_border_block(i)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -54,6 +48,8 @@ pub fn run(app_state: &mut ApplicationState) -> Result<(), Box<dyn Error>> {
|
|
|
|
if nitems == 0 {
|
|
|
|
if nitems == 0 {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set up sub layout which holds each item
|
|
|
|
let constraints: Vec<Constraint> =
|
|
|
|
let constraints: Vec<Constraint> =
|
|
|
|
vec![Constraint::Max(5); nitems].into_iter().collect();
|
|
|
|
vec![Constraint::Max(5); nitems].into_iter().collect();
|
|
|
|
let sub_chunks = Layout::default()
|
|
|
|
let sub_chunks = Layout::default()
|
|
|
@ -64,6 +60,7 @@ pub fn run(app_state: &mut ApplicationState) -> Result<(), Box<dyn Error>> {
|
|
|
|
for ((task, highlight), sub_chunk) in
|
|
|
|
for ((task, highlight), sub_chunk) in
|
|
|
|
zip(app_state.get_col_slice(i), sub_chunks.iter())
|
|
|
|
zip(app_state.get_col_slice(i), sub_chunks.iter())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// Set up each item and style the selected item
|
|
|
|
let style = if highlight {
|
|
|
|
let style = if highlight {
|
|
|
|
Style::default().bg(Color::Blue).fg(Color::DarkGray)
|
|
|
|
Style::default().bg(Color::Blue).fg(Color::DarkGray)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|