Skip to content

Commit

Permalink
Merge cebf789 into f2f5714
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot00 committed Dec 8, 2021
2 parents f2f5714 + cebf789 commit bc1249e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions quake_tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
quake_core = { path = "../quake_core", version = "0.1.0" }

crossterm = "0.22"
tui = { version = "0.16", default-features = false, features = ['crossterm'] }
unicode-width = "0.1.9"
serde_yaml = "0.8"
3 changes: 2 additions & 1 deletion quake_tui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod app;
mod ui;

use app::{App, MainWidget, Mode};
use crate::app::{App, MainWidget, Mode};
use crossterm::{
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
execute,
Expand Down Expand Up @@ -39,6 +39,7 @@ pub fn tui_main_loop() -> Result<(), Box<dyn Error>> {
}

fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
// TODO: refactor
loop {
terminal.draw(|f| {
draw(f, &mut app);
Expand Down
10 changes: 0 additions & 10 deletions quake_tui/src/main.rs

This file was deleted.

53 changes: 25 additions & 28 deletions quake_tui/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::app::{App, MainWidget, Mode};
use std::path::{Path, PathBuf};
use std::{fs, io};
use quake_core::entry::EntryDefines;
use quake_core::QuakeConfig;
use serde_yaml;
use std::error::Error;
use std::fs;
use std::path::Path;
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Corner, Direction, Layout, Rect};
use tui::style::{Color, Modifier, Style};
Expand Down Expand Up @@ -66,38 +70,31 @@ where
)
}
MainWidget::Dirs => {
let entry_dirs: Vec<ListItem> = list_workspaces()
.unwrap_or_default()
.iter()
.rev()
.map(|dir| {
let dir_name = Spans::from(vec![Span::styled(
dir.display().to_string(),
Style::default().fg(Color::Yellow),
)]);

ListItem::new(vec![Spans::from("-".repeat(area.width as usize)), dir_name])
})
.collect();
let dir_list = List::new(entry_dirs)
let entry_types: Vec<ListItem> = list_entry_types().unwrap_or_default();
let entry_types_list = List::new(entry_types)
.block(Block::default().borders(Borders::ALL).title("List"))
.start_corner(Corner::TopLeft);
frame.render_widget(dir_list, area);
frame.render_widget(entry_types_list, area);
}
}
}

fn list_workspaces() -> io::Result<Vec<PathBuf>> {
let mut entries = fs::read_dir(".")?
.map(|res| res.map(|e| e.path()))
.filter(|path| path.as_deref().map(is_workspace).unwrap_or(false))
.collect::<Result<Vec<_>, io::Error>>()?;

entries.sort();
fn list_entry_types() -> Result<Vec<ListItem<'static>>, Box<dyn Error>> {
let config: QuakeConfig = serde_yaml::from_str(fs::read_to_string(".quake.yaml")?.as_str())?;
let entry_defines_path = Path::new(&config.workspace).join("entries-define.yaml");
let entry_defines: EntryDefines =
serde_yaml::from_str(&fs::read_to_string(entry_defines_path)?)?;

Ok(entries)
}
Ok(entry_defines
.entries
.iter()
.map(|define| {
let entry_type = Spans::from(vec![Span::styled(
define.entry_type.clone(),
Style::default().fg(Color::Yellow),
)]);

fn is_workspace(path: &Path) -> bool {
path.is_dir() && path.join("entries.csv").exists()
ListItem::new(vec![entry_type])
})
.collect())
}

0 comments on commit bc1249e

Please sign in to comment.